@zoralabs/protocol-sdk 0.5.17 → 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 (63) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +1 -416
  4. package/dist/create/1155-create-helper.d.ts +16 -55
  5. package/dist/create/1155-create-helper.d.ts.map +1 -1
  6. package/dist/create/contract-setup.d.ts +14 -0
  7. package/dist/create/contract-setup.d.ts.map +1 -0
  8. package/dist/create/token-setup.d.ts +27 -0
  9. package/dist/create/token-setup.d.ts.map +1 -0
  10. package/dist/create/types.d.ts +45 -0
  11. package/dist/create/types.d.ts.map +1 -0
  12. package/dist/index.cjs +1273 -857
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1233 -831
  17. package/dist/index.js.map +1 -1
  18. package/dist/mint/mint-client.d.ts +4083 -43
  19. package/dist/mint/mint-client.d.ts.map +1 -1
  20. package/dist/mint/subgraph-mint-getter.d.ts +17 -0
  21. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
  22. package/dist/mint/types.d.ts +79 -0
  23. package/dist/mint/types.d.ts.map +1 -0
  24. package/dist/mints/mints-contracts.d.ts +24 -24
  25. package/dist/premint/contract-types.d.ts +4 -4
  26. package/dist/premint/contract-types.d.ts.map +1 -1
  27. package/dist/premint/conversions.d.ts +3 -1
  28. package/dist/premint/conversions.d.ts.map +1 -1
  29. package/dist/premint/premint-api-client.d.ts +27 -14
  30. package/dist/premint/premint-api-client.d.ts.map +1 -1
  31. package/dist/premint/premint-client.d.ts +62 -46
  32. package/dist/premint/premint-client.d.ts.map +1 -1
  33. package/dist/premint/preminter.d.ts +19 -7
  34. package/dist/premint/preminter.d.ts.map +1 -1
  35. package/dist/sdk.d.ts +43 -0
  36. package/dist/sdk.d.ts.map +1 -0
  37. package/dist/utils.d.ts +17 -6870
  38. package/dist/utils.d.ts.map +1 -1
  39. package/package.json +3 -2
  40. package/src/create/1155-create-helper.test.ts +235 -56
  41. package/src/create/1155-create-helper.ts +141 -309
  42. package/src/create/contract-setup.ts +88 -0
  43. package/src/create/token-setup.ts +379 -0
  44. package/src/create/types.ts +57 -0
  45. package/src/index.ts +5 -1
  46. package/src/mint/mint-client.test.ts +50 -61
  47. package/src/mint/mint-client.ts +321 -157
  48. package/src/mint/{mint-api-client.ts → subgraph-mint-getter.ts} +2 -25
  49. package/src/mint/types.ts +122 -0
  50. package/src/mints/mints-contracts.test.ts +1 -1
  51. package/src/mints/mints-contracts.ts +4 -4
  52. package/src/premint/contract-types.ts +4 -4
  53. package/src/premint/conversions.ts +12 -2
  54. package/src/premint/premint-api-client.ts +55 -43
  55. package/src/premint/premint-client.test.ts +75 -65
  56. package/src/premint/premint-client.ts +126 -153
  57. package/src/premint/preminter.test.ts +4 -5
  58. package/src/premint/preminter.ts +63 -13
  59. package/src/sdk.ts +98 -0
  60. package/src/utils.ts +30 -23
  61. package/test-integration/premint-client.test.ts +8 -8
  62. package/dist/mint/mint-api-client.d.ts +0 -35
  63. package/dist/mint/mint-api-client.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -20,8 +20,266 @@ import {
20
20
  keccak256,
21
21
  concat,
22
22
  recoverAddress,
23
- parseEther
23
+ parseEther as parseEther2
24
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
25
283
  var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
26
284
  async function isAuthorizedToCreatePremint({
27
285
  contractAdmin = zeroAddress,
@@ -164,8 +422,8 @@ var supportsPremintVersion = async ({
164
422
  };
165
423
  async function getPremintCollectionAddress({
166
424
  publicClient,
167
- collection,
168
- collectionAddress
425
+ contract: collection,
426
+ contractAddress: collectionAddress
169
427
  }) {
170
428
  if (typeof collection !== "undefined") {
171
429
  return publicClient.readContract({
@@ -224,7 +482,7 @@ async function getPremintMintFee({
224
482
  });
225
483
  } catch (e) {
226
484
  console.error(e);
227
- return parseEther("0.000777");
485
+ return parseEther2("0.000777");
228
486
  }
229
487
  }
230
488
  async function getPremintMintCosts({
@@ -234,14 +492,44 @@ async function getPremintMintCosts({
234
492
  quantityToMint
235
493
  }) {
236
494
  const mintFee = await getPremintMintFee({ tokenContract, publicClient });
495
+ const quantityToMintBigInt = BigInt(quantityToMint);
237
496
  return {
238
- mintFee: mintFee * quantityToMint,
239
- tokenPurchaseCost: tokenPrice * quantityToMint,
240
- totalCost: (mintFee + tokenPrice) * quantityToMint
497
+ mintFee: mintFee * quantityToMintBigInt,
498
+ totalPurchaseCost: tokenPrice * quantityToMintBigInt,
499
+ totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt
241
500
  };
242
501
  }
243
- function makeMintRewardsRecipient({
244
- mintReferral = zeroAddress,
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
+ }
531
+ function makeMintRewardsRecipient({
532
+ mintReferral = zeroAddress,
245
533
  platformReferral = zeroAddress
246
534
  }) {
247
535
  return [mintReferral, platformReferral];
@@ -267,12 +555,12 @@ var toContractCreationConfigOrAddress = ({
267
555
  }) => {
268
556
  if (typeof collection !== "undefined") {
269
557
  return {
270
- collection
558
+ contract: collection
271
559
  };
272
560
  }
273
561
  if (typeof collectionAddress !== "undefined") {
274
562
  return {
275
- collectionAddress
563
+ contractAddress: collectionAddress
276
564
  };
277
565
  }
278
566
  throw new Error("Must provide either a collection or a collection address");
@@ -348,433 +636,109 @@ var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
348
636
  return await retries(tryFn, maxTries, atTry + 1);
349
637
  }
350
638
  }
351
- }
352
- throw err;
353
- }
354
- };
355
- var httpClient = {
356
- get,
357
- post,
358
- retries
359
- };
360
-
361
- // src/constants.ts
362
- import { parseAbi } from "viem";
363
- var ZORA_API_BASE = "https://api.zora.co/";
364
- var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
365
- var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
366
- function getSubgraph(name, version) {
367
- return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
368
- }
369
- var zora721Abi = parseAbi([
370
- "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
371
- "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
372
- ]);
373
- var NFT_SALE_QUERY = `
374
- fragment SaleStrategy on SalesStrategyConfig {
375
- type
376
- fixedPrice {
377
- address
378
- pricePerToken
379
- saleEnd
380
- saleStart
381
- maxTokensPerAddress
382
- }
383
- erc20Minter {
384
- address
385
- pricePerToken
386
- currency
387
- saleEnd
388
- saleStart
389
- maxTokensPerAddress
390
- }
391
- }
392
-
393
- query ($id: ID!) {
394
- zoraCreateToken(id: $id) {
395
- id
396
- contract {
397
- mintFeePerQuantity
398
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
399
- ...SaleStrategy
400
- }
401
- }
402
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
403
- ...SaleStrategy
404
- }
405
- }
406
- }
407
- `;
408
-
409
- // src/apis/chain-constants.ts
410
- import {
411
- arbitrum,
412
- base,
413
- baseSepolia,
414
- foundry,
415
- mainnet,
416
- optimism,
417
- sepolia,
418
- zora,
419
- zoraSepolia
420
- } from "viem/chains";
421
- import { parseEther as parseEther2 } from "viem";
422
- var REWARD_PER_TOKEN = parseEther2("0.000777");
423
- var networkConfigByChain = {
424
- [mainnet.id]: {
425
- chainId: mainnet.id,
426
- isTestnet: false,
427
- zoraCollectPathChainName: "eth",
428
- zoraBackendChainName: "ETHEREUM-MAINNET",
429
- subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
430
- },
431
- [sepolia.id]: {
432
- chainId: sepolia.id,
433
- isTestnet: true,
434
- zoraCollectPathChainName: "sep",
435
- zoraBackendChainName: "ETHEREUM-SEPOLIA",
436
- subgraphUrl: getSubgraph("zora-create-sepolia", "stable")
437
- },
438
- [zora.id]: {
439
- chainId: zora.id,
440
- isTestnet: false,
441
- zoraCollectPathChainName: "zora",
442
- zoraBackendChainName: "ZORA-MAINNET",
443
- subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
444
- },
445
- [zoraSepolia.id]: {
446
- chainId: zoraSepolia.id,
447
- isTestnet: true,
448
- zoraCollectPathChainName: "zsep",
449
- zoraBackendChainName: "ZORA-SEPOLIA",
450
- subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
451
- },
452
- [optimism.id]: {
453
- chainId: optimism.id,
454
- isTestnet: false,
455
- zoraCollectPathChainName: "oeth",
456
- zoraBackendChainName: "OPTIMISM-MAINNET",
457
- subgraphUrl: getSubgraph("zora-create-optimism", "stable")
458
- },
459
- [arbitrum.id]: {
460
- chainId: arbitrum.id,
461
- isTestnet: true,
462
- zoraCollectPathChainName: "arb",
463
- zoraBackendChainName: "ARBITRUM-MAINNET",
464
- subgraphUrl: getSubgraph("zora-create-arbitrum-one", "stable")
465
- },
466
- [base.id]: {
467
- chainId: base.id,
468
- isTestnet: false,
469
- zoraCollectPathChainName: "base",
470
- zoraBackendChainName: "BASE-MAINNET",
471
- subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
472
- },
473
- [baseSepolia.id]: {
474
- chainId: baseSepolia.id,
475
- isTestnet: true,
476
- zoraCollectPathChainName: "bsep",
477
- zoraBackendChainName: "BASE-SEPOLIA",
478
- subgraphUrl: getSubgraph("zora-create-base-sepolia", "stable")
479
- },
480
- [foundry.id]: {
481
- chainId: foundry.id,
482
- isTestnet: true,
483
- zoraCollectPathChainName: "zgor",
484
- zoraBackendChainName: "ZORA-GOERLI",
485
- subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
486
- }
487
- };
488
-
489
- // src/mint/mint-api-client.ts
490
- var getApiNetworkConfigForChain = (chainId) => {
491
- if (!networkConfigByChain[chainId]) {
492
- throw new Error(`chain id ${chainId} network not configured `);
493
- }
494
- return networkConfigByChain[chainId];
495
- };
496
- var MintAPIClient = class {
497
- constructor(chainId, httpClient2) {
498
- this.httpClient = httpClient2 || httpClient;
499
- this.networkConfig = getApiNetworkConfigForChain(chainId);
500
- }
501
- async getSalesConfigAndTokenInfo({
502
- tokenAddress,
503
- tokenId,
504
- saleType
505
- }) {
506
- const { retries: retries2, post: post2 } = this.httpClient;
507
- return retries2(async () => {
508
- const response = await post2(this.networkConfig.subgraphUrl, {
509
- query: NFT_SALE_QUERY,
510
- variables: {
511
- id: tokenId !== void 0 ? (
512
- // Generic Token ID types all stringify down to the base numeric equivalent.
513
- `${tokenAddress.toLowerCase()}-${tokenId}`
514
- ) : `${tokenAddress.toLowerCase()}-0`
515
- }
516
- });
517
- const token = response.data?.zoraCreateToken;
518
- if (!token) {
519
- throw new Error("Cannot find a token to mint");
520
- }
521
- const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
522
- const saleStrategies = allStrategies.sort(
523
- (a, b) => BigInt(
524
- a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
525
- ) > BigInt(
526
- b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
527
- ) ? 1 : -1
528
- );
529
- let targetStrategy;
530
- if (!saleType) {
531
- targetStrategy = saleStrategies[0];
532
- if (!targetStrategy) {
533
- throw new Error("Cannot find sale strategy");
534
- }
535
- } else {
536
- const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
537
- targetStrategy = saleStrategies.find(
538
- (strategy) => strategy.type === mappedSaleType
539
- );
540
- if (!targetStrategy) {
541
- throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
542
- }
543
- }
544
- if (targetStrategy.type === "FIXED_PRICE") {
545
- return {
546
- salesConfig: {
547
- saleType: "fixedPrice",
548
- ...targetStrategy.fixedPrice,
549
- maxTokensPerAddress: BigInt(
550
- targetStrategy.fixedPrice.maxTokensPerAddress
551
- ),
552
- pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
553
- },
554
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
555
- };
556
- }
557
- if (targetStrategy.type === "ERC_20_MINTER") {
558
- return {
559
- salesConfig: {
560
- saleType: "erc20",
561
- ...targetStrategy.erc20Minter,
562
- maxTokensPerAddress: BigInt(
563
- targetStrategy.erc20Minter.maxTokensPerAddress
564
- ),
565
- pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
566
- },
567
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
568
- };
569
- }
570
- throw new Error("Invalid saleType");
571
- });
572
- }
573
- };
574
-
575
- // src/premint/conversions.ts
576
- import {
577
- PremintConfigVersion
578
- } from "@zoralabs/protocol-deployments";
579
- var convertCollectionFromApi = (collection) => {
580
- if (!collection)
581
- return void 0;
582
- return {
583
- additionalAdmins: collection.additionalAdmins || [],
584
- contractAdmin: collection.contractAdmin,
585
- contractName: collection.contractName,
586
- contractURI: collection.contractURI
587
- };
588
- };
589
- var convertPremintFromApi = (premint) => {
590
- if (premint.config_version === PremintConfigVersion.V1 || !premint.config_version) {
591
- const tokenConfig = premint.tokenConfig;
592
- return {
593
- premintConfigVersion: PremintConfigVersion.V1,
594
- premintConfig: {
595
- deleted: premint.deleted,
596
- uid: premint.uid,
597
- version: premint.version,
598
- tokenConfig: {
599
- ...tokenConfig,
600
- fixedPriceMinter: tokenConfig.fixedPriceMinter,
601
- royaltyRecipient: tokenConfig.royaltyRecipient,
602
- maxSupply: BigInt(tokenConfig.maxSupply),
603
- pricePerToken: BigInt(tokenConfig.pricePerToken),
604
- mintStart: BigInt(tokenConfig.mintStart),
605
- mintDuration: BigInt(tokenConfig.mintDuration),
606
- maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
607
- }
608
- }
609
- };
610
- } else {
611
- const tokenConfig = premint.tokenConfig;
612
- return {
613
- premintConfigVersion: PremintConfigVersion.V2,
614
- premintConfig: {
615
- deleted: premint.deleted,
616
- uid: premint.uid,
617
- version: premint.version,
618
- tokenConfig: {
619
- ...tokenConfig,
620
- fixedPriceMinter: tokenConfig.fixedPriceMinter,
621
- payoutRecipient: tokenConfig.payoutRecipient,
622
- createReferral: tokenConfig.createReferral,
623
- maxSupply: BigInt(tokenConfig.maxSupply),
624
- pricePerToken: BigInt(tokenConfig.pricePerToken),
625
- mintStart: BigInt(tokenConfig.mintStart),
626
- mintDuration: BigInt(tokenConfig.mintDuration),
627
- maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
628
- }
629
- }
630
- };
631
- }
632
- };
633
- var convertGetPremintApiResponse = (response) => ({
634
- ...convertPremintFromApi(response.premint),
635
- collection: convertCollectionFromApi(response.collection),
636
- collectionAddress: response.collection_address,
637
- signature: response.signature
638
- });
639
- var encodePremintV1ForAPI = ({
640
- tokenConfig,
641
- ...premint
642
- }) => ({
643
- ...premint,
644
- config_version: "1",
645
- tokenConfig: {
646
- ...tokenConfig,
647
- maxSupply: tokenConfig.maxSupply.toString(),
648
- pricePerToken: tokenConfig.pricePerToken.toString(),
649
- mintStart: tokenConfig.mintStart.toString(),
650
- mintDuration: tokenConfig.mintDuration.toString(),
651
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
652
- }
653
- });
654
- var encodePremintV2ForAPI = ({
655
- tokenConfig,
656
- ...premint
657
- }) => ({
658
- ...premint,
659
- config_version: "2",
660
- tokenConfig: {
661
- ...tokenConfig,
662
- maxSupply: tokenConfig.maxSupply.toString(),
663
- pricePerToken: tokenConfig.pricePerToken.toString(),
664
- mintStart: tokenConfig.mintStart.toString(),
665
- mintDuration: tokenConfig.mintDuration.toString(),
666
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
667
- }
668
- });
669
- var encodePremintForAPI = ({
670
- premintConfig,
671
- premintConfigVersion
672
- }) => {
673
- if (premintConfigVersion === PremintConfigVersion.V1) {
674
- return encodePremintV1ForAPI(premintConfig);
675
- }
676
- if (premintConfigVersion === PremintConfigVersion.V2) {
677
- return encodePremintV2ForAPI(premintConfig);
678
- }
679
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
680
- };
681
- var encodePostSignatureInput = ({
682
- collection,
683
- collectionAddress,
684
- premintConfigVersion,
685
- premintConfig,
686
- signature,
687
- chainId
688
- }) => ({
689
- premint: encodePremintForAPI({
690
- premintConfig,
691
- premintConfigVersion
692
- }),
693
- signature,
694
- collection,
695
- collection_address: collectionAddress,
696
- chain_name: networkConfigByChain[chainId].zoraBackendChainName
697
- });
639
+ }
640
+ throw err;
641
+ }
642
+ };
643
+ var httpClient = {
644
+ get,
645
+ post,
646
+ retries
647
+ };
698
648
 
699
- // src/premint/premint-api-client.ts
700
- var postSignature = async ({
701
- httpClient: { post: post2, retries: retries2 } = httpClient,
702
- ...data
703
- }) => retries2(
704
- () => post2(`${ZORA_API_BASE}premint/signature`, data)
705
- );
706
- var getNextUID = async ({
707
- chain_name,
708
- collection_address,
709
- httpClient: { retries: retries2, get: get2 } = httpClient
710
- }) => retries2(
711
- () => get2(
712
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
713
- )
714
- );
715
- var getSignature = async ({
716
- collection_address,
717
- uid,
718
- chain_name,
719
- httpClient: { retries: retries2, get: get2 } = httpClient
720
- }) => {
721
- const result = await retries2(
722
- () => get2(
723
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
724
- )
725
- );
726
- return result;
649
+ // src/mint/subgraph-mint-getter.ts
650
+ var getApiNetworkConfigForChain = (chainId) => {
651
+ if (!networkConfigByChain[chainId]) {
652
+ throw new Error(`chain id ${chainId} network not configured `);
653
+ }
654
+ return networkConfigByChain[chainId];
727
655
  };
728
- var PremintAPIClient = class {
656
+ var SubgraphMintGetter = class {
729
657
  constructor(chainId, httpClient2) {
730
- this.postSignature = async ({
731
- signature,
732
- ...rest
733
- }) => {
734
- const data = encodePostSignatureInput({
735
- ...rest,
736
- chainId: this.networkConfig.chainId,
737
- signature
738
- });
739
- return postSignature({
740
- ...data,
741
- httpClient: this.httpClient
742
- });
743
- };
744
- this.getNextUID = async (collectionAddress) => (await getNextUID({
745
- collection_address: collectionAddress.toLowerCase(),
746
- chain_name: this.networkConfig.zoraBackendChainName,
747
- httpClient: this.httpClient
748
- })).next_uid;
749
- this.getSignature = async ({
750
- collectionAddress,
751
- uid
752
- }) => {
753
- const response = await getSignature({
754
- collection_address: collectionAddress.toLowerCase(),
755
- uid,
756
- chain_name: this.networkConfig.zoraBackendChainName,
757
- httpClient: this.httpClient
758
- });
759
- return convertGetPremintApiResponse(response);
760
- };
761
658
  this.httpClient = httpClient2 || httpClient;
762
659
  this.networkConfig = getApiNetworkConfigForChain(chainId);
763
660
  }
661
+ async getSalesConfigAndTokenInfo({
662
+ tokenAddress,
663
+ tokenId,
664
+ saleType
665
+ }) {
666
+ const { retries: retries2, post: post2 } = this.httpClient;
667
+ return retries2(async () => {
668
+ const response = await post2(this.networkConfig.subgraphUrl, {
669
+ query: NFT_SALE_QUERY,
670
+ variables: {
671
+ id: tokenId !== void 0 ? (
672
+ // Generic Token ID types all stringify down to the base numeric equivalent.
673
+ `${tokenAddress.toLowerCase()}-${tokenId}`
674
+ ) : `${tokenAddress.toLowerCase()}-0`
675
+ }
676
+ });
677
+ const token = response.data?.zoraCreateToken;
678
+ if (!token) {
679
+ throw new Error("Cannot find a token to mint");
680
+ }
681
+ const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
682
+ const saleStrategies = allStrategies.sort(
683
+ (a, b) => BigInt(
684
+ a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
685
+ ) > BigInt(
686
+ b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
687
+ ) ? 1 : -1
688
+ );
689
+ let targetStrategy;
690
+ if (!saleType) {
691
+ targetStrategy = saleStrategies[0];
692
+ if (!targetStrategy) {
693
+ throw new Error("Cannot find sale strategy");
694
+ }
695
+ } else {
696
+ const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
697
+ targetStrategy = saleStrategies.find(
698
+ (strategy) => strategy.type === mappedSaleType
699
+ );
700
+ if (!targetStrategy) {
701
+ throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
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
+ });
732
+ }
764
733
  };
765
734
 
766
735
  // src/utils.ts
767
- import {
768
- createPublicClient,
769
- http
770
- } from "viem";
771
- var makeSimulateContractParamaters = (args) => args;
772
- function setupClient({ chain, httpClient: httpClient2, publicClient }) {
773
- return {
774
- chain,
775
- httpClient: httpClient2 || httpClient,
776
- publicClient: publicClient || createPublicClient({ chain, transport: http() })
777
- };
736
+ var makeContractParameters = (args) => args;
737
+ function mintRecipientOrAccount({
738
+ mintRecipient,
739
+ minterAccount
740
+ }) {
741
+ return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
778
742
  }
779
743
 
780
744
  // src/premint/premint-client.ts
@@ -782,8 +746,7 @@ var defaultTokenConfigV1MintArguments = () => ({
782
746
  maxSupply: OPEN_EDITION_MINT_SIZE,
783
747
  maxTokensPerAddress: 0n,
784
748
  pricePerToken: 0n,
785
- mintDuration: BigInt(60 * 60 * 24 * 7),
786
- // 1 week
749
+ mintDuration: 0n,
787
750
  mintStart: 0n,
788
751
  royaltyMintSchedule: 0,
789
752
  royaltyBPS: 1e3
@@ -824,8 +787,7 @@ var defaultTokenConfigV2MintArguments = () => ({
824
787
  maxSupply: OPEN_EDITION_MINT_SIZE,
825
788
  maxTokensPerAddress: 0n,
826
789
  pricePerToken: 0n,
827
- mintDuration: BigInt(60 * 60 * 24 * 7),
828
- // 1 week
790
+ mintDuration: 0n,
829
791
  mintStart: 0n,
830
792
  royaltyBPS: 1e3
831
793
  // 10%,
@@ -872,20 +834,17 @@ function getPremintedLogFromReceipt(receipt) {
872
834
  }
873
835
  }
874
836
  var PremintClient = class {
875
- constructor(chain, publicClient, httpClient2) {
876
- this.chain = chain;
877
- this.apiClient = new PremintAPIClient(chain.id, httpClient2);
837
+ constructor({
838
+ chainId,
839
+ publicClient,
840
+ premintApi
841
+ }) {
842
+ this.chainId = chainId;
843
+ this.apiClient = premintApi;
878
844
  this.publicClient = publicClient;
879
845
  }
880
- getDataFromPremintReceipt(receipt) {
881
- const premintedLog = getPremintedLogFromReceipt(receipt);
882
- return {
883
- premintedLog,
884
- urls: this.makeUrls({
885
- address: premintedLog?.contractAddress,
886
- tokenId: premintedLog?.tokenId
887
- })
888
- };
846
+ getDataFromPremintReceipt(receipt, blockExplorerUrl) {
847
+ return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
889
848
  }
890
849
  /**
891
850
  * Prepares data for updating a premint
@@ -898,7 +857,7 @@ var PremintClient = class {
898
857
  ...args,
899
858
  apiClient: this.apiClient,
900
859
  publicClient: this.publicClient,
901
- chainId: this.chain.id
860
+ chainId: this.chainId
902
861
  });
903
862
  }
904
863
  /**
@@ -912,7 +871,7 @@ var PremintClient = class {
912
871
  ...params,
913
872
  apiClient: this.apiClient,
914
873
  publicClient: this.publicClient,
915
- chainId: this.chain.id
874
+ chainId: this.chainId
916
875
  });
917
876
  }
918
877
  /**
@@ -926,7 +885,7 @@ var PremintClient = class {
926
885
  ...parameters,
927
886
  publicClient: this.publicClient,
928
887
  apiClient: this.apiClient,
929
- chainId: this.chain.id
888
+ chainId: this.chainId
930
889
  });
931
890
  }
932
891
  /**
@@ -936,10 +895,7 @@ var PremintClient = class {
936
895
  * @param uid UID for the desired premint
937
896
  * @returns PremintSignatureGetResponse of premint data from the API
938
897
  */
939
- async getPremintSignature({
940
- address,
941
- uid
942
- }) {
898
+ async getPremint({ address, uid }) {
943
899
  return await this.apiClient.getSignature({
944
900
  collectionAddress: address,
945
901
  uid
@@ -952,48 +908,9 @@ var PremintClient = class {
952
908
  */
953
909
  async getCollectionAddress(collection) {
954
910
  return await getPremintCollectionAddress({
955
- collection,
956
- publicClient: this.publicClient
957
- });
958
- }
959
- /**
960
- * Check user signature for v1
961
- *
962
- * @param data Signature data from the API
963
- * @returns isValid = signature is valid or not, recoveredSigner = signer from contract
964
- */
965
- async isValidSignature({
966
- signature,
967
- premintConfig,
968
- premintConfigVersion,
969
- ...collectionAndOrAddress
970
- }) {
971
- const collectionAddressToUse = await getPremintCollectionAddress({
972
- ...collectionAndOrAddress,
911
+ contract: collection,
973
912
  publicClient: this.publicClient
974
913
  });
975
- const { isAuthorized, recoveredAddress } = await isValidSignature({
976
- chainId: this.chain.id,
977
- signature,
978
- publicClient: this.publicClient,
979
- premintConfig,
980
- premintConfigVersion: premintConfigVersion || PremintConfigVersion2.V1,
981
- collectionAddress: collectionAddressToUse,
982
- collection: collectionAndOrAddress.collection
983
- });
984
- return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
985
- }
986
- makeUrls({
987
- uid,
988
- address,
989
- tokenId
990
- }) {
991
- return makeUrls({
992
- uid,
993
- address,
994
- tokenId,
995
- chain: this.chain
996
- });
997
914
  }
998
915
  async getMintCosts({
999
916
  tokenContract,
@@ -1014,17 +931,40 @@ var PremintClient = class {
1014
931
  * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
1015
932
  * @returns receipt, log, zoraURL
1016
933
  */
1017
- async makeMintParameters(parameters) {
1018
- return await makeMintParameters({
1019
- ...parameters,
1020
- 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,
1021
951
  publicClient: this.publicClient
1022
952
  });
1023
953
  }
1024
954
  };
1025
- function createPremintClient(clientConfig) {
1026
- const { chain, httpClient: httpClient2, publicClient } = setupClient(clientConfig);
1027
- 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
+ };
1028
968
  }
1029
969
  function makePremintReturn({
1030
970
  premintConfig,
@@ -1054,7 +994,7 @@ function makePremintReturn({
1054
994
  await submit({
1055
995
  signature,
1056
996
  checkSignature,
1057
- signerAccount
997
+ account: signerAccount
1058
998
  });
1059
999
  return {
1060
1000
  signature,
@@ -1064,7 +1004,7 @@ function makePremintReturn({
1064
1004
  const submit = async ({
1065
1005
  signature,
1066
1006
  checkSignature,
1067
- signerAccount
1007
+ account
1068
1008
  }) => {
1069
1009
  if (checkSignature) {
1070
1010
  const isAuthorized = await isAuthorizedToCreatePremint({
@@ -1072,7 +1012,7 @@ function makePremintReturn({
1072
1012
  additionalAdmins: collection?.additionalAdmins,
1073
1013
  contractAdmin: collection?.contractAdmin,
1074
1014
  publicClient,
1075
- signer: signerAccount
1015
+ signer: account
1076
1016
  });
1077
1017
  if (!isAuthorized) {
1078
1018
  throw new Error("Not authorized to create premint");
@@ -1115,7 +1055,7 @@ async function signPremint({
1115
1055
  };
1116
1056
  }
1117
1057
  async function createPremint({
1118
- tokenCreationConfig,
1058
+ token: tokenCreationConfig,
1119
1059
  uid,
1120
1060
  publicClient,
1121
1061
  apiClient,
@@ -1138,7 +1078,7 @@ async function createPremint({
1138
1078
  premintConfig,
1139
1079
  premintConfigVersion,
1140
1080
  collectionAddress: collectionAddressToUse,
1141
- collection: collectionOrAddress.collection,
1081
+ collection: collectionOrAddress.contract,
1142
1082
  publicClient,
1143
1083
  apiClient,
1144
1084
  chainId
@@ -1245,32 +1185,32 @@ async function deletePremint({
1245
1185
  chainId
1246
1186
  });
1247
1187
  }
1248
- async function makeMintParameters({
1188
+ async function collectPremint({
1249
1189
  uid,
1250
1190
  tokenContract,
1251
1191
  minterAccount,
1252
- mintArguments,
1192
+ quantityToMint,
1193
+ mintComment = "",
1194
+ mintReferral,
1195
+ mintRecipient,
1253
1196
  firstMinter,
1254
- apiClient,
1197
+ premintGetter,
1255
1198
  publicClient
1256
1199
  }) {
1257
- if (mintArguments && mintArguments?.quantityToMint < 1) {
1200
+ if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
1258
1201
  throw new Error("Quantity to mint cannot be below 1");
1259
1202
  }
1260
- if (!minterAccount) {
1261
- throw new Error("Wallet not passed in");
1262
- }
1263
1203
  const {
1264
1204
  premintConfig,
1265
1205
  premintConfigVersion,
1266
1206
  collection,
1267
1207
  collectionAddress,
1268
1208
  signature
1269
- } = await apiClient.getSignature({
1209
+ } = await premintGetter.getSignature({
1270
1210
  collectionAddress: tokenContract,
1271
1211
  uid
1272
1212
  });
1273
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1213
+ const numberToMint = BigInt(quantityToMint || 1);
1274
1214
  if (premintConfigVersion === PremintConfigVersion2.V3) {
1275
1215
  throw new Error("PremintV3 not supported in premint SDK");
1276
1216
  }
@@ -1279,18 +1219,21 @@ async function makeMintParameters({
1279
1219
  quantityToMint: numberToMint,
1280
1220
  publicClient,
1281
1221
  tokenPrice: premintConfig.tokenConfig.pricePerToken
1282
- })).totalCost;
1222
+ })).totalCostEth;
1283
1223
  const mintArgumentsContract = {
1284
- mintComment: mintArguments?.mintComment || "",
1285
- mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1224
+ mintComment,
1225
+ mintRecipient: mintRecipientOrAccount({
1226
+ mintRecipient,
1227
+ minterAccount
1228
+ }),
1286
1229
  mintRewardsRecipients: makeMintRewardsRecipient({
1287
- mintReferral: mintArguments?.mintReferral
1230
+ mintReferral
1288
1231
  })
1289
1232
  };
1290
1233
  const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
1291
1234
  const collectionAddressToSubmit = collection ? zeroAddress2 : collectionAddress;
1292
1235
  const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
1293
- return makeSimulateContractParamaters({
1236
+ return makeContractParameters({
1294
1237
  account: minterAccount,
1295
1238
  abi: zoraCreator1155PremintExecutorImplABI2,
1296
1239
  functionName: "premint",
@@ -1315,15 +1258,16 @@ function makeUrls({
1315
1258
  uid,
1316
1259
  address,
1317
1260
  tokenId,
1318
- chain
1261
+ chainId,
1262
+ blockExplorerUrl
1319
1263
  }) {
1320
1264
  if ((!uid || !tokenId) && !address) {
1321
1265
  return { explorer: null, zoraCollect: null, zoraManage: null };
1322
1266
  }
1323
1267
  const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
1324
- const network = getApiNetworkConfigForChain(chain.id);
1268
+ const network = getApiNetworkConfigForChain(chainId);
1325
1269
  return {
1326
- explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1270
+ explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
1327
1271
  zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
1328
1272
  zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
1329
1273
  };
@@ -1340,11 +1284,79 @@ var PremintConfigVersion3 = ((PremintConfigVersion4) => {
1340
1284
  return PremintConfigVersion4;
1341
1285
  })(PremintConfigVersion3 || {});
1342
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
+
1343
1354
  // src/mint/mint-client.ts
1344
1355
  import {
1345
1356
  encodeAbiParameters,
1346
1357
  parseAbiParameters,
1347
- zeroAddress as zeroAddress3
1358
+ zeroAddress as zeroAddress3,
1359
+ erc20Abi
1348
1360
  } from "viem";
1349
1361
  import {
1350
1362
  erc20MinterABI,
@@ -1352,6 +1364,15 @@ import {
1352
1364
  zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
1353
1365
  zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
1354
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
1355
1376
  var MintError = class extends Error {
1356
1377
  };
1357
1378
  var MintInactiveError = class extends Error {
@@ -1361,265 +1382,612 @@ var Errors = {
1361
1382
  MintInactiveError
1362
1383
  };
1363
1384
  var MintClient = class {
1364
- constructor(chain, publicClient, httpClient2) {
1365
- this.apiClient = new MintAPIClient(chain.id, httpClient2);
1385
+ constructor({
1386
+ chainId,
1387
+ publicClient,
1388
+ premintGetter,
1389
+ mintGetter
1390
+ }) {
1391
+ this.chainId = chainId;
1366
1392
  this.publicClient = publicClient;
1393
+ this.mintGetter = mintGetter;
1394
+ this.premintGetter = premintGetter;
1367
1395
  }
1368
1396
  /**
1369
1397
  * Returns the parameters needed to prepare a transaction mint a token.
1398
+ * Works with premint, onchain 1155, and onchain 721.
1370
1399
  *
1371
- * @param parameters - Parameters for collecting the token {@link MintTokenParams}
1400
+ * @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
1372
1401
  * @returns Parameters for simulating/executing the mint transaction
1373
1402
  */
1374
- async makePrepareMintTokenParams(parameters) {
1375
- 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({
1376
1419
  ...parameters,
1377
- apiClient: this.apiClient,
1420
+ mintGetter: this.mintGetter,
1421
+ premintGetter: this.premintGetter,
1378
1422
  publicClient: this.publicClient
1379
1423
  });
1380
1424
  }
1381
1425
  };
1382
- function createMintClient(clientConfig) {
1383
- const { chain, publicClient, httpClient: httpClient2 } = setupClient(clientConfig);
1384
- return new MintClient(chain, publicClient, httpClient2);
1426
+ function isPremintCollect(parameters) {
1427
+ return parameters.mintType === "premint";
1428
+ }
1429
+ function is721Collect(parameters) {
1430
+ return parameters.mintType === "721";
1385
1431
  }
1386
- async function makePrepareMintTokenParams({
1432
+ async function mint({
1433
+ parameters,
1434
+ chainId,
1387
1435
  publicClient,
1388
- apiClient,
1389
- tokenId,
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({
1450
+ ...parameters,
1451
+ mintGetter,
1452
+ chainId
1453
+ })
1454
+ };
1455
+ }
1456
+ function requestErc20ApprovalForMint({
1457
+ account,
1390
1458
  tokenAddress,
1391
- mintArguments,
1392
- ...rest
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
1494
+ });
1495
+ }
1496
+ return void 0;
1497
+ }
1498
+ async function collectOnchain({
1499
+ chainId,
1500
+ mintGetter,
1501
+ ...parameters
1393
1502
  }) {
1394
- 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({
1395
1506
  tokenId,
1396
- tokenAddress,
1397
- saleType: mintArguments.saleType
1507
+ tokenAddress: tokenContract,
1508
+ saleType
1398
1509
  });
1399
- if (tokenId === void 0) {
1510
+ if (is721Collect(parameters)) {
1400
1511
  return makePrepareMint721TokenParams({
1401
1512
  salesConfigAndTokenInfo,
1402
- tokenAddress,
1403
- mintArguments,
1404
- ...rest
1513
+ ...parameters
1405
1514
  });
1406
1515
  }
1407
1516
  return makePrepareMint1155TokenParams({
1408
1517
  salesConfigAndTokenInfo,
1409
- tokenAddress,
1410
- tokenId,
1411
- mintArguments,
1412
- ...rest
1518
+ chainId,
1519
+ ...parameters
1413
1520
  });
1414
1521
  }
1415
1522
  async function makePrepareMint721TokenParams({
1416
- tokenAddress,
1417
1523
  salesConfigAndTokenInfo,
1418
1524
  minterAccount,
1419
- mintArguments
1525
+ tokenContract,
1526
+ mintComment,
1527
+ mintReferral,
1528
+ mintRecipient,
1529
+ quantityToMint
1420
1530
  }) {
1421
- const mintValue = getMintCosts({
1531
+ const actualQuantityToMint = BigInt(quantityToMint || 1);
1532
+ const mintValue = parseMintCosts({
1422
1533
  salesConfigAndTokenInfo,
1423
- quantityToMint: BigInt(mintArguments.quantityToMint)
1424
- }).totalCost;
1425
- return makeSimulateContractParamaters({
1534
+ quantityToMint: actualQuantityToMint
1535
+ }).totalCostEth;
1536
+ return makeContractParameters({
1426
1537
  abi: zora721Abi,
1427
- address: tokenAddress,
1538
+ address: tokenContract,
1428
1539
  account: minterAccount,
1429
1540
  functionName: "mintWithRewards",
1430
1541
  value: mintValue,
1431
1542
  args: [
1432
- mintArguments.mintToAddress,
1433
- BigInt(mintArguments.quantityToMint),
1434
- mintArguments.mintComment || "",
1435
- mintArguments.mintReferral || zeroAddress3
1543
+ mintRecipientOrAccount({ mintRecipient, minterAccount }),
1544
+ actualQuantityToMint,
1545
+ mintComment || "",
1546
+ mintReferral || zeroAddress3
1436
1547
  ]
1437
1548
  });
1438
1549
  }
1439
- function getMintCosts({
1550
+ function parseMintCosts({
1440
1551
  salesConfigAndTokenInfo,
1441
1552
  quantityToMint
1442
1553
  }) {
1443
1554
  const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
1444
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;
1445
1560
  return {
1446
1561
  mintFee: mintFeeForTokens,
1447
- tokenPurchaseCost,
1448
- totalCost: mintFeeForTokens + tokenPurchaseCost
1562
+ totalPurchaseCost: tokenPurchaseCost,
1563
+ totalPurchaseCostCurrency,
1564
+ totalCostEth: mintFeeForTokens + totalPurchaseCostEth
1449
1565
  };
1450
1566
  }
1451
- 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,
1452
1590
  tokenId,
1453
1591
  salesConfigAndTokenInfo,
1454
1592
  minterAccount,
1455
- tokenAddress,
1456
- mintArguments
1593
+ mintComment,
1594
+ mintReferral,
1595
+ mintRecipient,
1596
+ quantityToMint,
1597
+ chainId
1457
1598
  }) {
1458
- const mintQuantity = BigInt(mintArguments.quantityToMint);
1459
- const mintValue = getMintCosts({
1460
- salesConfigAndTokenInfo,
1461
- quantityToMint: mintQuantity
1462
- }).totalCost;
1463
- switch (salesConfigAndTokenInfo.salesConfig.saleType) {
1464
- case "fixedPrice":
1465
- const fixedPriceArgs = mintArguments;
1466
- return makeSimulateContractParamaters({
1467
- abi: zoraCreator1155ImplABI2,
1468
- functionName: "mintWithRewards",
1469
- account: minterAccount,
1470
- value: mintValue,
1471
- address: tokenAddress,
1472
- /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1473
- args: [
1474
- salesConfigAndTokenInfo.salesConfig.address || zoraCreatorFixedPriceSaleStrategyAddress2[999999999],
1475
- BigInt(tokenId),
1476
- mintQuantity,
1477
- encodeAbiParameters(parseAbiParameters("address, string"), [
1478
- fixedPriceArgs.mintToAddress,
1479
- fixedPriceArgs.mintComment || ""
1480
- ]),
1481
- fixedPriceArgs.mintReferral || zeroAddress3
1482
- ]
1483
- });
1484
- case "erc20":
1485
- const erc20Args = mintArguments;
1486
- return makeSimulateContractParamaters({
1487
- abi: erc20MinterABI,
1488
- functionName: "mint",
1489
- account: minterAccount,
1490
- address: salesConfigAndTokenInfo?.salesConfig.address || erc20MinterAddress[999999999],
1491
- /* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
1492
- args: [
1493
- mintArguments.mintToAddress,
1494
- mintQuantity,
1495
- tokenAddress,
1496
- BigInt(tokenId),
1497
- salesConfigAndTokenInfo.salesConfig.pricePerToken,
1498
- salesConfigAndTokenInfo.salesConfig.currency,
1499
- erc20Args.mintReferral || zeroAddress3,
1500
- erc20Args.mintComment || ""
1501
- ]
1502
- });
1503
- default:
1504
- 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
+ });
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
+ });
1505
1644
  }
1645
+ throw new MintError("Unsupported sale type");
1506
1646
  }
1507
1647
 
1508
1648
  // src/create/1155-create-helper.ts
1509
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,
1510
1659
  zoraCreator1155FactoryImplABI,
1511
1660
  zoraCreator1155FactoryImplAddress,
1512
- zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
1513
- zoraCreatorFixedPriceSaleStrategyABI
1661
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI3
1514
1662
  } from "@zoralabs/protocol-deployments";
1515
- import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
1516
- var SALE_END_FOREVER = 18446744073709551615n;
1517
- var ROYALTY_BPS_DEFAULT = 1e3;
1518
- var DEFAULT_SALE_SETTINGS = {
1519
- fundsRecipient: zeroAddress4,
1520
- // Free Mint
1521
- pricePerToken: 0n,
1522
- // Sale start time – defaults to beginning of unix time
1523
- saleStart: 0n,
1524
- // This is the end of uint64, plenty of time
1525
- saleEnd: SALE_END_FOREVER,
1526
- // 0 Here means no limit
1527
- maxTokensPerAddress: 0n
1528
- };
1529
- var PERMISSION_BIT_MINTER = 4n;
1530
- function create1155TokenSetupArgs({
1531
- nextTokenId,
1532
- // How many NFTs upon initialization to mint to the creator
1533
- mintToCreatorCount,
1534
- tokenMetadataURI,
1535
- // Fixed price minter address – required minter
1536
- fixedPriceMinterAddress,
1537
- // Address to use as the create referral, optional.
1538
- createReferral,
1539
- // Optional max supply of the token. Default unlimited
1540
- maxSupply,
1541
- // wallet sending the transaction
1542
- account,
1543
- salesConfig,
1544
- 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
1545
1675
  }) {
1546
- if (!maxSupply) {
1547
- 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;
1548
1700
  }
1549
- maxSupply = BigInt(maxSupply);
1550
- mintToCreatorCount = BigInt(mintToCreatorCount);
1551
- const salesConfigWithDefaults = {
1552
- // 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 {
1553
1741
  ...DEFAULT_SALE_SETTINGS,
1554
- // Override with user settings.
1555
- ...salesConfig
1742
+ ...saleSettings
1556
1743
  };
1557
- const setupActions = [
1558
- encodeFunctionData({
1559
- abi: zoraCreator1155ImplABI3,
1560
- functionName: "assumeLastTokenIdMatches",
1561
- args: [nextTokenId - 1n]
1562
- }),
1563
- createReferral ? encodeFunctionData({
1564
- 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,
1565
1868
  functionName: "setupNewTokenWithCreateReferral",
1566
- args: [tokenMetadataURI, maxSupply, createReferral]
1567
- }) : encodeFunctionData({
1568
- abi: zoraCreator1155ImplABI3,
1569
- functionName: "setupNewToken",
1570
- args: [tokenMetadataURI, maxSupply]
1571
- }),
1572
- encodeFunctionData({
1573
- abi: zoraCreator1155ImplABI3,
1574
- functionName: "addPermission",
1575
- args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
1576
- }),
1577
- encodeFunctionData({
1578
- abi: zoraCreator1155ImplABI3,
1579
- 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",
1580
1892
  args: [
1581
1893
  nextTokenId,
1582
- fixedPriceMinterAddress,
1583
- encodeFunctionData({
1584
- abi: zoraCreatorFixedPriceSaleStrategyABI,
1585
- functionName: "setSale",
1586
- args: [nextTokenId, salesConfigWithDefaults]
1587
- })
1894
+ {
1895
+ royaltyBPS,
1896
+ royaltyRecipient,
1897
+ royaltyMintSchedule: 0
1898
+ }
1588
1899
  ]
1589
- })
1590
- ];
1591
- if (mintToCreatorCount) {
1592
- setupActions.push(
1593
- encodeFunctionData({
1594
- abi: zoraCreator1155ImplABI3,
1595
- functionName: "adminMint",
1596
- args: [account, nextTokenId, mintToCreatorCount, "0x"]
1597
- })
1598
- );
1900
+ });
1599
1901
  }
1600
- if (royaltySettings) {
1601
- setupActions.push(
1602
- encodeFunctionData({
1603
- abi: zoraCreator1155ImplABI3,
1604
- functionName: "updateRoyaltiesForToken",
1605
- args: [
1606
- nextTokenId,
1607
- {
1608
- royaltyMintSchedule: 0,
1609
- royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1610
- royaltyRecipient: royaltySettings?.royaltyRecipient || account
1611
- }
1612
- ]
1613
- })
1614
- );
1902
+ return null;
1903
+ }
1904
+ function makeAdminMintCall({
1905
+ ownerAddress,
1906
+ mintQuantity,
1907
+ nextTokenId
1908
+ }) {
1909
+ if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
1910
+ return null;
1615
1911
  }
1616
- 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
+ };
1617
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;
1618
1986
  var getTokenIdFromCreateReceipt = (receipt) => {
1619
1987
  for (const data of receipt.logs) {
1620
1988
  try {
1621
1989
  const decodedLog = decodeEventLog2({
1622
- abi: zoraCreator1155ImplABI3,
1990
+ abi: zoraCreator1155ImplABI5,
1623
1991
  eventName: "SetupNewToken",
1624
1992
  ...data
1625
1993
  });
@@ -1630,132 +1998,116 @@ var getTokenIdFromCreateReceipt = (receipt) => {
1630
1998
  }
1631
1999
  }
1632
2000
  };
1633
- async function getContractExists(publicClient, contract, account) {
1634
- let contractAddress;
1635
- let contractExists = false;
1636
- if (typeof contract !== "string") {
1637
- contractAddress = await publicClient.readContract({
1638
- abi: zoraCreator1155FactoryImplABI,
1639
- // Since this address is deterministic we can hardcode a chain id safely here.
1640
- address: zoraCreator1155FactoryImplAddress[999],
1641
- 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],
1642
2023
  args: [
1643
- account,
1644
2024
  contract.uri,
1645
2025
  contract.name,
1646
- 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
1647
2034
  ]
1648
2035
  });
1649
- try {
1650
- await publicClient.readContract({
1651
- abi: zoraCreator1155ImplABI3,
1652
- address: contractAddress,
1653
- functionName: "contractVersion"
1654
- });
1655
- contractExists = true;
1656
- } catch (e) {
1657
- }
1658
- return { contractAddress, contractExists };
1659
2036
  }
1660
- return {
1661
- contractExists: true,
1662
- contractAddress: contract
1663
- };
1664
- }
1665
- function create1155CreatorClient(clientConfig) {
1666
- const { publicClient } = setupClient(clientConfig);
1667
- async function createNew1155Token({
1668
- contract,
1669
- tokenMetadataURI,
1670
- mintToCreatorCount = 1,
1671
- salesConfig = {},
1672
- maxSupply,
2037
+ return makeContractParameters({
2038
+ abi: zoraCreator1155ImplABI5,
2039
+ functionName: "multicall",
1673
2040
  account,
1674
- royaltySettings,
1675
- createReferral,
1676
- getAdditionalSetupActions
2041
+ address: contractAddress,
2042
+ args: [tokenSetupActions]
2043
+ });
2044
+ }
2045
+ var Create1155Client = class {
2046
+ constructor({
2047
+ chainId,
2048
+ publicClient
1677
2049
  }) {
1678
- const { contractExists, contractAddress } = await getContractExists(
1679
- publicClient,
1680
- contract,
1681
- account
1682
- );
1683
- let nextTokenId = 1n;
1684
- if (contractExists) {
1685
- nextTokenId = await publicClient.readContract({
1686
- abi: zoraCreator1155ImplABI3,
1687
- functionName: "nextTokenId",
1688
- address: contractAddress
1689
- });
1690
- }
1691
- const fixedPriceMinterAddress = await publicClient.readContract({
1692
- abi: zoraCreator1155FactoryImplABI,
1693
- address: zoraCreator1155FactoryImplAddress[999],
1694
- functionName: "fixedPriceMinter"
1695
- });
1696
- let tokenSetupActions = create1155TokenSetupArgs({
1697
- tokenMetadataURI,
1698
- nextTokenId,
1699
- salesConfig,
1700
- maxSupply,
1701
- fixedPriceMinterAddress,
1702
- account,
1703
- mintToCreatorCount,
1704
- royaltySettings,
1705
- 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
1706
2058
  });
1707
- if (getAdditionalSetupActions) {
1708
- tokenSetupActions = [
1709
- ...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
1710
- ...tokenSetupActions
1711
- ];
1712
- }
1713
- if (!contractAddress && typeof contract === "string") {
1714
- throw new Error("Invariant: contract cannot be missing and an address");
1715
- }
1716
- if (!contractExists && typeof contract !== "string") {
1717
- const request = makeSimulateContractParamaters({
1718
- abi: zoraCreator1155FactoryImplABI,
1719
- functionName: "createContractDeterministic",
1720
- account,
1721
- address: zoraCreator1155FactoryImplAddress[999],
1722
- args: [
1723
- contract.uri,
1724
- contract.name,
1725
- {
1726
- // deprecated
1727
- royaltyMintSchedule: 0,
1728
- royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1729
- royaltyRecipient: royaltySettings?.royaltyRecipient || account
1730
- },
1731
- contract.defaultAdmin || account,
1732
- tokenSetupActions
1733
- ]
1734
- });
1735
- return {
1736
- request,
1737
- tokenSetupActions,
1738
- contractAddress,
1739
- contractExists
1740
- };
1741
- } else if (contractExists) {
1742
- const request = makeSimulateContractParamaters({
1743
- abi: zoraCreator1155ImplABI3,
1744
- functionName: "multicall",
1745
- account,
1746
- address: contractAddress,
1747
- args: [tokenSetupActions]
1748
- });
1749
- return {
1750
- request,
1751
- tokenSetupActions,
1752
- contractAddress,
1753
- contractExists
1754
- };
1755
- }
1756
- throw new Error("Unsupported contract argument type");
1757
2059
  }
1758
- 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
+ };
1759
2111
  }
1760
2112
 
1761
2113
  // src/mints/mints-queries.ts
@@ -1835,7 +2187,7 @@ var mintWithEthParams = ({
1835
2187
  chainId,
1836
2188
  pricePerMint,
1837
2189
  account
1838
- }) => makeSimulateContractParamaters({
2190
+ }) => makeContractParameters({
1839
2191
  abi: zoraMintsManagerImplConfig.abi,
1840
2192
  address: zoraMintsManagerImplConfig.address[chainId],
1841
2193
  functionName: "mintWithEth",
@@ -1891,7 +2243,7 @@ function collectWithMintsParams({
1891
2243
  minter,
1892
2244
  mintArguments
1893
2245
  });
1894
- return makeSimulateContractParamaters({
2246
+ return makeContractParameters({
1895
2247
  abi: zoraMints1155Config.abi,
1896
2248
  address: zoraMints1155Config.address[chainId],
1897
2249
  functionName: "transferBatchToManagerAndCall",
@@ -2037,7 +2389,7 @@ function collectPremintV2WithMintsParams({
2037
2389
  const call = encodePremintOnManager({
2038
2390
  ...rest
2039
2391
  });
2040
- return makeSimulateContractParamaters({
2392
+ return makeContractParameters({
2041
2393
  abi: zoraMints1155Config.abi,
2042
2394
  address: zoraMints1155Config.address[chainId],
2043
2395
  functionName: "transferBatchToManagerAndCall",
@@ -2090,23 +2442,63 @@ var unwrapAndForwardEthPermitAndTypedDataDefinition = ({
2090
2442
  to: mintsEthUnwrapperAndCallerAddress[chainId],
2091
2443
  nonce
2092
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
+ }
2093
2483
  export {
2094
- DEFAULT_SALE_SETTINGS,
2484
+ Create1155Client,
2095
2485
  Errors,
2096
- MintAPIClient,
2486
+ MintClient,
2097
2487
  PremintAPIClient,
2488
+ PremintClient,
2098
2489
  PremintConfigVersion3 as PremintConfigVersion,
2490
+ SubgraphMintGetter,
2099
2491
  ZORA_API_BASE,
2100
2492
  applyUpdateToPremint,
2493
+ collectOnchain,
2494
+ collectPremint,
2101
2495
  collectPremintV2WithMintsParams,
2102
2496
  collectWithMintsParams,
2103
2497
  convertCollectionFromApi,
2104
2498
  convertGetPremintApiResponse,
2105
2499
  convertPremintFromApi,
2106
- create1155CreatorClient,
2107
- create1155TokenSetupArgs,
2108
- createMintClient,
2109
- createPremintClient,
2500
+ createCollectorClient,
2501
+ createCreatorClient,
2110
2502
  decodeCallFailedError,
2111
2503
  defaultAdditionalAdmins,
2112
2504
  defaultTokenConfigV1MintArguments,
@@ -2116,17 +2508,24 @@ export {
2116
2508
  encodePostSignatureInput,
2117
2509
  encodePremintForAPI,
2118
2510
  getApiNetworkConfigForChain,
2511
+ getDataFromPremintReceipt,
2119
2512
  getDefaultFixedPriceMinterAddress,
2120
2513
  getMintCosts,
2121
2514
  getMintsAccountBalanceWithPriceQuery,
2122
2515
  getMintsEthPrice,
2516
+ getNecessaryErc20Approval,
2123
2517
  getPremintCollectionAddress,
2124
2518
  getPremintExecutorAddress,
2125
2519
  getPremintMintCosts,
2520
+ getPremintMintCostsWithUnknownTokenPrice,
2126
2521
  getPremintMintFee,
2522
+ getPremintPricePerToken,
2127
2523
  getPremintedLogFromReceipt,
2524
+ getSignature,
2128
2525
  getTokenIdFromCreateReceipt,
2129
2526
  isAuthorizedToCreatePremint,
2527
+ isPremintConfigV1,
2528
+ isPremintConfigV2,
2130
2529
  isValidSignature,
2131
2530
  makeCallWithEthSafeTransferData,
2132
2531
  makeMintRewardsRecipient,
@@ -2134,12 +2533,15 @@ export {
2134
2533
  makePermitToCollectPremintOrNonPremint,
2135
2534
  makePermitTransferBatchAndTypeData,
2136
2535
  makePermitTransferTypeData,
2536
+ makePrepareMint1155TokenParams,
2137
2537
  makeUrls,
2138
2538
  migratePremintConfigToV2,
2139
2539
  mintWithEthParams,
2140
2540
  mintsBalanceOfAccountParams,
2541
+ parseMintCosts,
2141
2542
  recoverCreatorFromCreatorAttribution,
2142
2543
  recoverPremintSigner,
2544
+ requestErc20ApprovalForMint,
2143
2545
  selectMintsToCollectWithFromQueryResult,
2144
2546
  sumBalances,
2145
2547
  supportedPremintVersions,