@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
@@ -2,50 +2,57 @@ import { decodeEventLog, zeroAddress } from "viem";
2
2
  import type {
3
3
  Account,
4
4
  Address,
5
- Chain,
6
5
  Hex,
7
6
  SimulateContractParameters,
8
7
  TransactionReceipt,
9
8
  TypedDataDefinition,
10
9
  WalletClient,
11
10
  } from "viem";
12
- import { zoraCreator1155PremintExecutorImplABI } from "@zoralabs/protocol-deployments";
11
+ import {
12
+ PremintConfigAndVersion,
13
+ TokenConfigWithVersion,
14
+ encodePremintConfig,
15
+ zoraCreator1155PremintExecutorImplABI,
16
+ } from "@zoralabs/protocol-deployments";
13
17
  import {
14
18
  getPremintCollectionAddress,
15
- isValidSignature,
16
19
  isAuthorizedToCreatePremint,
17
20
  getPremintExecutorAddress,
18
21
  applyUpdateToPremint,
19
22
  makeNewPremint,
20
- supportsPremintVersion,
23
+ supportedPremintVersions,
21
24
  getPremintMintCosts,
22
25
  makeMintRewardsRecipient,
23
26
  getDefaultFixedPriceMinterAddress,
27
+ emptyContractCreationConfig,
28
+ defaultAdditionalAdmins,
29
+ toContractCreationConfigOrAddress,
24
30
  } from "./preminter";
25
31
  import {
26
32
  PremintConfigVersion,
27
33
  ContractCreationConfig,
28
- TokenConfigForVersion,
29
34
  TokenCreationConfigV1,
30
35
  TokenCreationConfigV2,
31
36
  TokenCreationConfig,
32
- PremintConfigForVersion,
33
37
  PremintConfigWithVersion,
34
38
  PremintMintArguments,
35
39
  premintTypedDataDefinition,
36
40
  } from "@zoralabs/protocol-deployments";
37
- import { PremintAPIClient } from "./premint-api-client";
41
+ import { IPremintAPI, IPremintGetter } from "./premint-api-client";
38
42
  import type { DecodeEventLogReturnType } from "viem";
39
43
  import { OPEN_EDITION_MINT_SIZE } from "../constants";
40
- import { IHttpClient } from "src/apis/http-api-base";
41
- import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
44
+ import { getApiNetworkConfigForChain } from "src/mint/subgraph-mint-getter";
42
45
  import { MintCosts } from "src/mint/mint-client";
43
46
  import {
44
- ClientConfig,
45
- makeSimulateContractParamaters,
47
+ makeContractParameters,
48
+ mintRecipientOrAccount,
46
49
  PublicClient,
47
- setupClient,
48
50
  } from "src/utils";
51
+ import {
52
+ ContractCreationConfigAndAddress,
53
+ ContractCreationConfigOrAddress,
54
+ } from "./contract-types";
55
+ import { MakePremintMintParametersArguments } from "src/mint/types";
49
56
 
50
57
  type PremintedV2LogType = DecodeEventLogReturnType<
51
58
  typeof zoraCreator1155PremintExecutorImplABI,
@@ -65,12 +72,53 @@ export const defaultTokenConfigV1MintArguments = (): Omit<
65
72
  maxSupply: OPEN_EDITION_MINT_SIZE,
66
73
  maxTokensPerAddress: 0n,
67
74
  pricePerToken: 0n,
68
- mintDuration: BigInt(60 * 60 * 24 * 7), // 1 week
75
+ mintDuration: 0n,
69
76
  mintStart: 0n,
70
77
  royaltyMintSchedule: 0,
71
78
  royaltyBPS: 1000, // 10%,
72
79
  });
73
80
 
81
+ const pickTokenConfigV1 = (tokenConfig: TokenConfigInput) => ({
82
+ maxSupply: tokenConfig.maxSupply,
83
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
84
+ pricePerToken: tokenConfig.pricePerToken,
85
+ mintDuration: tokenConfig.mintDuration,
86
+ mintStart: tokenConfig.mintStart,
87
+ royaltyBPS: tokenConfig.royaltyBPS,
88
+ tokenURI: tokenConfig.tokenURI,
89
+ royaltyRecipient: tokenConfig.payoutRecipient,
90
+ });
91
+
92
+ const pickTokenConfigV2 = (tokenConfig: TokenConfigInput) => ({
93
+ maxSupply: tokenConfig.maxSupply,
94
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
95
+ pricePerToken: tokenConfig.pricePerToken,
96
+ mintDuration: tokenConfig.mintDuration,
97
+ mintStart: tokenConfig.mintStart,
98
+ royaltyBPS: tokenConfig.royaltyBPS,
99
+ tokenURI: tokenConfig.tokenURI,
100
+ payoutRecipient: tokenConfig.payoutRecipient,
101
+ createReferral: tokenConfig.createReferral || zeroAddress,
102
+ });
103
+
104
+ const tokenConfigV1WithDefault = (
105
+ tokenConfig: TokenConfigInput,
106
+ fixedPriceMinter: Address,
107
+ ): TokenCreationConfigV1 => ({
108
+ ...pickTokenConfigV1(tokenConfig),
109
+ ...defaultTokenConfigV1MintArguments(),
110
+ fixedPriceMinter,
111
+ });
112
+
113
+ const tokenConfigV2WithDefault = (
114
+ tokenConfig: TokenConfigInput,
115
+ fixedPriceMinter: Address,
116
+ ): TokenCreationConfigV2 => ({
117
+ ...pickTokenConfigV2(tokenConfig),
118
+ ...defaultTokenConfigV2MintArguments(),
119
+ fixedPriceMinter,
120
+ });
121
+
74
122
  export const defaultTokenConfigV2MintArguments = (): Omit<
75
123
  TokenCreationConfigV2,
76
124
  "fixedPriceMinter" | "tokenURI" | "payoutRecipient" | "createReferral"
@@ -78,51 +126,67 @@ export const defaultTokenConfigV2MintArguments = (): Omit<
78
126
  maxSupply: OPEN_EDITION_MINT_SIZE,
79
127
  maxTokensPerAddress: 0n,
80
128
  pricePerToken: 0n,
81
- mintDuration: BigInt(60 * 60 * 24 * 7), // 1 week
129
+ mintDuration: 0n,
82
130
  mintStart: 0n,
83
131
  royaltyBPS: 1000, // 10%,
84
132
  });
85
133
 
86
- const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
134
+ type TokenConfigInput = {
135
+ /** Metadata URI of the token to create. */
136
+ tokenURI: string;
137
+ /** Account to receive creator rewards if it's a free mint, and token price value if its a paid mint. Defaults to the premint signing account. */
138
+ payoutRecipient: Address;
139
+ /** Optional: account to receive the create referral award. */
140
+ createReferral?: Address;
141
+ /** Optional: max supply of tokens that can be minted. Defaults to unlimited. */
142
+ maxSupply?: bigint;
143
+ /** Optional: max tokens that can be minted for an address, 0 if unlimited. Defaults to unlimited. */
144
+ maxTokensPerAddress?: bigint;
145
+ /** Optional: price per token, if this is a paid mint. 0 if a free mint. Defaults to 0, or a free mint. */
146
+ pricePerToken?: bigint;
147
+ /** Optional: duration of the mint, starting from the time the premint is brought onchain. 0 for infinite. Defaults to infinite. */
148
+ mintDuration?: bigint;
149
+ /** Optional: earliest time the premint can be brought onchain and minted. 0 for immediately. Defaults to immediately. */
150
+ mintStart?: bigint;
151
+ /** Optional: The royalty amount in basis points for secondary sales, in basis points. Defaults to 1000. */
152
+ royaltyBPS?: number;
153
+ };
154
+
155
+ const makeTokenConfigWithDefaults = ({
87
156
  chainId,
88
- premintConfigVersion,
89
157
  tokenCreationConfig,
90
- payoutRecipient,
158
+ supportedPremintVersions,
91
159
  }: {
92
160
  chainId: number;
93
- premintConfigVersion: T;
94
- tokenCreationConfig: Partial<TokenConfigForVersion<T>> & { tokenURI: string };
95
- payoutRecipient: Address;
96
- }): TokenConfigForVersion<T> => {
97
- if (premintConfigVersion === PremintConfigVersion.V3) {
98
- throw new Error("PremintV3 not supported in SDK");
99
- }
100
-
101
- const fixedPriceMinter =
102
- (
103
- tokenCreationConfig as
104
- | Partial<TokenCreationConfigV1>
105
- | Partial<TokenCreationConfigV2>
106
- ).fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
161
+ tokenCreationConfig: TokenConfigInput;
162
+ supportedPremintVersions: PremintConfigVersion[];
163
+ }): TokenConfigWithVersion<
164
+ PremintConfigVersion.V1 | PremintConfigVersion.V2
165
+ > => {
166
+ const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
167
+
168
+ if (!supportedPremintVersions.includes(PremintConfigVersion.V2)) {
169
+ // we need to return a token config v1
170
+ if (tokenCreationConfig.createReferral) {
171
+ throw new Error("Contract does not support create referral");
172
+ }
107
173
 
108
- if (premintConfigVersion === PremintConfigVersion.V1) {
109
174
  return {
110
- fixedPriceMinter,
111
- ...defaultTokenConfigV1MintArguments(),
112
- royaltyRecipient: payoutRecipient,
113
- ...(tokenCreationConfig as Partial<TokenCreationConfigV1>),
114
- } as TokenCreationConfigV1;
115
- } else if (premintConfigVersion === PremintConfigVersion.V2) {
116
- return {
117
- fixedPriceMinter,
118
- ...defaultTokenConfigV2MintArguments(),
119
- payoutRecipient: payoutRecipient,
120
- createReferral: zeroAddress,
121
- ...tokenCreationConfig,
175
+ premintConfigVersion: PremintConfigVersion.V1,
176
+ tokenConfig: tokenConfigV1WithDefault(
177
+ tokenCreationConfig,
178
+ fixedPriceMinter,
179
+ ),
122
180
  };
123
- } else {
124
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
125
181
  }
182
+
183
+ return {
184
+ premintConfigVersion: PremintConfigVersion.V2,
185
+ tokenConfig: tokenConfigV2WithDefault(
186
+ tokenCreationConfig,
187
+ fixedPriceMinter,
188
+ ),
189
+ };
126
190
  };
127
191
 
128
192
  /**
@@ -150,30 +214,30 @@ export function getPremintedLogFromReceipt(
150
214
  /**
151
215
  * Preminter API to access ZORA Premint functionality.
152
216
  */
153
- class PremintClient {
154
- readonly apiClient: PremintAPIClient;
217
+ export class PremintClient {
218
+ readonly apiClient: IPremintAPI;
155
219
  readonly publicClient: PublicClient;
156
- readonly chain: Chain;
220
+ readonly chainId: number;
157
221
 
158
- constructor(
159
- chain: Chain,
160
- publicClient: PublicClient,
161
- httpClient: IHttpClient,
162
- ) {
163
- this.chain = chain;
164
- this.apiClient = new PremintAPIClient(chain.id, httpClient);
222
+ constructor({
223
+ chainId,
224
+ publicClient,
225
+ premintApi,
226
+ }: {
227
+ chainId: number;
228
+ publicClient: PublicClient;
229
+ premintApi: IPremintAPI;
230
+ }) {
231
+ this.chainId = chainId;
232
+ this.apiClient = premintApi;
165
233
  this.publicClient = publicClient;
166
234
  }
167
235
 
168
- getDataFromPremintReceipt(receipt: TransactionReceipt) {
169
- const premintedLog = getPremintedLogFromReceipt(receipt);
170
- return {
171
- premintedLog,
172
- urls: this.makeUrls({
173
- address: premintedLog?.contractAddress,
174
- tokenId: premintedLog?.tokenId,
175
- }),
176
- };
236
+ getDataFromPremintReceipt(
237
+ receipt: TransactionReceipt,
238
+ blockExplorerUrl?: string,
239
+ ) {
240
+ return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
177
241
  }
178
242
 
179
243
  /**
@@ -187,7 +251,7 @@ class PremintClient {
187
251
  ...args,
188
252
  apiClient: this.apiClient,
189
253
  publicClient: this.publicClient,
190
- chainId: this.chain.id,
254
+ chainId: this.chainId,
191
255
  });
192
256
  }
193
257
 
@@ -204,7 +268,7 @@ class PremintClient {
204
268
  ...params,
205
269
  apiClient: this.apiClient,
206
270
  publicClient: this.publicClient,
207
- chainId: this.chain.id,
271
+ chainId: this.chainId,
208
272
  });
209
273
  }
210
274
 
@@ -214,14 +278,14 @@ class PremintClient {
214
278
  * @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
215
279
  * @returns A PremintReturn. {@link PremintReturn}
216
280
  */
217
- async createPremint<T extends PremintConfigVersion = PremintConfigVersion.V2>(
218
- parameters: CreatePremintParameters<T>,
281
+ async createPremint(
282
+ parameters: CreatePremintParameters,
219
283
  ): Promise<PremintReturn<any>> {
220
284
  return createPremint({
221
285
  ...parameters,
222
286
  publicClient: this.publicClient,
223
287
  apiClient: this.apiClient,
224
- chainId: this.chain.id,
288
+ chainId: this.chainId,
225
289
  });
226
290
  }
227
291
 
@@ -232,13 +296,7 @@ class PremintClient {
232
296
  * @param uid UID for the desired premint
233
297
  * @returns PremintSignatureGetResponse of premint data from the API
234
298
  */
235
- async getPremintSignature({
236
- address,
237
- uid,
238
- }: {
239
- address: Address;
240
- uid: number;
241
- }) {
299
+ async getPremint({ address, uid }: { address: Address; uid: number }) {
242
300
  return await this.apiClient.getSignature({
243
301
  collectionAddress: address,
244
302
  uid,
@@ -252,57 +310,8 @@ class PremintClient {
252
310
  */
253
311
  async getCollectionAddress(collection: ContractCreationConfig) {
254
312
  return await getPremintCollectionAddress({
255
- collection,
256
- publicClient: this.publicClient,
257
- });
258
- }
259
-
260
- /**
261
- * Check user signature for v1
262
- *
263
- * @param data Signature data from the API
264
- * @returns isValid = signature is valid or not, recoveredSigner = signer from contract
265
- */
266
- async isValidSignature<T extends PremintConfigVersion>({
267
- signature,
268
- collection,
269
- premintConfig,
270
- premintConfigVersion,
271
- }: {
272
- signature: Hex;
273
- collection: ContractCreationConfig;
274
- premintConfig: PremintConfigForVersion<T>;
275
- premintConfigVersion?: T;
276
- }): Promise<{
277
- isValid: boolean;
278
- recoveredSigner: Address | undefined;
279
- }> {
280
- const { isAuthorized, recoveredAddress } = await isValidSignature({
281
- chainId: this.chain.id,
282
- signature: signature as Hex,
283
- collection: collection,
313
+ contract: collection,
284
314
  publicClient: this.publicClient,
285
- premintConfig,
286
- premintConfigVersion: premintConfigVersion || PremintConfigVersion.V1,
287
- });
288
-
289
- return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
290
- }
291
-
292
- protected makeUrls({
293
- uid,
294
- address,
295
- tokenId,
296
- }: {
297
- uid?: number;
298
- tokenId?: bigint;
299
- address?: Address;
300
- }): URLSReturnType {
301
- return makeUrls({
302
- uid,
303
- address,
304
- tokenId,
305
- chain: this.chain,
306
315
  });
307
316
  }
308
317
 
@@ -330,28 +339,50 @@ class PremintClient {
330
339
  * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
331
340
  * @returns receipt, log, zoraURL
332
341
  */
333
- async makeMintParameters(parameters: MakeMintParametersArguments) {
334
- return await makeMintParameters({
335
- ...parameters,
336
- apiClient: this.apiClient,
342
+ async makeMintParameters({
343
+ minterAccount,
344
+ tokenContract,
345
+ uid,
346
+ mintArguments,
347
+ firstMinter,
348
+ }: MakeMintParametersArguments) {
349
+ return await collectPremint({
350
+ uid,
351
+ tokenContract,
352
+ minterAccount,
353
+ quantityToMint: mintArguments?.quantityToMint || 1n,
354
+ mintComment: mintArguments?.mintComment,
355
+ mintReferral: mintArguments?.mintReferral,
356
+ mintRecipient: mintArguments?.mintRecipient,
357
+ firstMinter,
358
+ premintGetter: this.apiClient,
337
359
  publicClient: this.publicClient,
338
360
  });
339
361
  }
340
362
  }
341
363
 
342
- export function createPremintClient(clientConfig: ClientConfig) {
343
- const { chain, httpClient, publicClient } = setupClient(clientConfig);
344
- return new PremintClient(chain, publicClient, httpClient);
364
+ export function getDataFromPremintReceipt(
365
+ receipt: TransactionReceipt,
366
+ chainId: number,
367
+ blockExplorerUrl?: string,
368
+ ) {
369
+ const premintedLog = getPremintedLogFromReceipt(receipt);
370
+ return {
371
+ tokenId: premintedLog?.tokenId,
372
+ collectionAddres: premintedLog?.contractAddress,
373
+ premintedLog,
374
+ urls: makeUrls({
375
+ address: premintedLog?.contractAddress,
376
+ tokenId: premintedLog?.tokenId,
377
+ chainId,
378
+ blockExplorerUrl,
379
+ }),
380
+ };
345
381
  }
346
382
 
347
- type ContractCreationConfigWithoutAdditionalAdmins = Omit<
348
- ContractCreationConfig,
349
- "additionalAdmins"
350
- >;
351
-
352
383
  type PremintContext = {
353
384
  publicClient: PublicClient;
354
- apiClient: PremintAPIClient;
385
+ apiClient: IPremintAPI;
355
386
  chainId: number;
356
387
  };
357
388
 
@@ -360,11 +391,7 @@ type PremintContext = {
360
391
  export type SignAndSubmitParams = {
361
392
  /** The WalletClient used to sign the premint */
362
393
  walletClient: WalletClient;
363
- /** The account that is to sign the premint */
364
- account: Account | Address;
365
- /** If the signature should be checked before submitting it to the api */
366
- checkSignature?: boolean;
367
- };
394
+ } & CheckSignatureParams;
368
395
 
369
396
  export type SignAndSubmitReturn = {
370
397
  /** The signature of the Premint */
@@ -373,14 +400,23 @@ export type SignAndSubmitReturn = {
373
400
  signerAccount: Account | Address;
374
401
  };
375
402
 
403
+ export type CheckSignatureParams =
404
+ | {
405
+ /** If the premint signature should be validated before submitting to the API */
406
+ checkSignature: true;
407
+ /** Account that signed the premint */
408
+ account: Account | Address;
409
+ }
410
+ | {
411
+ /** If the premint signature should be validated before submitting to the API */
412
+ checkSignature?: false;
413
+ account?: Account | Address;
414
+ };
415
+
376
416
  export type SubmitParams = {
377
417
  /** The signature of the Premint */
378
418
  signature: Hex;
379
- /** If the premint signature should be validated before submitting to the API */
380
- checkSignature?: boolean;
381
- /** The account that signed the premint */
382
- signerAccount: Account | Address;
383
- };
419
+ } & CheckSignatureParams;
384
420
 
385
421
  type PremintReturn<T extends PremintConfigVersion> = {
386
422
  /** The typedDataDefinition of the Premint which is to be signed the creator. */
@@ -396,15 +432,14 @@ type PremintReturn<T extends PremintConfigVersion> = {
396
432
  function makePremintReturn<T extends PremintConfigVersion>({
397
433
  premintConfig,
398
434
  premintConfigVersion,
399
- collectionAddress,
400
- collection,
401
435
  publicClient,
402
436
  apiClient,
403
437
  chainId,
404
- }: PremintConfigWithVersion<T> & {
405
- collectionAddress: Address;
406
- collection: ContractCreationConfigWithoutAdditionalAdmins;
407
- } & PremintContext): PremintReturn<T> {
438
+ ...collectionAndAddress
439
+ }: PremintConfigWithVersion<T> &
440
+ ContractCreationConfigAndAddress &
441
+ PremintContext): PremintReturn<T> {
442
+ const { collection, collectionAddress } = collectionAndAddress;
408
443
  const typedDataDefinition = premintTypedDataDefinition({
409
444
  verifyingContract: collectionAddress,
410
445
  premintConfig,
@@ -414,7 +449,7 @@ function makePremintReturn<T extends PremintConfigVersion>({
414
449
 
415
450
  const signAndSubmit = async ({
416
451
  walletClient,
417
- account,
452
+ account: account,
418
453
  checkSignature,
419
454
  }: SignAndSubmitParams): Promise<SignAndSubmitReturn> => {
420
455
  const { signature, signerAccount } = await signPremint({
@@ -426,7 +461,7 @@ function makePremintReturn<T extends PremintConfigVersion>({
426
461
  await submit({
427
462
  signature,
428
463
  checkSignature,
429
- signerAccount,
464
+ account: signerAccount,
430
465
  });
431
466
 
432
467
  return {
@@ -438,28 +473,24 @@ function makePremintReturn<T extends PremintConfigVersion>({
438
473
  const submit = async ({
439
474
  signature,
440
475
  checkSignature,
441
- signerAccount,
442
- }: {
443
- signature: Hex;
444
- checkSignature?: boolean;
445
- signerAccount: Account | Address;
446
- }) => {
476
+ account,
477
+ }: SubmitParams) => {
447
478
  if (checkSignature) {
448
- await validateSignature({
449
- collection: {
450
- ...collection,
451
- additionalAdmins: [],
452
- },
479
+ const isAuthorized = await isAuthorizedToCreatePremint({
480
+ collectionAddress,
481
+ additionalAdmins: collection?.additionalAdmins,
482
+ contractAdmin: collection?.contractAdmin,
453
483
  publicClient,
454
- signerAccount,
484
+ signer: account,
455
485
  });
486
+
487
+ if (!isAuthorized) {
488
+ throw new Error("Not authorized to create premint");
489
+ }
456
490
  }
457
491
 
458
492
  await apiClient.postSignature({
459
- collection: {
460
- ...collection,
461
- additionalAdmins: [],
462
- },
493
+ ...toContractCreationConfigOrAddress(collectionAndAddress),
463
494
  signature: signature,
464
495
  premintConfig,
465
496
  premintConfigVersion,
@@ -506,66 +537,30 @@ async function signPremint({
506
537
  };
507
538
  }
508
539
 
509
- const validateSignature = async ({
510
- collection,
511
- publicClient,
512
- signerAccount,
513
- }: {
514
- collection: ContractCreationConfig;
515
- publicClient: PublicClient;
516
- signerAccount: Address | Account;
517
- }) => {
518
- const isAuthorized = await isAuthorizedToCreatePremint({
519
- collection,
520
- publicClient,
521
- signer:
522
- typeof signerAccount === "string" ? signerAccount : signerAccount.address,
523
- collectionAddress: await getPremintCollectionAddress({
524
- collection,
525
- publicClient,
526
- }),
527
- });
528
- if (!isAuthorized) {
529
- throw new Error("Not authorized to create premint");
530
- }
531
- };
532
-
533
540
  /** CREATE */
534
541
 
535
- type CreatePremintParameters<T extends PremintConfigVersion> = {
536
- /** The account to receive the creator reward if it's a free mint, and the paid mint fee if it's a paid mint */
537
- payoutRecipient: Address;
538
- /** Collection information for the mint */
539
- collection: ContractCreationConfigWithoutAdditionalAdmins;
542
+ type CreatePremintParameters = {
540
543
  /** tokenCreationConfig Token creation settings, optional settings are overridden with sensible defaults */
541
- tokenCreationConfig: Partial<TokenConfigForVersion<T>> & {
542
- tokenURI: string;
543
- };
544
- /** Premint config version to use, defaults to V2 */
545
- premintConfigVersion?: T;
544
+ token: TokenConfigInput;
546
545
  /** uid the UID to use – optional and retrieved as a fresh UID from ZORA by default. */
547
546
  uid?: number;
548
- };
547
+ } & ContractCreationConfigOrAddress;
549
548
 
550
- async function createPremint<T extends PremintConfigVersion>({
551
- payoutRecipient: creatorAccount,
552
- collection,
553
- tokenCreationConfig,
554
- premintConfigVersion,
549
+ async function createPremint({
550
+ token: tokenCreationConfig,
555
551
  uid,
556
552
  publicClient,
557
553
  apiClient,
558
554
  chainId,
559
- }: CreatePremintParameters<T> & PremintContext) {
555
+ ...collectionOrAddress
556
+ }: CreatePremintParameters & PremintContext) {
560
557
  const {
561
558
  premintConfig,
562
- premintConfigVersion: actualVersion,
563
- collectionAddress,
564
- } = await prepareCreatePremintConfig<T>({
565
- payoutRecipient: creatorAccount,
566
- collection,
567
- tokenCreationConfig,
568
559
  premintConfigVersion,
560
+ collectionAddress: collectionAddressToUse,
561
+ } = await prepareCreatePremintConfig({
562
+ ...collectionOrAddress,
563
+ tokenCreationConfig,
569
564
  uid,
570
565
  publicClient,
571
566
  apiClient,
@@ -574,42 +569,34 @@ async function createPremint<T extends PremintConfigVersion>({
574
569
 
575
570
  return makePremintReturn({
576
571
  premintConfig,
577
- premintConfigVersion: actualVersion,
578
- collectionAddress,
579
- collection,
572
+ premintConfigVersion,
573
+ collectionAddress: collectionAddressToUse,
574
+ collection: collectionOrAddress.contract,
580
575
  publicClient,
581
576
  apiClient,
582
577
  chainId,
583
578
  });
584
579
  }
585
580
 
586
- async function prepareCreatePremintConfig<T extends PremintConfigVersion>({
587
- payoutRecipient,
588
- collection,
581
+ type PreparePremintReturn = {
582
+ collectionAddress: Address;
583
+ } & PremintConfigAndVersion;
584
+
585
+ async function prepareCreatePremintConfig({
589
586
  tokenCreationConfig,
590
- premintConfigVersion,
591
587
  uid,
592
588
  publicClient,
593
589
  apiClient,
594
590
  chainId,
591
+ ...collectionOrAddress
595
592
  }: {
596
- payoutRecipient: Address | Account;
597
- collection: Omit<ContractCreationConfig, "additionalAdmins"> & {
598
- additionalAdmins?: Address[];
599
- };
600
- tokenCreationConfig: Partial<TokenConfigForVersion<T>> & {
601
- tokenURI: string;
602
- };
603
- premintConfigVersion?: T;
593
+ tokenCreationConfig: TokenConfigInput;
604
594
  uid?: number;
605
- } & PremintContext) {
606
- const collectionWithAdditionalAdmins: ContractCreationConfig = {
607
- ...collection,
608
- additionalAdmins: collection.additionalAdmins || [],
609
- };
595
+ } & PremintContext &
596
+ ContractCreationConfigOrAddress): Promise<PreparePremintReturn> {
610
597
  const newContractAddress = await getPremintCollectionAddress({
611
598
  publicClient,
612
- collection: collectionWithAdditionalAdmins,
599
+ ...collectionOrAddress,
613
600
  });
614
601
 
615
602
  let uidToUse = uid;
@@ -618,37 +605,29 @@ async function prepareCreatePremintConfig<T extends PremintConfigVersion>({
618
605
  uidToUse = await apiClient.getNextUID(newContractAddress);
619
606
  }
620
607
 
621
- const actualVersion = premintConfigVersion || PremintConfigVersion.V1;
608
+ const supportedVersions = await supportedPremintVersions({
609
+ tokenContract: newContractAddress,
610
+ publicClient,
611
+ });
622
612
 
623
- if (
624
- !(await supportsPremintVersion({
625
- version: actualVersion,
626
- publicClient,
627
- tokenContract: newContractAddress,
628
- }))
629
- ) {
630
- throw new Error(
631
- `Premint version ${actualVersion} not supported by contract`,
632
- );
633
- }
613
+ const tokenConfigAndVersion = makeTokenConfigWithDefaults({
614
+ tokenCreationConfig,
615
+ chainId,
616
+ supportedPremintVersions: supportedVersions,
617
+ });
634
618
 
635
619
  const premintConfig = makeNewPremint({
636
- tokenConfig: makeTokenConfigWithDefaults({
637
- // @ts-ignore
638
- premintConfigVersion: actualVersion,
639
- tokenCreationConfig,
640
- payoutRecipient:
641
- typeof payoutRecipient === "string"
642
- ? payoutRecipient
643
- : payoutRecipient.address,
644
- chainId,
645
- }),
620
+ ...tokenConfigAndVersion,
646
621
  uid: uidToUse,
647
622
  });
648
623
 
649
- return {
624
+ const premintConfigAndVersion = {
650
625
  premintConfig,
651
- premintConfigVersion: actualVersion,
626
+ premintConfigVersion: tokenConfigAndVersion.premintConfigVersion,
627
+ } as PremintConfigAndVersion;
628
+
629
+ return {
630
+ ...premintConfigAndVersion,
652
631
  collectionAddress: newContractAddress,
653
632
  };
654
633
  }
@@ -672,7 +651,7 @@ async function updatePremint({
672
651
  publicClient,
673
652
  chainId,
674
653
  }: UpdatePremintParams & {
675
- apiClient: PremintAPIClient;
654
+ apiClient: IPremintAPI;
676
655
  publicClient: PublicClient;
677
656
  chainId: number;
678
657
  }) {
@@ -719,7 +698,7 @@ async function deletePremint({
719
698
  apiClient,
720
699
  chainId,
721
700
  }: DeletePremintParams & {
722
- apiClient: PremintAPIClient;
701
+ apiClient: IPremintAPI;
723
702
  publicClient: PublicClient;
724
703
  chainId: number;
725
704
  }) {
@@ -727,6 +706,7 @@ async function deletePremint({
727
706
  premintConfig,
728
707
  premintConfigVersion,
729
708
  collection: collectionCreationConfig,
709
+ collectionAddress,
730
710
  } = await apiClient.getSignature({
731
711
  collectionAddress: collection,
732
712
  uid: uid,
@@ -741,7 +721,7 @@ async function deletePremint({
741
721
  return makePremintReturn({
742
722
  premintConfig: deletedPremint,
743
723
  premintConfigVersion,
744
- collectionAddress: collection,
724
+ collectionAddress,
745
725
  collection: collectionCreationConfig,
746
726
  publicClient,
747
727
  apiClient,
@@ -767,45 +747,52 @@ export type MakeMintParametersArguments = {
767
747
  /** Address to receive the minted tokens */
768
748
  mintRecipient?: Address;
769
749
  };
750
+ /** Account to receive first minter reward, if this mint brings the premint onchain */
751
+ firstMinter?: Address;
770
752
  };
771
753
 
772
754
  /** ======== MINTING ======== */
773
755
 
774
- async function makeMintParameters({
756
+ export async function collectPremint({
775
757
  uid,
776
758
  tokenContract,
777
759
  minterAccount,
778
- mintArguments,
779
- apiClient,
760
+ quantityToMint,
761
+ mintComment = "",
762
+ mintReferral,
763
+ mintRecipient,
764
+ firstMinter,
765
+ premintGetter,
780
766
  publicClient,
781
- }: MakeMintParametersArguments & {
782
- apiClient: PremintAPIClient;
767
+ }: Omit<MakePremintMintParametersArguments, "mintType"> & {
768
+ premintGetter: IPremintGetter;
783
769
  publicClient: PublicClient;
784
770
  }): Promise<
785
771
  SimulateContractParameters<
786
772
  typeof zoraCreator1155PremintExecutorImplABI,
787
- "premintV1" | "premintV2",
773
+ "premint",
788
774
  any,
789
775
  any,
790
776
  any,
791
777
  Account | Address
792
778
  >
793
779
  > {
794
- if (mintArguments && mintArguments?.quantityToMint < 1) {
780
+ if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
795
781
  throw new Error("Quantity to mint cannot be below 1");
796
782
  }
797
783
 
798
- if (!minterAccount) {
799
- throw new Error("Wallet not passed in");
800
- }
801
-
802
- const { premintConfig, premintConfigVersion, collection, signature } =
803
- await apiClient.getSignature({
804
- collectionAddress: tokenContract,
805
- uid,
806
- });
784
+ const {
785
+ premintConfig,
786
+ premintConfigVersion,
787
+ collection,
788
+ collectionAddress,
789
+ signature,
790
+ } = await premintGetter.getSignature({
791
+ collectionAddress: tokenContract,
792
+ uid,
793
+ });
807
794
 
808
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
795
+ const numberToMint = BigInt(quantityToMint || 1);
809
796
 
810
797
  if (premintConfigVersion === PremintConfigVersion.V3) {
811
798
  throw new Error("PremintV3 not supported in premint SDK");
@@ -818,65 +805,64 @@ async function makeMintParameters({
818
805
  publicClient,
819
806
  tokenPrice: premintConfig.tokenConfig.pricePerToken,
820
807
  })
821
- ).totalCost;
808
+ ).totalCostEth;
822
809
 
823
810
  const mintArgumentsContract: PremintMintArguments = {
824
- mintComment: mintArguments?.mintComment || "",
825
- mintRecipient:
826
- mintArguments?.mintRecipient ||
827
- (typeof minterAccount === "string"
828
- ? minterAccount
829
- : minterAccount.address),
811
+ mintComment: mintComment,
812
+ mintRecipient: mintRecipientOrAccount({
813
+ mintRecipient,
814
+ minterAccount,
815
+ }),
830
816
  mintRewardsRecipients: makeMintRewardsRecipient({
831
- mintReferral: mintArguments?.mintReferral,
817
+ mintReferral,
832
818
  }),
833
819
  };
834
820
 
835
- if (premintConfigVersion === PremintConfigVersion.V1) {
836
- return makeSimulateContractParamaters({
837
- account: minterAccount,
838
- abi: zoraCreator1155PremintExecutorImplABI,
839
- functionName: "premintV1",
840
- value,
841
- address: getPremintExecutorAddress(),
842
- args: [
843
- collection,
821
+ const collectionOrEmpty: ContractCreationConfig = collection
822
+ ? defaultAdditionalAdmins(collection)
823
+ : emptyContractCreationConfig();
824
+ const collectionAddressToSubmit = collection
825
+ ? zeroAddress
826
+ : collectionAddress;
827
+
828
+ const firstMinterToSubmit: Address =
829
+ firstMinter ||
830
+ (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
831
+
832
+ return makeContractParameters({
833
+ account: minterAccount,
834
+ abi: zoraCreator1155PremintExecutorImplABI,
835
+ functionName: "premint",
836
+ value,
837
+ address: getPremintExecutorAddress(),
838
+ args: [
839
+ collectionOrEmpty,
840
+ collectionAddressToSubmit,
841
+ encodePremintConfig({
844
842
  premintConfig,
845
- signature,
846
- numberToMint,
847
- mintArgumentsContract,
848
- ],
849
- });
850
- } else if (premintConfigVersion === PremintConfigVersion.V2) {
851
- return makeSimulateContractParamaters({
852
- account: minterAccount,
853
- abi: zoraCreator1155PremintExecutorImplABI,
854
- functionName: "premintV2",
855
- value,
856
- address: getPremintExecutorAddress(),
857
- args: [
858
- collection,
859
- premintConfig,
860
- signature,
861
- numberToMint,
862
- mintArgumentsContract,
863
- ],
864
- });
865
- }
866
-
867
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
843
+ premintConfigVersion,
844
+ }),
845
+ signature,
846
+ numberToMint,
847
+ mintArgumentsContract,
848
+ firstMinterToSubmit,
849
+ zeroAddress,
850
+ ],
851
+ });
868
852
  }
869
853
 
870
854
  export function makeUrls({
871
855
  uid,
872
856
  address,
873
857
  tokenId,
874
- chain,
858
+ chainId,
859
+ blockExplorerUrl,
875
860
  }: {
876
861
  uid?: number;
877
862
  tokenId?: bigint;
878
863
  address?: Address;
879
- chain: Chain;
864
+ chainId: number;
865
+ blockExplorerUrl?: string;
880
866
  }): URLSReturnType {
881
867
  if ((!uid || !tokenId) && !address) {
882
868
  return { explorer: null, zoraCollect: null, zoraManage: null };
@@ -884,11 +870,11 @@ export function makeUrls({
884
870
 
885
871
  const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
886
872
 
887
- const network = getApiNetworkConfigForChain(chain.id);
873
+ const network = getApiNetworkConfigForChain(chainId);
888
874
 
889
875
  return {
890
876
  explorer: tokenId
891
- ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}`
877
+ ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}`
892
878
  : null,
893
879
  zoraCollect: `https://${
894
880
  network.isTestnet ? "testnet." : ""