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