@zoralabs/protocol-sdk 0.3.4 → 0.4.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 (44) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +34 -0
  3. package/README.md +30 -58
  4. package/dist/anvil.d.ts +4 -2
  5. package/dist/anvil.d.ts.map +1 -1
  6. package/dist/constants.d.ts +32 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/index.cjs +819 -518
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +788 -493
  13. package/dist/index.js.map +1 -1
  14. package/dist/mint/mint-api-client.d.ts +16 -216
  15. package/dist/mint/mint-api-client.d.ts.map +1 -1
  16. package/dist/mint/mint-client.d.ts +7 -227
  17. package/dist/mint/mint-client.d.ts.map +1 -1
  18. package/dist/premint/contract-types.d.ts +125 -0
  19. package/dist/premint/contract-types.d.ts.map +1 -0
  20. package/dist/premint/premint-api-client.d.ts +14 -7
  21. package/dist/premint/premint-api-client.d.ts.map +1 -1
  22. package/dist/premint/premint-client.d.ts +45 -115
  23. package/dist/premint/premint-client.d.ts.map +1 -1
  24. package/dist/premint/preminter.d.ts +102 -21
  25. package/dist/premint/preminter.d.ts.map +1 -1
  26. package/dist/types.d.ts +2 -0
  27. package/dist/types.d.ts.map +1 -0
  28. package/package.json +1 -1
  29. package/src/anvil.ts +7 -4
  30. package/src/constants.ts +7 -0
  31. package/src/index.ts +2 -0
  32. package/src/mint/mint-api-client.ts +72 -68
  33. package/src/mint/mint-client.test.ts +9 -11
  34. package/src/mint/mint-client.ts +51 -221
  35. package/src/premint/contract-types.ts +109 -0
  36. package/src/premint/premint-api-client.ts +162 -22
  37. package/src/premint/premint-client.test.ts +186 -84
  38. package/src/premint/premint-client.ts +357 -289
  39. package/src/premint/preminter.test.ts +209 -130
  40. package/src/premint/preminter.ts +377 -54
  41. package/src/types.ts +1 -0
  42. package/dist/apis/generated/discover-api-types.d.ts +0 -2131
  43. package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
  44. package/src/apis/generated/discover-api-types.ts +0 -2180
@@ -1,4 +1,4 @@
1
- import { createPublicClient, decodeEventLog, http } from "viem";
1
+ import { createPublicClient, decodeEventLog, http, zeroAddress } from "viem";
2
2
  import type {
3
3
  Account,
4
4
  Address,
@@ -11,14 +11,31 @@ import type {
11
11
  } from "viem";
12
12
  import {
13
13
  zoraCreator1155PremintExecutorImplABI,
14
- zoraCreator1155PremintExecutorImplAddress,
15
14
  zoraCreatorFixedPriceSaleStrategyAddress,
16
15
  } from "@zoralabs/protocol-deployments";
17
- import { PremintConfig, preminterTypedDataDefinition } from "./preminter";
18
- import type {
19
- PremintSignatureGetResponse,
20
- PremintSignatureResponse,
21
- } from "./premint-api-client";
16
+ import {
17
+ getPremintCollectionAddress,
18
+ premintTypedDataDefinition,
19
+ isValidSignature,
20
+ isAuthorizedToCreatePremint,
21
+ getPremintExecutorAddress,
22
+ applyUpdateToPremint,
23
+ markPremintDeleted,
24
+ makeNewPremint,
25
+ supportsPremintVersion,
26
+ } from "./preminter";
27
+ import {
28
+ PremintConfigV2,
29
+ PremintConfigVersion,
30
+ ContractCreationConfig,
31
+ TokenConfigForVersion,
32
+ PremintConfigWithVersion,
33
+ TokenCreationConfigV1,
34
+ TokenCreationConfigV2,
35
+ TokenCreationConfig,
36
+ PremintConfigForVersion,
37
+ } from "./contract-types";
38
+ import type { PremintSignatureResponse } from "./premint-api-client";
22
39
  import { PremintAPIClient } from "./premint-api-client";
23
40
  import type { DecodeEventLogReturnType } from "viem";
24
41
  import { OPEN_EDITION_MINT_SIZE } from "../constants";
@@ -26,19 +43,6 @@ import { REWARD_PER_TOKEN } from "src/apis/chain-constants";
26
43
  import { IHttpClient } from "src/apis/http-api-base";
27
44
  import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
28
45
 
29
- type MintArgumentsSettings = {
30
- tokenURI: string;
31
- maxSupply?: bigint;
32
- maxTokensPerAddress?: bigint;
33
- pricePerToken?: bigint;
34
- mintStart?: bigint;
35
- mintDuration?: bigint;
36
- royaltyMintSchedule?: number;
37
- royaltyBPS?: number;
38
- royaltyRecipient?: Address;
39
- fixedPriceMinter?: Address;
40
- };
41
-
42
46
  type PremintedLogType = DecodeEventLogReturnType<
43
47
  typeof zoraCreator1155PremintExecutorImplABI,
44
48
  "Preminted"
@@ -57,7 +61,10 @@ type SignedPremintResponse = {
57
61
  premint: PremintSignatureResponse;
58
62
  };
59
63
 
60
- export const DefaultMintArguments = {
64
+ export const defaultTokenConfigV1MintArguments = (): Omit<
65
+ TokenCreationConfigV1,
66
+ "fixedPriceMinter" | "tokenURI" | "royaltyRecipient"
67
+ > => ({
61
68
  maxSupply: OPEN_EDITION_MINT_SIZE,
62
69
  maxTokensPerAddress: 0n,
63
70
  pricePerToken: 0n,
@@ -65,6 +72,50 @@ export const DefaultMintArguments = {
65
72
  mintStart: 0n,
66
73
  royaltyMintSchedule: 0,
67
74
  royaltyBPS: 1000, // 10%,
75
+ });
76
+
77
+ export const defaultTokenConfigV2MintArguments = (): Omit<
78
+ TokenCreationConfigV2,
79
+ "fixedPriceMinter" | "tokenURI" | "payoutRecipient" | "createReferral"
80
+ > => ({
81
+ maxSupply: OPEN_EDITION_MINT_SIZE,
82
+ maxTokensPerAddress: 0n,
83
+ pricePerToken: 0n,
84
+ mintDuration: BigInt(60 * 60 * 24 * 7), // 1 week
85
+ mintStart: 0n,
86
+ royaltyBPS: 1000, // 10%,
87
+ });
88
+
89
+ const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
90
+ premintConfigVersion,
91
+ tokenCreationConfig,
92
+ creatorAccount,
93
+ }: {
94
+ premintConfigVersion: PremintConfigVersion;
95
+ tokenCreationConfig: Partial<TokenConfigForVersion<T>> & { tokenURI: string };
96
+ creatorAccount: Address;
97
+ }): TokenConfigForVersion<T> => {
98
+ const fixedPriceMinter =
99
+ tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
100
+
101
+ if (premintConfigVersion === PremintConfigVersion.V1) {
102
+ return {
103
+ fixedPriceMinter,
104
+ ...defaultTokenConfigV1MintArguments(),
105
+ royaltyRecipient: creatorAccount,
106
+ ...tokenCreationConfig,
107
+ };
108
+ } else if (premintConfigVersion === PremintConfigVersion.V2) {
109
+ return {
110
+ fixedPriceMinter,
111
+ ...defaultTokenConfigV2MintArguments(),
112
+ payoutRecipient: creatorAccount,
113
+ createReferral: zeroAddress,
114
+ ...tokenCreationConfig,
115
+ };
116
+ } else {
117
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
118
+ }
68
119
  };
69
120
 
70
121
  /**
@@ -89,57 +140,6 @@ export function getPremintedLogFromReceipt(
89
140
  } catch (err: any) {}
90
141
  }
91
142
  }
92
-
93
- /**
94
- * Convert server to on-chain types for a premint
95
- *
96
- * @param premint Premint object from the server to convert to one that's compatible with viem
97
- * @returns Viem type-compatible premint object
98
- */
99
- export const convertPremint = (
100
- premint: PremintSignatureGetResponse["premint"],
101
- ) => ({
102
- ...premint,
103
- tokenConfig: {
104
- ...premint.tokenConfig,
105
- fixedPriceMinter: premint.tokenConfig.fixedPriceMinter as Address,
106
- royaltyRecipient: premint.tokenConfig.royaltyRecipient as Address,
107
- maxSupply: BigInt(premint.tokenConfig.maxSupply),
108
- pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
109
- mintStart: BigInt(premint.tokenConfig.mintStart),
110
- mintDuration: BigInt(premint.tokenConfig.mintDuration),
111
- maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress),
112
- },
113
- });
114
-
115
- export const convertCollection = (
116
- collection: PremintSignatureGetResponse["collection"],
117
- ) => ({
118
- ...collection,
119
- contractAdmin: collection.contractAdmin as Address,
120
- });
121
-
122
- /**
123
- * Convert on-chain types for a premint to a server safe type
124
- *
125
- * @param premint Premint object from viem to convert to a JSON compatible type.
126
- * @returns JSON compatible premint
127
- */
128
- export const encodePremintForAPI = ({
129
- tokenConfig,
130
- ...premint
131
- }: PremintConfig) => ({
132
- ...premint,
133
- tokenConfig: {
134
- ...tokenConfig,
135
- maxSupply: tokenConfig.maxSupply.toString(),
136
- pricePerToken: tokenConfig.pricePerToken.toString(),
137
- mintStart: tokenConfig.mintStart.toString(),
138
- mintDuration: tokenConfig.mintDuration.toString(),
139
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString(),
140
- },
141
- });
142
-
143
143
  /**
144
144
  * Preminter API to access ZORA Premint functionality.
145
145
  * Currently only supports V1 premints.
@@ -160,27 +160,6 @@ class PremintClient {
160
160
  publicClient || createPublicClient({ chain, transport: http() });
161
161
  }
162
162
 
163
- /**
164
- * The premint executor address is deployed to the same address across all chains.
165
- * Can be overridden as needed by making a parent class.
166
- *
167
- * @returns Executor address for premints
168
- */
169
- getExecutorAddress() {
170
- return zoraCreator1155PremintExecutorImplAddress[999];
171
- }
172
-
173
- /**
174
- * The fixed price minter address is the same across all chains for our current
175
- * deployer strategy.
176
- * Can be overridden as needed by making a parent class.
177
- *
178
- * @returns Fixed price sale strategy
179
- */
180
- getFixedPriceMinterAddress() {
181
- return zoraCreatorFixedPriceSaleStrategyAddress[999];
182
- }
183
-
184
163
  getDataFromPremintReceipt(receipt: TransactionReceipt) {
185
164
  const premintedLog = getPremintedLogFromReceipt(receipt);
186
165
  return {
@@ -214,43 +193,39 @@ class PremintClient {
214
193
  walletClient,
215
194
  uid,
216
195
  collection,
217
- token,
218
196
  account,
197
+ tokenConfigUpdates,
219
198
  }: {
220
199
  walletClient: WalletClient;
221
200
  uid: number;
222
- token: MintArgumentsSettings;
223
201
  account?: Account | Address;
224
202
  collection: Address;
203
+ tokenConfigUpdates: Partial<TokenCreationConfig>;
225
204
  }): Promise<SignedPremintResponse> {
226
- const signatureResponse = await this.apiClient.getSignature({
227
- collection_address: collection.toLowerCase(),
205
+ const {
206
+ premintConfig,
207
+ collection: collectionCreationConfig,
208
+ premintConfigVersion,
209
+ } = await this.apiClient.getSignature({
210
+ collectionAddress: collection,
228
211
  uid: uid,
229
212
  });
230
213
 
231
- const convertedPremint = convertPremint(signatureResponse.premint);
232
- const signerData = {
233
- ...signatureResponse,
234
- premint: {
235
- ...convertedPremint,
236
- tokenConfig: {
237
- ...convertedPremint.tokenConfig,
238
- ...token,
239
- },
240
- },
241
- };
214
+ const updatedPremint = applyUpdateToPremint({
215
+ uid: premintConfig.uid,
216
+ version: premintConfig.version,
217
+ tokenConfig: premintConfig.tokenConfig,
218
+ tokenConfigUpdates: tokenConfigUpdates,
219
+ });
242
220
 
243
221
  return await this.signAndSubmitPremint({
244
222
  walletClient,
245
223
  account,
246
- checkSignature: false,
224
+ checkSignature: true,
247
225
  verifyingContract: collection,
248
- uid: uid,
249
- collection: {
250
- ...signerData.collection,
251
- contractAdmin: signerData.collection.contractAdmin as Address,
252
- },
253
- premintConfig: signerData.premint,
226
+ collection: collectionCreationConfig,
227
+ premintConfig: updatedPremint,
228
+ premintConfigVersion: premintConfigVersion,
254
229
  });
255
230
  }
256
231
 
@@ -279,28 +254,25 @@ class PremintClient {
279
254
  account?: Account | Address;
280
255
  collection: Address;
281
256
  }) {
282
- const signatureResponse = await this.apiClient.getSignature({
283
- collection_address: collection.toLowerCase(),
257
+ const {
258
+ premintConfig,
259
+ premintConfigVersion,
260
+ collection: collectionCreationConfig,
261
+ } = await this.apiClient.getSignature({
262
+ collectionAddress: collection,
284
263
  uid: uid,
285
264
  });
286
265
 
287
- const signerData = {
288
- ...signatureResponse,
289
- collection: convertCollection(signatureResponse.collection),
290
- premint: {
291
- ...convertPremint(signatureResponse.premint),
292
- deleted: true,
293
- },
294
- };
266
+ const deletedPremint = markPremintDeleted(premintConfig);
295
267
 
296
268
  return await this.signAndSubmitPremint({
297
269
  walletClient,
298
270
  account,
299
271
  checkSignature: false,
300
272
  verifyingContract: collection,
301
- uid: uid,
302
- collection: signerData.collection,
303
- premintConfig: signerData.premint,
273
+ collection: collectionCreationConfig,
274
+ premintConfig: deletedPremint,
275
+ premintConfigVersion,
304
276
  });
305
277
  }
306
278
 
@@ -310,58 +282,17 @@ class PremintClient {
310
282
  * @param premintArguments Arguments to premint
311
283
  * @returns
312
284
  */
313
- private async signAndSubmitPremint({
314
- walletClient,
315
- verifyingContract,
316
- premintConfig,
317
- uid,
318
- account,
319
- checkSignature,
320
- collection,
321
- }: {
322
- uid: number;
323
- walletClient: WalletClient;
324
- verifyingContract: Address;
325
- checkSignature: boolean;
326
- account?: Address | Account;
327
- premintConfig: PremintConfig;
328
- collection: PremintSignatureGetResponse["collection"];
329
- }) {
330
- if (!account) {
331
- account = walletClient.account;
332
- }
333
- if (!account) {
334
- throw new Error("No account provided");
335
- }
336
-
337
- const signature = await walletClient.signTypedData({
338
- account,
339
- ...preminterTypedDataDefinition({
340
- verifyingContract,
341
- premintConfig,
342
- chainId: this.chain.id,
343
- }),
285
+ private async signAndSubmitPremint<T extends PremintConfigVersion>(
286
+ params: SignAndSubmitPremintParams<T>,
287
+ ) {
288
+ const { premint, verifyingContract } = await signAndSubmitPremint({
289
+ ...params,
290
+ chainId: this.chain.id,
291
+ apiClient: this.apiClient,
292
+ publicClient: this.publicClient,
344
293
  });
345
294
 
346
- if (checkSignature) {
347
- const [isValidSignature] = await this.publicClient.readContract({
348
- abi: zoraCreator1155PremintExecutorImplABI,
349
- address: this.getExecutorAddress(),
350
- functionName: "isValidSignature",
351
- args: [convertCollection(collection), premintConfig, signature],
352
- });
353
- if (!isValidSignature) {
354
- throw new Error("Invalid signature");
355
- }
356
- }
357
-
358
- const apiData = {
359
- collection,
360
- premint: encodePremintForAPI(premintConfig),
361
- signature: signature,
362
- };
363
-
364
- const premint = await this.apiClient.postSignature(apiData);
295
+ const uid = params.premintConfig.uid;
365
296
 
366
297
  return {
367
298
  urls: this.makeUrls({ address: verifyingContract, uid }),
@@ -377,74 +308,73 @@ class PremintClient {
377
308
  * @param settings Settings for the new premint
378
309
  * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
379
310
  * @param settings.collection Collection information for the mint
380
- * @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
381
- * @param settings.publicClient Public client (optional) – instantiated if not passed in with defaults.
382
- * @param settings.walletClient Required wallet client for signing the premint message.
383
- * @param settings.executionSettings Execution settings for premint options
384
- * @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
385
- * @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
311
+ * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
312
+ * @param setings.premintConfigVersion Premint config version to use, defaults to V2
313
+ * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
386
314
  * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
387
315
  * @returns premint url, uid, newContractAddress, and premint object
388
316
  */
389
- async createPremint({
390
- account,
317
+ async createPremint<
318
+ T extends PremintConfigVersion = PremintConfigVersion.V1,
319
+ >({
320
+ creatorAccount,
391
321
  collection,
392
- token,
322
+ tokenCreationConfig,
323
+ premintConfigVersion,
393
324
  walletClient,
394
- executionSettings,
325
+ uid,
395
326
  checkSignature = false,
396
327
  }: {
397
- account: Address;
328
+ creatorAccount: Address;
398
329
  checkSignature?: boolean;
399
330
  walletClient: WalletClient;
400
- collection: PremintSignatureGetResponse["collection"];
401
- token: MintArgumentsSettings;
402
- executionSettings?: {
403
- deleted?: boolean;
404
- uid?: number;
331
+ collection: ContractCreationConfig;
332
+ tokenCreationConfig: Partial<TokenConfigForVersion<T>> & {
333
+ tokenURI: string;
405
334
  };
335
+ premintConfigVersion?: T;
336
+ uid?: number;
406
337
  }) {
407
- const newContractAddress = await this.publicClient.readContract({
408
- address: this.getExecutorAddress(),
409
- abi: zoraCreator1155PremintExecutorImplABI,
410
- functionName: "getContractAddress",
411
- args: [convertCollection(collection)],
338
+ const newContractAddress = await getPremintCollectionAddress({
339
+ publicClient: this.publicClient,
340
+ collection,
412
341
  });
413
342
 
414
- const tokenConfig = {
415
- ...DefaultMintArguments,
416
- fixedPriceMinter: this.getFixedPriceMinterAddress(),
417
- royaltyRecipient: account,
418
- ...token,
419
- };
343
+ let uidToUse = uid;
420
344
 
421
- let uid = executionSettings?.uid;
422
- if (!uid) {
423
- const uidResponse = await this.apiClient.getNextUID({
424
- collection_address: newContractAddress.toLowerCase(),
425
- });
426
- uid = uidResponse.next_uid;
345
+ if (typeof uidToUse !== "number") {
346
+ uidToUse = await this.apiClient.getNextUID(newContractAddress);
427
347
  }
428
348
 
429
- if (!uid) {
430
- throw new Error("UID is missing but required");
349
+ const actualVersion = premintConfigVersion || PremintConfigVersion.V1;
350
+
351
+ if (
352
+ !(await supportsPremintVersion({
353
+ version: actualVersion,
354
+ publicClient: this.publicClient,
355
+ tokenContract: newContractAddress,
356
+ }))
357
+ ) {
358
+ throw new Error(
359
+ `Premint version ${actualVersion} not supported by contract`,
360
+ );
431
361
  }
432
362
 
433
- let deleted = executionSettings?.deleted || false;
434
-
435
- const premintConfig = {
436
- tokenConfig: tokenConfig,
437
- uid,
438
- version: 1,
439
- deleted,
440
- };
363
+ const premintConfig = makeNewPremint({
364
+ tokenConfig: makeTokenConfigWithDefaults({
365
+ premintConfigVersion: actualVersion,
366
+ tokenCreationConfig,
367
+ creatorAccount,
368
+ }),
369
+ uid: uidToUse,
370
+ });
441
371
 
442
372
  return await this.signAndSubmitPremint({
443
- uid,
444
373
  verifyingContract: newContractAddress,
445
374
  premintConfig,
375
+ premintConfigVersion: actualVersion,
446
376
  checkSignature,
447
- account,
377
+ account: creatorAccount,
448
378
  walletClient,
449
379
  collection,
450
380
  });
@@ -457,47 +387,61 @@ class PremintClient {
457
387
  * @param uid UID for the desired premint
458
388
  * @returns PremintSignatureGetResponse of premint data from the API
459
389
  */
460
- async getPremintData({
390
+ async getPremintSignature({
461
391
  address,
462
392
  uid,
463
393
  }: {
464
- address: string;
394
+ address: Address;
465
395
  uid: number;
466
- }): Promise<PremintSignatureGetResponse> {
396
+ }) {
467
397
  return await this.apiClient.getSignature({
468
- collection_address: address,
398
+ collectionAddress: address,
469
399
  uid,
470
400
  });
471
401
  }
472
402
 
403
+ /**
404
+ * Gets the deterministic contract address for a premint collection
405
+ * @param collection Collection to get the address for
406
+ * @returns deterministic contract address
407
+ */
408
+ async getCollectionAddress(collection: ContractCreationConfig) {
409
+ return await getPremintCollectionAddress({
410
+ collection,
411
+ publicClient: this.publicClient,
412
+ });
413
+ }
414
+
473
415
  /**
474
416
  * Check user signature for v1
475
417
  *
476
418
  * @param data Signature data from the API
477
- * @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
419
+ * @returns isValid = signature is valid or not, recoveredSigner = signer from contract
478
420
  */
479
- async isValidSignature({
480
- data,
421
+ async isValidSignature<T extends PremintConfigVersion>({
422
+ signature,
423
+ collection,
424
+ premintConfig,
425
+ premintConfigVersion,
481
426
  }: {
482
- data: PremintSignatureGetResponse;
427
+ signature: Hex;
428
+ collection: ContractCreationConfig;
429
+ premintConfig: PremintConfigForVersion<T>;
430
+ premintConfigVersion?: T;
483
431
  }): Promise<{
484
432
  isValid: boolean;
485
- contractAddress: Address;
486
- recoveredSigner: Address;
433
+ recoveredSigner: Address | undefined;
487
434
  }> {
488
- const [isValid, contractAddress, recoveredSigner] =
489
- await this.publicClient.readContract({
490
- abi: zoraCreator1155PremintExecutorImplABI,
491
- address: this.getExecutorAddress(),
492
- functionName: "isValidSignature",
493
- args: [
494
- convertCollection(data.collection),
495
- convertPremint(data.premint),
496
- data.signature as Hex,
497
- ],
498
- });
435
+ const { isAuthorized, recoveredAddress } = await isValidSignature({
436
+ chainId: this.chain.id,
437
+ signature: signature as Hex,
438
+ collection: collection,
439
+ publicClient: this.publicClient,
440
+ premintConfig,
441
+ premintConfigVersion: premintConfigVersion || PremintConfigVersion.V1,
442
+ });
499
443
 
500
- return { isValid, contractAddress, recoveredSigner };
444
+ return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
501
445
  }
502
446
 
503
447
  protected makeUrls({
@@ -509,29 +453,12 @@ class PremintClient {
509
453
  tokenId?: bigint;
510
454
  address?: Address;
511
455
  }): URLSReturnType {
512
- if ((!uid || !tokenId) && !address) {
513
- return { explorer: null, zoraCollect: null, zoraManage: null };
514
- }
515
-
516
- const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
517
-
518
- const network = getApiNetworkConfigForChain(this.chain.id);
519
-
520
- return {
521
- explorer: tokenId
522
- ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}`
523
- : null,
524
- zoraCollect: `https://${
525
- network.isTestnet ? "testnet." : ""
526
- }zora.co/collect/${
527
- network.zoraPathChainName
528
- }:${address}/${zoraTokenPath}`,
529
- zoraManage: `https://${
530
- network.isTestnet ? "testnet." : ""
531
- }zora.co/collect/${
532
- network.zoraPathChainName
533
- }:${address}/${zoraTokenPath}`,
534
- };
456
+ return makeUrls({
457
+ uid,
458
+ address,
459
+ tokenId,
460
+ chain: this.chain,
461
+ });
535
462
  }
536
463
 
537
464
  /**
@@ -547,47 +474,87 @@ class PremintClient {
547
474
  * @returns receipt, log, zoraURL
548
475
  */
549
476
  async makeMintParameters({
550
- data,
477
+ uid,
478
+ tokenContract,
551
479
  account,
552
480
  mintArguments,
553
481
  }: {
554
- data: PremintSignatureGetResponse;
482
+ uid: number;
483
+ tokenContract: Address;
555
484
  account: Account | Address;
556
485
  mintArguments?: {
557
486
  quantityToMint: number;
558
487
  mintComment?: string;
488
+ mintReferral?: Address;
489
+ mintRecipient?: Address;
559
490
  };
560
491
  }): Promise<SimulateContractParameters> {
561
492
  if (mintArguments && mintArguments?.quantityToMint < 1) {
562
493
  throw new Error("Quantity to mint cannot be below 1");
563
494
  }
564
495
 
565
- const targetAddress = this.getExecutorAddress();
566
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
567
- const args = [
568
- convertCollection(data.collection),
569
- convertPremint(data.premint),
570
- data.signature as Hex,
571
- numberToMint,
572
- mintArguments?.mintComment || "",
573
- ] as const;
574
-
575
496
  if (!account) {
576
497
  throw new Error("Wallet not passed in");
577
498
  }
578
499
 
500
+ const { premintConfig, premintConfigVersion, collection, signature } =
501
+ await this.getPremintSignature({
502
+ address: tokenContract,
503
+ uid,
504
+ });
505
+
506
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
507
+
579
508
  const value = numberToMint * REWARD_PER_TOKEN;
580
509
 
581
- const request: SimulateContractParameters = {
582
- account,
583
- abi: zoraCreator1155PremintExecutorImplABI,
584
- functionName: "premint",
585
- value,
586
- address: targetAddress,
587
- args,
588
- };
510
+ if (premintConfigVersion === PremintConfigVersion.V1) {
511
+ return {
512
+ account,
513
+ abi: zoraCreator1155PremintExecutorImplABI,
514
+ functionName: "premint",
515
+ value,
516
+ address: getPremintExecutorAddress(),
517
+ args: [
518
+ collection,
519
+ premintConfig,
520
+ signature,
521
+ numberToMint,
522
+ mintArguments?.mintComment || "",
523
+ ],
524
+ } satisfies SimulateContractParameters<
525
+ typeof zoraCreator1155PremintExecutorImplABI,
526
+ "premint"
527
+ >;
528
+ } else if (premintConfigVersion === PremintConfigVersion.V2) {
529
+ const toPost = premintConfig as PremintConfigV2;
530
+ const accountAddress =
531
+ typeof account === "string" ? account : account.address;
532
+
533
+ return {
534
+ account,
535
+ abi: zoraCreator1155PremintExecutorImplABI,
536
+ functionName: "premintV2",
537
+ value,
538
+ address: getPremintExecutorAddress(),
539
+ // args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
540
+ args: [
541
+ collection,
542
+ toPost,
543
+ signature,
544
+ numberToMint,
545
+ {
546
+ mintComment: mintArguments?.mintComment || "",
547
+ mintRecipient: mintArguments?.mintRecipient || accountAddress,
548
+ mintReferral: mintArguments?.mintReferral || zeroAddress,
549
+ },
550
+ ],
551
+ } satisfies SimulateContractParameters<
552
+ typeof zoraCreator1155PremintExecutorImplABI,
553
+ "premintV2"
554
+ >;
555
+ }
589
556
 
590
- return request;
557
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
591
558
  }
592
559
  }
593
560
 
@@ -602,3 +569,104 @@ export function createPremintClient({
602
569
  }) {
603
570
  return new PremintClient(chain, publicClient, httpClient);
604
571
  }
572
+
573
+ function makeUrls({
574
+ uid,
575
+ address,
576
+ tokenId,
577
+ chain,
578
+ }: {
579
+ uid?: number;
580
+ tokenId?: bigint;
581
+ address?: Address;
582
+ chain: Chain;
583
+ }): URLSReturnType {
584
+ if ((!uid || !tokenId) && !address) {
585
+ return { explorer: null, zoraCollect: null, zoraManage: null };
586
+ }
587
+
588
+ const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
589
+
590
+ const network = getApiNetworkConfigForChain(chain.id);
591
+
592
+ return {
593
+ explorer: tokenId
594
+ ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}`
595
+ : null,
596
+ zoraCollect: `https://${
597
+ network.isTestnet ? "testnet." : ""
598
+ }zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
599
+ zoraManage: `https://${
600
+ network.isTestnet ? "testnet." : ""
601
+ }zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
602
+ };
603
+ }
604
+
605
+ type SignAndSubmitPremintParams<T extends PremintConfigVersion> = {
606
+ walletClient: WalletClient;
607
+ verifyingContract: Address;
608
+ checkSignature: boolean;
609
+ account?: Address | Account;
610
+ collection: ContractCreationConfig;
611
+ } & PremintConfigWithVersion<T>;
612
+
613
+ async function signAndSubmitPremint<T extends PremintConfigVersion>({
614
+ walletClient,
615
+ verifyingContract,
616
+ account,
617
+ checkSignature,
618
+ collection,
619
+ chainId,
620
+ publicClient,
621
+ apiClient,
622
+ ...premintConfigAndVersion
623
+ }: SignAndSubmitPremintParams<T> & {
624
+ chainId: number;
625
+ publicClient: PublicClient;
626
+ apiClient: PremintAPIClient;
627
+ }) {
628
+ if (!account) {
629
+ account = walletClient.account;
630
+ }
631
+ if (!account) {
632
+ throw new Error("No account provided");
633
+ }
634
+
635
+ const signature = await walletClient.signTypedData({
636
+ account,
637
+ ...premintTypedDataDefinition({
638
+ verifyingContract,
639
+ ...premintConfigAndVersion,
640
+ chainId,
641
+ }),
642
+ });
643
+
644
+ if (checkSignature) {
645
+ const isAuthorized = await isAuthorizedToCreatePremint({
646
+ collection,
647
+ signature,
648
+ publicClient,
649
+ signer: typeof account === "string" ? account : account.address,
650
+ collectionAddress: await getPremintCollectionAddress({
651
+ collection,
652
+ publicClient,
653
+ }),
654
+ ...premintConfigAndVersion,
655
+ });
656
+ if (!isAuthorized) {
657
+ throw new Error("Not authorized to create premint");
658
+ }
659
+ }
660
+
661
+ const premint = await apiClient.postSignature({
662
+ collection: collection,
663
+ signature: signature,
664
+ ...premintConfigAndVersion,
665
+ });
666
+
667
+ return { premint, verifyingContract };
668
+ }
669
+
670
+ function getDefaultFixedPriceMinterAddress() {
671
+ return zoraCreatorFixedPriceSaleStrategyAddress[999];
672
+ }