@zoralabs/protocol-sdk 0.3.5 → 0.4.1

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.
package/dist/index.cjs CHANGED
@@ -21,36 +21,41 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  DEFAULT_SALE_SETTINGS: () => DEFAULT_SALE_SETTINGS,
24
- DefaultMintArguments: () => DefaultMintArguments,
25
24
  Errors: () => Errors,
26
25
  MintAPIClient: () => MintAPIClient,
27
26
  PremintAPIClient: () => PremintAPIClient,
28
27
  PremintConfigVersion: () => PremintConfigVersion,
29
28
  PreminterDomain: () => PreminterDomain,
30
29
  ZORA_API_BASE: () => ZORA_API_BASE,
31
- convertCollection: () => convertCollection,
32
- convertPremintV1: () => convertPremintV1,
30
+ applyUpdateToPremint: () => applyUpdateToPremint,
33
31
  create1155CreatorClient: () => create1155CreatorClient,
34
32
  create1155TokenSetupArgs: () => create1155TokenSetupArgs,
35
33
  createMintClient: () => createMintClient,
36
34
  createPremintClient: () => createPremintClient,
37
- encodePremintForAPI: () => encodePremintForAPI,
38
- encodePremintV1ForAPI: () => encodePremintV1ForAPI,
39
- encodePremintV2ForAPI: () => encodePremintV2ForAPI,
35
+ defaultTokenConfigV1MintArguments: () => defaultTokenConfigV1MintArguments,
36
+ defaultTokenConfigV2MintArguments: () => defaultTokenConfigV2MintArguments,
40
37
  getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
41
38
  getMintCosts: () => getMintCosts,
42
39
  getPremintCollectionAddress: () => getPremintCollectionAddress,
43
40
  getPremintExecutorAddress: () => getPremintExecutorAddress,
41
+ getPremintMintCosts: () => getPremintMintCosts,
42
+ getPremintMintFee: () => getPremintMintFee,
44
43
  getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
45
44
  getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
46
45
  isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
47
46
  isValidSignature: () => isValidSignature,
47
+ makeMintRewardsRecipient: () => makeMintRewardsRecipient,
48
+ makeNewPremint: () => makeNewPremint,
49
+ markPremintDeleted: () => markPremintDeleted,
48
50
  migratePremintConfigToV2: () => migratePremintConfigToV2,
49
51
  premintTypedDataDefinition: () => premintTypedDataDefinition,
50
52
  recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
51
53
  recoverPremintSigner: () => recoverPremintSigner,
54
+ supportedPremintVersions: () => supportedPremintVersions,
52
55
  supportsPremintVersion: () => supportsPremintVersion,
53
- tryRecoverPremintSigner: () => tryRecoverPremintSigner
56
+ tryRecoverPremintSigner: () => tryRecoverPremintSigner,
57
+ v1Types: () => v1Types,
58
+ v2Types: () => v2Types
54
59
  });
55
60
  module.exports = __toCommonJS(src_exports);
56
61
 
@@ -61,6 +66,8 @@ var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
61
66
  // src/premint/preminter.ts
62
67
  var import_protocol_deployments = require("@zoralabs/protocol-deployments");
63
68
  var import_viem = require("viem");
69
+
70
+ // src/premint/contract-types.ts
64
71
  var v1Types = {
65
72
  CreatorAttribution: [
66
73
  { name: "tokenConfig", type: "TokenCreationConfig" },
@@ -110,10 +117,13 @@ var v2Types = {
110
117
  ]
111
118
  };
112
119
  var PreminterDomain = "Preminter";
113
- var PremintConfigVersion = {
114
- V1: "1",
115
- V2: "2"
116
- };
120
+ var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
121
+ PremintConfigVersion2["V1"] = "1";
122
+ PremintConfigVersion2["V2"] = "2";
123
+ return PremintConfigVersion2;
124
+ })(PremintConfigVersion || {});
125
+
126
+ // src/premint/preminter.ts
117
127
  var getPremintExecutorAddress = () => import_protocol_deployments.zoraCreator1155PremintExecutorImplAddress[999];
118
128
  var premintTypedDataDefinition = ({
119
129
  verifyingContract,
@@ -127,14 +137,14 @@ var premintTypedDataDefinition = ({
127
137
  version,
128
138
  verifyingContract
129
139
  };
130
- if (version === PremintConfigVersion.V1)
140
+ if (version === "1" /* V1 */)
131
141
  return {
132
142
  domain,
133
143
  types: v1Types,
134
144
  message: premintConfig,
135
145
  primaryType: "CreatorAttribution"
136
146
  };
137
- if (version === PremintConfigVersion.V2) {
147
+ if (version === "2" /* V2 */) {
138
148
  return {
139
149
  domain,
140
150
  types: v2Types,
@@ -153,7 +163,7 @@ async function isAuthorizedToCreatePremint({
153
163
  signature,
154
164
  signer
155
165
  }) {
156
- if (premintConfigVersion === PremintConfigVersion.V1) {
166
+ if (premintConfigVersion === "1" /* V1 */) {
157
167
  const [isValidSignature2] = await publicClient.readContract({
158
168
  abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
159
169
  address: getPremintExecutorAddress(),
@@ -276,14 +286,28 @@ var recoverCreatorFromCreatorAttribution = async ({
276
286
  signature
277
287
  });
278
288
  };
279
- var supportsPremintVersion = async (version, tokenContract, publicClient) => {
280
- const supportedPremintSignatureVersions = await publicClient.readContract({
281
- abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
282
- address: getPremintExecutorAddress(),
283
- functionName: "supportedPremintSignatureVersions",
284
- args: [tokenContract]
285
- });
286
- return supportedPremintSignatureVersions.includes(version);
289
+ var supportedPremintVersions = async ({
290
+ tokenContract,
291
+ publicClient
292
+ }) => {
293
+ try {
294
+ return await publicClient.readContract({
295
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
296
+ address: getPremintExecutorAddress(),
297
+ functionName: "supportedPremintSignatureVersions",
298
+ args: [tokenContract]
299
+ });
300
+ } catch (e) {
301
+ console.error(e);
302
+ return ["1"];
303
+ }
304
+ };
305
+ var supportsPremintVersion = async ({
306
+ version,
307
+ tokenContract,
308
+ publicClient
309
+ }) => {
310
+ return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
287
311
  };
288
312
  async function getPremintCollectionAddress({
289
313
  collection,
@@ -296,6 +320,77 @@ async function getPremintCollectionAddress({
296
320
  args: [collection]
297
321
  });
298
322
  }
323
+ function markPremintDeleted(premintConfig) {
324
+ return {
325
+ ...premintConfig,
326
+ version: premintConfig.version + 1,
327
+ deleted: true
328
+ };
329
+ }
330
+ function applyUpdateToPremint({
331
+ uid,
332
+ version,
333
+ tokenConfig,
334
+ tokenConfigUpdates
335
+ }) {
336
+ const updatedTokenConfig = {
337
+ ...tokenConfig,
338
+ ...tokenConfigUpdates
339
+ };
340
+ const result = {
341
+ deleted: false,
342
+ uid,
343
+ version: version + 1,
344
+ tokenConfig: updatedTokenConfig
345
+ };
346
+ return result;
347
+ }
348
+ function makeNewPremint({
349
+ tokenConfig,
350
+ uid
351
+ }) {
352
+ return {
353
+ deleted: false,
354
+ uid,
355
+ version: 0,
356
+ tokenConfig
357
+ };
358
+ }
359
+ async function getPremintMintFee({
360
+ tokenContract,
361
+ publicClient
362
+ }) {
363
+ try {
364
+ return await publicClient.readContract({
365
+ address: getPremintExecutorAddress(),
366
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
367
+ functionName: "mintFee",
368
+ args: [tokenContract]
369
+ });
370
+ } catch (e) {
371
+ console.error(e);
372
+ return (0, import_viem.parseEther)("0.000777");
373
+ }
374
+ }
375
+ async function getPremintMintCosts({
376
+ publicClient,
377
+ tokenContract,
378
+ tokenPrice,
379
+ quantityToMint
380
+ }) {
381
+ const mintFee = await getPremintMintFee({ tokenContract, publicClient });
382
+ return {
383
+ mintFee: mintFee * quantityToMint,
384
+ tokenPurchaseCost: tokenPrice * quantityToMint,
385
+ totalCost: (mintFee + tokenPrice) * quantityToMint
386
+ };
387
+ }
388
+ function makeMintRewardsRecipient({
389
+ mintReferral = import_viem.zeroAddress,
390
+ platformReferral = import_viem.zeroAddress
391
+ }) {
392
+ return [mintReferral, platformReferral];
393
+ }
299
394
 
300
395
  // src/apis/http-api-base.ts
301
396
  var BadResponseError = class extends Error {
@@ -557,64 +652,22 @@ var getSignature = async ({
557
652
  uid,
558
653
  chain_name,
559
654
  httpClient: { retries: retries2, get: get2 } = httpClient
560
- }) => retries2(
561
- () => get2(
562
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
563
- )
564
- );
565
- var PremintAPIClient = class {
566
- constructor(chainId, httpClient2) {
567
- this.postSignature = async (data) => postSignature({
568
- ...data,
569
- chain_name: this.networkConfig.zoraBackendChainName,
570
- httpClient: this.httpClient
571
- });
572
- this.getNextUID = async (path) => getNextUID({
573
- ...path,
574
- chain_name: this.networkConfig.zoraBackendChainName,
575
- httpClient: this.httpClient
576
- });
577
- this.getSignature = async ({
578
- collection_address,
579
- uid
580
- }) => getSignature({
581
- collection_address,
582
- uid,
583
- chain_name: this.networkConfig.zoraBackendChainName,
584
- httpClient: this.httpClient
585
- });
586
- this.httpClient = httpClient2 || httpClient;
587
- this.networkConfig = getApiNetworkConfigForChain(chainId);
588
- }
589
- };
590
-
591
- // src/premint/premint-client.ts
592
- var DefaultMintArguments = {
593
- maxSupply: OPEN_EDITION_MINT_SIZE,
594
- maxTokensPerAddress: 0n,
595
- pricePerToken: 0n,
596
- mintDuration: BigInt(60 * 60 * 24 * 7),
597
- // 1 week
598
- mintStart: 0n,
599
- royaltyMintSchedule: 0,
600
- royaltyBPS: 1e3
601
- // 10%,
655
+ }) => {
656
+ const result = await retries2(
657
+ () => get2(
658
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
659
+ )
660
+ );
661
+ return {
662
+ ...result,
663
+ // for now - we stub the backend api to simulate returning v1
664
+ premint_config_version: "1" /* V1 */
665
+ };
602
666
  };
603
- function getPremintedLogFromReceipt(receipt) {
604
- for (const data of receipt.logs) {
605
- try {
606
- const decodedLog = (0, import_viem4.decodeEventLog)({
607
- abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
608
- eventName: "Preminted",
609
- ...data
610
- });
611
- if (decodedLog.eventName === "Preminted") {
612
- return decodedLog.args;
613
- }
614
- } catch (err) {
615
- }
616
- }
617
- }
667
+ var convertCollection = (collection) => ({
668
+ ...collection,
669
+ contractAdmin: collection.contractAdmin
670
+ });
618
671
  var convertPremintV1 = (premint) => ({
619
672
  ...premint,
620
673
  tokenConfig: {
@@ -628,10 +681,6 @@ var convertPremintV1 = (premint) => ({
628
681
  maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
629
682
  }
630
683
  });
631
- var convertCollection = (collection) => ({
632
- ...collection,
633
- contractAdmin: collection.contractAdmin
634
- });
635
684
  var encodePremintV1ForAPI = ({
636
685
  tokenConfig,
637
686
  ...premint
@@ -664,30 +713,144 @@ var encodePremintForAPI = ({
664
713
  premintConfig,
665
714
  premintConfigVersion
666
715
  }) => {
667
- if (premintConfigVersion === PremintConfigVersion.V1) {
716
+ if (premintConfigVersion === "1" /* V1 */) {
668
717
  return encodePremintV1ForAPI(premintConfig);
669
718
  }
670
- if (premintConfigVersion === PremintConfigVersion.V2) {
719
+ if (premintConfigVersion === "2" /* V2 */) {
671
720
  return encodePremintV2ForAPI(premintConfig);
672
721
  }
673
722
  throw new Error(`Invalid premint config version ${premintConfigVersion}`);
674
723
  };
724
+ var PremintAPIClient = class {
725
+ constructor(chainId, httpClient2) {
726
+ this.postSignature = async ({
727
+ collection,
728
+ premintConfigVersion,
729
+ premintConfig,
730
+ signature
731
+ }) => {
732
+ if (premintConfigVersion === "1" /* V1 */) {
733
+ const data = {
734
+ premint: encodePremintForAPI({
735
+ premintConfig,
736
+ premintConfigVersion
737
+ }),
738
+ signature,
739
+ collection
740
+ };
741
+ return postSignature({
742
+ ...data,
743
+ chain_name: this.networkConfig.zoraBackendChainName,
744
+ httpClient: this.httpClient
745
+ });
746
+ } else {
747
+ throw new Error("Unsupported premint config version");
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
+ const premintConfigVersion = response.premint_config_version || "1" /* V1 */;
766
+ let premintConfig;
767
+ if (premintConfigVersion === "1" /* V1 */) {
768
+ premintConfig = convertPremintV1(response.premint);
769
+ } else {
770
+ throw new Error(
771
+ `Unsupported premint config version: ${premintConfigVersion}`
772
+ );
773
+ }
774
+ return {
775
+ signature: response.signature,
776
+ collection: convertCollection(response.collection),
777
+ premintConfig,
778
+ premintConfigVersion
779
+ };
780
+ };
781
+ this.httpClient = httpClient2 || httpClient;
782
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
783
+ }
784
+ };
785
+
786
+ // src/premint/premint-client.ts
787
+ var defaultTokenConfigV1MintArguments = () => ({
788
+ maxSupply: OPEN_EDITION_MINT_SIZE,
789
+ maxTokensPerAddress: 0n,
790
+ pricePerToken: 0n,
791
+ mintDuration: BigInt(60 * 60 * 24 * 7),
792
+ // 1 week
793
+ mintStart: 0n,
794
+ royaltyMintSchedule: 0,
795
+ royaltyBPS: 1e3
796
+ // 10%,
797
+ });
798
+ var defaultTokenConfigV2MintArguments = () => ({
799
+ maxSupply: OPEN_EDITION_MINT_SIZE,
800
+ maxTokensPerAddress: 0n,
801
+ pricePerToken: 0n,
802
+ mintDuration: BigInt(60 * 60 * 24 * 7),
803
+ // 1 week
804
+ mintStart: 0n,
805
+ royaltyBPS: 1e3
806
+ // 10%,
807
+ });
808
+ var makeTokenConfigWithDefaults = ({
809
+ premintConfigVersion,
810
+ tokenCreationConfig,
811
+ creatorAccount
812
+ }) => {
813
+ const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
814
+ if (premintConfigVersion === "1" /* V1 */) {
815
+ return {
816
+ fixedPriceMinter,
817
+ ...defaultTokenConfigV1MintArguments(),
818
+ royaltyRecipient: creatorAccount,
819
+ ...tokenCreationConfig
820
+ };
821
+ } else if (premintConfigVersion === "2" /* V2 */) {
822
+ return {
823
+ fixedPriceMinter,
824
+ ...defaultTokenConfigV2MintArguments(),
825
+ payoutRecipient: creatorAccount,
826
+ createReferral: import_viem4.zeroAddress,
827
+ ...tokenCreationConfig
828
+ };
829
+ } else {
830
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
831
+ }
832
+ };
833
+ function getPremintedLogFromReceipt(receipt) {
834
+ for (const data of receipt.logs) {
835
+ try {
836
+ const decodedLog = (0, import_viem4.decodeEventLog)({
837
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
838
+ eventName: "Preminted",
839
+ ...data
840
+ });
841
+ if (decodedLog.eventName === "Preminted") {
842
+ return decodedLog.args;
843
+ }
844
+ } catch (err) {
845
+ }
846
+ }
847
+ }
675
848
  var PremintClient = class {
676
849
  constructor(chain, publicClient, httpClient2) {
677
850
  this.chain = chain;
678
851
  this.apiClient = new PremintAPIClient(chain.id, httpClient2);
679
852
  this.publicClient = publicClient || (0, import_viem4.createPublicClient)({ chain, transport: (0, import_viem4.http)() });
680
853
  }
681
- /**
682
- * The fixed price minter address is the same across all chains for our current
683
- * deployer strategy.
684
- * Can be overridden as needed by making a parent class.
685
- *
686
- * @returns Fixed price sale strategy
687
- */
688
- getFixedPriceMinterAddress() {
689
- return import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999];
690
- }
691
854
  getDataFromPremintReceipt(receipt) {
692
855
  const premintedLog = getPremintedLogFromReceipt(receipt);
693
856
  return {
@@ -720,36 +883,31 @@ var PremintClient = class {
720
883
  walletClient,
721
884
  uid,
722
885
  collection,
723
- token,
724
- account
886
+ account,
887
+ tokenConfigUpdates
725
888
  }) {
726
- const signatureResponse = await this.apiClient.getSignature({
727
- collection_address: collection.toLowerCase(),
889
+ const {
890
+ premintConfig,
891
+ collection: collectionCreationConfig,
892
+ premintConfigVersion
893
+ } = await this.apiClient.getSignature({
894
+ collectionAddress: collection,
728
895
  uid
729
896
  });
730
- const convertedPremint = convertPremintV1(signatureResponse.premint);
731
- const signerData = {
732
- ...signatureResponse,
733
- premint: {
734
- ...convertedPremint,
735
- tokenConfig: {
736
- ...convertedPremint.tokenConfig,
737
- ...token
738
- }
739
- }
740
- };
897
+ const updatedPremint = applyUpdateToPremint({
898
+ uid: premintConfig.uid,
899
+ version: premintConfig.version,
900
+ tokenConfig: premintConfig.tokenConfig,
901
+ tokenConfigUpdates
902
+ });
741
903
  return await this.signAndSubmitPremint({
742
904
  walletClient,
743
905
  account,
744
- checkSignature: false,
906
+ checkSignature: true,
745
907
  verifyingContract: collection,
746
- uid,
747
- collection: {
748
- ...signerData.collection,
749
- contractAdmin: signerData.collection.contractAdmin
750
- },
751
- premintConfig: signerData.premint,
752
- premintConfigVersion: PremintConfigVersion.V1
908
+ collection: collectionCreationConfig,
909
+ premintConfig: updatedPremint,
910
+ premintConfigVersion
753
911
  });
754
912
  }
755
913
  /**
@@ -772,27 +930,23 @@ var PremintClient = class {
772
930
  account,
773
931
  collection
774
932
  }) {
775
- const signatureResponse = await this.apiClient.getSignature({
776
- collection_address: collection.toLowerCase(),
933
+ const {
934
+ premintConfig,
935
+ premintConfigVersion,
936
+ collection: collectionCreationConfig
937
+ } = await this.apiClient.getSignature({
938
+ collectionAddress: collection,
777
939
  uid
778
940
  });
779
- const signerData = {
780
- ...signatureResponse,
781
- collection: convertCollection(signatureResponse.collection),
782
- premint: {
783
- ...convertPremintV1(signatureResponse.premint),
784
- deleted: true
785
- }
786
- };
941
+ const deletedPremint = markPremintDeleted(premintConfig);
787
942
  return await this.signAndSubmitPremint({
788
943
  walletClient,
789
944
  account,
790
945
  checkSignature: false,
791
946
  verifyingContract: collection,
792
- uid,
793
- collection: signerData.collection,
794
- premintConfig: signerData.premint,
795
- premintConfigVersion: PremintConfigVersion.V1
947
+ collection: collectionCreationConfig,
948
+ premintConfig: deletedPremint,
949
+ premintConfigVersion
796
950
  });
797
951
  }
798
952
  /**
@@ -801,52 +955,14 @@ var PremintClient = class {
801
955
  * @param premintArguments Arguments to premint
802
956
  * @returns
803
957
  */
804
- async signAndSubmitPremint({
805
- walletClient,
806
- verifyingContract,
807
- uid,
808
- account,
809
- checkSignature,
810
- collection,
811
- ...premintConfigAndVersion
812
- }) {
813
- if (!account) {
814
- account = walletClient.account;
815
- }
816
- if (!account) {
817
- throw new Error("No account provided");
818
- }
819
- const signature = await walletClient.signTypedData({
820
- account,
821
- ...premintTypedDataDefinition({
822
- verifyingContract,
823
- ...premintConfigAndVersion,
824
- chainId: this.chain.id
825
- })
958
+ async signAndSubmitPremint(params) {
959
+ const { premint, verifyingContract } = await signAndSubmitPremint({
960
+ ...params,
961
+ chainId: this.chain.id,
962
+ apiClient: this.apiClient,
963
+ publicClient: this.publicClient
826
964
  });
827
- if (checkSignature) {
828
- const convertedCollection = convertCollection(collection);
829
- const isAuthorized = await isAuthorizedToCreatePremint({
830
- collection: convertCollection(collection),
831
- signature,
832
- publicClient: this.publicClient,
833
- signer: typeof account === "string" ? account : account.address,
834
- collectionAddress: await this.getCollectionAddress(convertedCollection),
835
- ...premintConfigAndVersion
836
- });
837
- if (!isAuthorized) {
838
- throw new Error("Not authorized to create premint");
839
- }
840
- }
841
- if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) {
842
- throw new Error("premint config v2 not supported yet");
843
- }
844
- const apiData = {
845
- collection,
846
- premint: encodePremintV1ForAPI(premintConfigAndVersion.premintConfig),
847
- signature
848
- };
849
- const premint = await this.apiClient.postSignature(apiData);
965
+ const uid = params.premintConfig.uid;
850
966
  return {
851
967
  urls: this.makeUrls({ address: verifyingContract, uid }),
852
968
  uid,
@@ -860,57 +976,53 @@ var PremintClient = class {
860
976
  * @param settings Settings for the new premint
861
977
  * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
862
978
  * @param settings.collection Collection information for the mint
863
- * @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
864
- * @param settings.publicClient Public client (optional) – instantiated if not passed in with defaults.
865
- * @param settings.walletClient Required wallet client for signing the premint message.
866
- * @param settings.executionSettings Execution settings for premint options
867
- * @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
868
- * @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
979
+ * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
980
+ * @param setings.premintConfigVersion Premint config version to use, defaults to V2
981
+ * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
869
982
  * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
870
983
  * @returns premint url, uid, newContractAddress, and premint object
871
984
  */
872
985
  async createPremint({
873
- account,
986
+ creatorAccount,
874
987
  collection,
875
- token,
988
+ tokenCreationConfig,
989
+ premintConfigVersion,
876
990
  walletClient,
877
- executionSettings,
991
+ uid,
878
992
  checkSignature = false
879
993
  }) {
880
994
  const newContractAddress = await getPremintCollectionAddress({
881
995
  publicClient: this.publicClient,
882
- collection: convertCollection(collection)
996
+ collection
883
997
  });
884
- const tokenConfig = {
885
- ...DefaultMintArguments,
886
- fixedPriceMinter: this.getFixedPriceMinterAddress(),
887
- royaltyRecipient: account,
888
- ...token
889
- };
890
- let uid = executionSettings?.uid;
891
- if (!uid) {
892
- const uidResponse = await this.apiClient.getNextUID({
893
- collection_address: newContractAddress.toLowerCase()
894
- });
895
- uid = uidResponse.next_uid;
998
+ let uidToUse = uid;
999
+ if (typeof uidToUse !== "number") {
1000
+ uidToUse = await this.apiClient.getNextUID(newContractAddress);
896
1001
  }
897
- if (!uid) {
898
- throw new Error("UID is missing but required");
1002
+ const actualVersion = premintConfigVersion || "1" /* V1 */;
1003
+ if (!await supportsPremintVersion({
1004
+ version: actualVersion,
1005
+ publicClient: this.publicClient,
1006
+ tokenContract: newContractAddress
1007
+ })) {
1008
+ throw new Error(
1009
+ `Premint version ${actualVersion} not supported by contract`
1010
+ );
899
1011
  }
900
- let deleted = executionSettings?.deleted || false;
901
- const premintConfig = {
902
- tokenConfig,
903
- uid,
904
- version: 1,
905
- deleted
906
- };
1012
+ const premintConfig = makeNewPremint({
1013
+ tokenConfig: makeTokenConfigWithDefaults({
1014
+ premintConfigVersion: actualVersion,
1015
+ tokenCreationConfig,
1016
+ creatorAccount
1017
+ }),
1018
+ uid: uidToUse
1019
+ });
907
1020
  return await this.signAndSubmitPremint({
908
- uid,
909
1021
  verifyingContract: newContractAddress,
910
1022
  premintConfig,
911
- premintConfigVersion: PremintConfigVersion.V1,
1023
+ premintConfigVersion: actualVersion,
912
1024
  checkSignature,
913
- account,
1025
+ account: creatorAccount,
914
1026
  walletClient,
915
1027
  collection
916
1028
  });
@@ -922,12 +1034,12 @@ var PremintClient = class {
922
1034
  * @param uid UID for the desired premint
923
1035
  * @returns PremintSignatureGetResponse of premint data from the API
924
1036
  */
925
- async getPremintData({
1037
+ async getPremintSignature({
926
1038
  address,
927
1039
  uid
928
1040
  }) {
929
1041
  return await this.apiClient.getSignature({
930
- collection_address: address,
1042
+ collectionAddress: address,
931
1043
  uid
932
1044
  });
933
1045
  }
@@ -950,16 +1062,17 @@ var PremintClient = class {
950
1062
  */
951
1063
  async isValidSignature({
952
1064
  signature,
953
- premint,
954
- collection
1065
+ collection,
1066
+ premintConfig,
1067
+ premintConfigVersion
955
1068
  }) {
956
1069
  const { isAuthorized, recoveredAddress } = await isValidSignature({
957
1070
  chainId: this.chain.id,
958
1071
  signature,
959
- premintConfig: convertPremintV1(premint),
960
- premintConfigVersion: PremintConfigVersion.V1,
961
- collection: convertCollection(collection),
962
- publicClient: this.publicClient
1072
+ collection,
1073
+ publicClient: this.publicClient,
1074
+ premintConfig,
1075
+ premintConfigVersion: premintConfigVersion || "1" /* V1 */
963
1076
  });
964
1077
  return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
965
1078
  }
@@ -968,16 +1081,24 @@ var PremintClient = class {
968
1081
  address,
969
1082
  tokenId
970
1083
  }) {
971
- if ((!uid || !tokenId) && !address) {
972
- return { explorer: null, zoraCollect: null, zoraManage: null };
973
- }
974
- const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
975
- const network = getApiNetworkConfigForChain(this.chain.id);
976
- return {
977
- explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
978
- zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
979
- zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
980
- };
1084
+ return makeUrls({
1085
+ uid,
1086
+ address,
1087
+ tokenId,
1088
+ chain: this.chain
1089
+ });
1090
+ }
1091
+ async getMintCosts({
1092
+ tokenContract,
1093
+ quantityToMint,
1094
+ tokenCreationConfig
1095
+ }) {
1096
+ return await getPremintMintCosts({
1097
+ publicClient: this.publicClient,
1098
+ quantityToMint,
1099
+ tokenContract,
1100
+ tokenPrice: tokenCreationConfig.pricePerToken
1101
+ });
981
1102
  }
982
1103
  /**
983
1104
  * Execute premint on-chain
@@ -992,34 +1113,70 @@ var PremintClient = class {
992
1113
  * @returns receipt, log, zoraURL
993
1114
  */
994
1115
  async makeMintParameters({
995
- data,
1116
+ uid,
1117
+ tokenContract,
996
1118
  account,
997
1119
  mintArguments
998
1120
  }) {
999
1121
  if (mintArguments && mintArguments?.quantityToMint < 1) {
1000
1122
  throw new Error("Quantity to mint cannot be below 1");
1001
1123
  }
1002
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1003
- const args = [
1004
- convertCollection(data.collection),
1005
- convertPremintV1(data.premint),
1006
- data.signature,
1007
- numberToMint,
1008
- mintArguments?.mintComment || ""
1009
- ];
1010
1124
  if (!account) {
1011
1125
  throw new Error("Wallet not passed in");
1012
1126
  }
1013
- const value = numberToMint * REWARD_PER_TOKEN;
1014
- const request = {
1015
- account,
1016
- abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1017
- functionName: "premint",
1018
- value,
1019
- address: getPremintExecutorAddress(),
1020
- args
1021
- };
1022
- return request;
1127
+ const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
1128
+ address: tokenContract,
1129
+ uid
1130
+ });
1131
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1132
+ const value = (await getPremintMintCosts({
1133
+ tokenContract,
1134
+ quantityToMint: numberToMint,
1135
+ publicClient: this.publicClient,
1136
+ tokenPrice: premintConfig.tokenConfig.pricePerToken
1137
+ })).totalCost;
1138
+ if (premintConfigVersion === "1" /* V1 */) {
1139
+ return {
1140
+ account,
1141
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1142
+ functionName: "premint",
1143
+ value,
1144
+ address: getPremintExecutorAddress(),
1145
+ args: [
1146
+ collection,
1147
+ premintConfig,
1148
+ signature,
1149
+ numberToMint,
1150
+ mintArguments?.mintComment || ""
1151
+ ]
1152
+ };
1153
+ } else if (premintConfigVersion === "2" /* V2 */) {
1154
+ const toPost = premintConfig;
1155
+ const accountAddress = typeof account === "string" ? account : account.address;
1156
+ return {
1157
+ account,
1158
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1159
+ functionName: "premintV2",
1160
+ value,
1161
+ address: getPremintExecutorAddress(),
1162
+ // args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
1163
+ args: [
1164
+ collection,
1165
+ toPost,
1166
+ signature,
1167
+ numberToMint,
1168
+ {
1169
+ mintComment: mintArguments?.mintComment || "",
1170
+ mintRecipient: mintArguments?.mintRecipient || accountAddress,
1171
+ mintRewardsRecipients: makeMintRewardsRecipient({
1172
+ mintReferral: mintArguments?.mintReferral,
1173
+ platformReferral: mintArguments?.platformReferral
1174
+ })
1175
+ }
1176
+ ]
1177
+ };
1178
+ }
1179
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1023
1180
  }
1024
1181
  };
1025
1182
  function createPremintClient({
@@ -1029,6 +1186,74 @@ function createPremintClient({
1029
1186
  }) {
1030
1187
  return new PremintClient(chain, publicClient, httpClient2);
1031
1188
  }
1189
+ function makeUrls({
1190
+ uid,
1191
+ address,
1192
+ tokenId,
1193
+ chain
1194
+ }) {
1195
+ if ((!uid || !tokenId) && !address) {
1196
+ return { explorer: null, zoraCollect: null, zoraManage: null };
1197
+ }
1198
+ const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
1199
+ const network = getApiNetworkConfigForChain(chain.id);
1200
+ return {
1201
+ explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1202
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
1203
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
1204
+ };
1205
+ }
1206
+ async function signAndSubmitPremint({
1207
+ walletClient,
1208
+ verifyingContract,
1209
+ account,
1210
+ checkSignature,
1211
+ collection,
1212
+ chainId,
1213
+ publicClient,
1214
+ apiClient,
1215
+ ...premintConfigAndVersion
1216
+ }) {
1217
+ if (!account) {
1218
+ account = walletClient.account;
1219
+ }
1220
+ if (!account) {
1221
+ throw new Error("No account provided");
1222
+ }
1223
+ const signature = await walletClient.signTypedData({
1224
+ account,
1225
+ ...premintTypedDataDefinition({
1226
+ verifyingContract,
1227
+ ...premintConfigAndVersion,
1228
+ chainId
1229
+ })
1230
+ });
1231
+ if (checkSignature) {
1232
+ const isAuthorized = await isAuthorizedToCreatePremint({
1233
+ collection,
1234
+ signature,
1235
+ publicClient,
1236
+ signer: typeof account === "string" ? account : account.address,
1237
+ collectionAddress: await getPremintCollectionAddress({
1238
+ collection,
1239
+ publicClient
1240
+ }),
1241
+ ...premintConfigAndVersion
1242
+ });
1243
+ if (!isAuthorized) {
1244
+ throw new Error("Not authorized to create premint");
1245
+ }
1246
+ }
1247
+ const premint = await apiClient.postSignature({
1248
+ collection,
1249
+ signature,
1250
+ ...premintConfigAndVersion
1251
+ });
1252
+ return { premint, verifyingContract };
1253
+ }
1254
+ function getDefaultFixedPriceMinterAddress() {
1255
+ return import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999];
1256
+ }
1032
1257
 
1033
1258
  // src/mint/mint-client.ts
1034
1259
  var import_viem5 = require("viem");
@@ -1414,35 +1639,40 @@ function create1155CreatorClient({
1414
1639
  // Annotate the CommonJS export names for ESM import in node:
1415
1640
  0 && (module.exports = {
1416
1641
  DEFAULT_SALE_SETTINGS,
1417
- DefaultMintArguments,
1418
1642
  Errors,
1419
1643
  MintAPIClient,
1420
1644
  PremintAPIClient,
1421
1645
  PremintConfigVersion,
1422
1646
  PreminterDomain,
1423
1647
  ZORA_API_BASE,
1424
- convertCollection,
1425
- convertPremintV1,
1648
+ applyUpdateToPremint,
1426
1649
  create1155CreatorClient,
1427
1650
  create1155TokenSetupArgs,
1428
1651
  createMintClient,
1429
1652
  createPremintClient,
1430
- encodePremintForAPI,
1431
- encodePremintV1ForAPI,
1432
- encodePremintV2ForAPI,
1653
+ defaultTokenConfigV1MintArguments,
1654
+ defaultTokenConfigV2MintArguments,
1433
1655
  getApiNetworkConfigForChain,
1434
1656
  getMintCosts,
1435
1657
  getPremintCollectionAddress,
1436
1658
  getPremintExecutorAddress,
1659
+ getPremintMintCosts,
1660
+ getPremintMintFee,
1437
1661
  getPremintedLogFromReceipt,
1438
1662
  getTokenIdFromCreateReceipt,
1439
1663
  isAuthorizedToCreatePremint,
1440
1664
  isValidSignature,
1665
+ makeMintRewardsRecipient,
1666
+ makeNewPremint,
1667
+ markPremintDeleted,
1441
1668
  migratePremintConfigToV2,
1442
1669
  premintTypedDataDefinition,
1443
1670
  recoverCreatorFromCreatorAttribution,
1444
1671
  recoverPremintSigner,
1672
+ supportedPremintVersions,
1445
1673
  supportsPremintVersion,
1446
- tryRecoverPremintSigner
1674
+ tryRecoverPremintSigner,
1675
+ v1Types,
1676
+ v2Types
1447
1677
  });
1448
1678
  //# sourceMappingURL=index.cjs.map