@zoralabs/protocol-sdk 0.3.5 → 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.
package/dist/index.cjs CHANGED
@@ -21,22 +21,19 @@ 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,
@@ -45,12 +42,17 @@ __export(src_exports, {
45
42
  getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
46
43
  isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
47
44
  isValidSignature: () => isValidSignature,
45
+ makeNewPremint: () => makeNewPremint,
46
+ markPremintDeleted: () => markPremintDeleted,
48
47
  migratePremintConfigToV2: () => migratePremintConfigToV2,
49
48
  premintTypedDataDefinition: () => premintTypedDataDefinition,
50
49
  recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
51
50
  recoverPremintSigner: () => recoverPremintSigner,
51
+ supportedPremintVersions: () => supportedPremintVersions,
52
52
  supportsPremintVersion: () => supportsPremintVersion,
53
- tryRecoverPremintSigner: () => tryRecoverPremintSigner
53
+ tryRecoverPremintSigner: () => tryRecoverPremintSigner,
54
+ v1Types: () => v1Types,
55
+ v2Types: () => v2Types
54
56
  });
55
57
  module.exports = __toCommonJS(src_exports);
56
58
 
@@ -61,6 +63,8 @@ var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
61
63
  // src/premint/preminter.ts
62
64
  var import_protocol_deployments = require("@zoralabs/protocol-deployments");
63
65
  var import_viem = require("viem");
66
+
67
+ // src/premint/contract-types.ts
64
68
  var v1Types = {
65
69
  CreatorAttribution: [
66
70
  { name: "tokenConfig", type: "TokenCreationConfig" },
@@ -110,10 +114,13 @@ var v2Types = {
110
114
  ]
111
115
  };
112
116
  var PreminterDomain = "Preminter";
113
- var PremintConfigVersion = {
114
- V1: "1",
115
- V2: "2"
116
- };
117
+ var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
118
+ PremintConfigVersion2["V1"] = "1";
119
+ PremintConfigVersion2["V2"] = "2";
120
+ return PremintConfigVersion2;
121
+ })(PremintConfigVersion || {});
122
+
123
+ // src/premint/preminter.ts
117
124
  var getPremintExecutorAddress = () => import_protocol_deployments.zoraCreator1155PremintExecutorImplAddress[999];
118
125
  var premintTypedDataDefinition = ({
119
126
  verifyingContract,
@@ -127,14 +134,14 @@ var premintTypedDataDefinition = ({
127
134
  version,
128
135
  verifyingContract
129
136
  };
130
- if (version === PremintConfigVersion.V1)
137
+ if (version === "1" /* V1 */)
131
138
  return {
132
139
  domain,
133
140
  types: v1Types,
134
141
  message: premintConfig,
135
142
  primaryType: "CreatorAttribution"
136
143
  };
137
- if (version === PremintConfigVersion.V2) {
144
+ if (version === "2" /* V2 */) {
138
145
  return {
139
146
  domain,
140
147
  types: v2Types,
@@ -153,7 +160,7 @@ async function isAuthorizedToCreatePremint({
153
160
  signature,
154
161
  signer
155
162
  }) {
156
- if (premintConfigVersion === PremintConfigVersion.V1) {
163
+ if (premintConfigVersion === "1" /* V1 */) {
157
164
  const [isValidSignature2] = await publicClient.readContract({
158
165
  abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
159
166
  address: getPremintExecutorAddress(),
@@ -276,14 +283,28 @@ var recoverCreatorFromCreatorAttribution = async ({
276
283
  signature
277
284
  });
278
285
  };
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);
286
+ var supportedPremintVersions = async ({
287
+ tokenContract,
288
+ publicClient
289
+ }) => {
290
+ try {
291
+ return await publicClient.readContract({
292
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
293
+ address: getPremintExecutorAddress(),
294
+ functionName: "supportedPremintSignatureVersions",
295
+ args: [tokenContract]
296
+ });
297
+ } catch (e) {
298
+ console.error(e);
299
+ return ["1"];
300
+ }
301
+ };
302
+ var supportsPremintVersion = async ({
303
+ version,
304
+ tokenContract,
305
+ publicClient
306
+ }) => {
307
+ return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
287
308
  };
288
309
  async function getPremintCollectionAddress({
289
310
  collection,
@@ -296,6 +317,42 @@ async function getPremintCollectionAddress({
296
317
  args: [collection]
297
318
  });
298
319
  }
320
+ function markPremintDeleted(premintConfig) {
321
+ return {
322
+ ...premintConfig,
323
+ version: premintConfig.version + 1,
324
+ deleted: true
325
+ };
326
+ }
327
+ function applyUpdateToPremint({
328
+ uid,
329
+ version,
330
+ tokenConfig,
331
+ tokenConfigUpdates
332
+ }) {
333
+ const updatedTokenConfig = {
334
+ ...tokenConfig,
335
+ ...tokenConfigUpdates
336
+ };
337
+ const result = {
338
+ deleted: false,
339
+ uid,
340
+ version: version + 1,
341
+ tokenConfig: updatedTokenConfig
342
+ };
343
+ return result;
344
+ }
345
+ function makeNewPremint({
346
+ tokenConfig,
347
+ uid
348
+ }) {
349
+ return {
350
+ deleted: false,
351
+ uid,
352
+ version: 0,
353
+ tokenConfig
354
+ };
355
+ }
299
356
 
300
357
  // src/apis/http-api-base.ts
301
358
  var BadResponseError = class extends Error {
@@ -557,64 +614,22 @@ var getSignature = async ({
557
614
  uid,
558
615
  chain_name,
559
616
  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%,
617
+ }) => {
618
+ const result = await retries2(
619
+ () => get2(
620
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
621
+ )
622
+ );
623
+ return {
624
+ ...result,
625
+ // for now - we stub the backend api to simulate returning v1
626
+ premint_config_version: "1" /* V1 */
627
+ };
602
628
  };
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
- }
629
+ var convertCollection = (collection) => ({
630
+ ...collection,
631
+ contractAdmin: collection.contractAdmin
632
+ });
618
633
  var convertPremintV1 = (premint) => ({
619
634
  ...premint,
620
635
  tokenConfig: {
@@ -628,10 +643,6 @@ var convertPremintV1 = (premint) => ({
628
643
  maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
629
644
  }
630
645
  });
631
- var convertCollection = (collection) => ({
632
- ...collection,
633
- contractAdmin: collection.contractAdmin
634
- });
635
646
  var encodePremintV1ForAPI = ({
636
647
  tokenConfig,
637
648
  ...premint
@@ -664,30 +675,144 @@ var encodePremintForAPI = ({
664
675
  premintConfig,
665
676
  premintConfigVersion
666
677
  }) => {
667
- if (premintConfigVersion === PremintConfigVersion.V1) {
678
+ if (premintConfigVersion === "1" /* V1 */) {
668
679
  return encodePremintV1ForAPI(premintConfig);
669
680
  }
670
- if (premintConfigVersion === PremintConfigVersion.V2) {
681
+ if (premintConfigVersion === "2" /* V2 */) {
671
682
  return encodePremintV2ForAPI(premintConfig);
672
683
  }
673
684
  throw new Error(`Invalid premint config version ${premintConfigVersion}`);
674
685
  };
686
+ var PremintAPIClient = class {
687
+ constructor(chainId, httpClient2) {
688
+ this.postSignature = async ({
689
+ collection,
690
+ premintConfigVersion,
691
+ premintConfig,
692
+ signature
693
+ }) => {
694
+ if (premintConfigVersion === "1" /* V1 */) {
695
+ const data = {
696
+ premint: encodePremintForAPI({
697
+ premintConfig,
698
+ premintConfigVersion
699
+ }),
700
+ signature,
701
+ collection
702
+ };
703
+ return postSignature({
704
+ ...data,
705
+ chain_name: this.networkConfig.zoraBackendChainName,
706
+ httpClient: this.httpClient
707
+ });
708
+ } else {
709
+ throw new Error("Unsupported premint config version");
710
+ }
711
+ };
712
+ this.getNextUID = async (collectionAddress) => (await getNextUID({
713
+ collection_address: collectionAddress.toLowerCase(),
714
+ chain_name: this.networkConfig.zoraBackendChainName,
715
+ httpClient: this.httpClient
716
+ })).next_uid;
717
+ this.getSignature = async ({
718
+ collectionAddress,
719
+ uid
720
+ }) => {
721
+ const response = await getSignature({
722
+ collection_address: collectionAddress.toLowerCase(),
723
+ uid,
724
+ chain_name: this.networkConfig.zoraBackendChainName,
725
+ httpClient: this.httpClient
726
+ });
727
+ const premintConfigVersion = response.premint_config_version || "1" /* V1 */;
728
+ let premintConfig;
729
+ if (premintConfigVersion === "1" /* V1 */) {
730
+ premintConfig = convertPremintV1(response.premint);
731
+ } else {
732
+ throw new Error(
733
+ `Unsupported premint config version: ${premintConfigVersion}`
734
+ );
735
+ }
736
+ return {
737
+ signature: response.signature,
738
+ collection: convertCollection(response.collection),
739
+ premintConfig,
740
+ premintConfigVersion
741
+ };
742
+ };
743
+ this.httpClient = httpClient2 || httpClient;
744
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
745
+ }
746
+ };
747
+
748
+ // src/premint/premint-client.ts
749
+ var defaultTokenConfigV1MintArguments = () => ({
750
+ maxSupply: OPEN_EDITION_MINT_SIZE,
751
+ maxTokensPerAddress: 0n,
752
+ pricePerToken: 0n,
753
+ mintDuration: BigInt(60 * 60 * 24 * 7),
754
+ // 1 week
755
+ mintStart: 0n,
756
+ royaltyMintSchedule: 0,
757
+ royaltyBPS: 1e3
758
+ // 10%,
759
+ });
760
+ var defaultTokenConfigV2MintArguments = () => ({
761
+ maxSupply: OPEN_EDITION_MINT_SIZE,
762
+ maxTokensPerAddress: 0n,
763
+ pricePerToken: 0n,
764
+ mintDuration: BigInt(60 * 60 * 24 * 7),
765
+ // 1 week
766
+ mintStart: 0n,
767
+ royaltyBPS: 1e3
768
+ // 10%,
769
+ });
770
+ var makeTokenConfigWithDefaults = ({
771
+ premintConfigVersion,
772
+ tokenCreationConfig,
773
+ creatorAccount
774
+ }) => {
775
+ const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
776
+ if (premintConfigVersion === "1" /* V1 */) {
777
+ return {
778
+ fixedPriceMinter,
779
+ ...defaultTokenConfigV1MintArguments(),
780
+ royaltyRecipient: creatorAccount,
781
+ ...tokenCreationConfig
782
+ };
783
+ } else if (premintConfigVersion === "2" /* V2 */) {
784
+ return {
785
+ fixedPriceMinter,
786
+ ...defaultTokenConfigV2MintArguments(),
787
+ payoutRecipient: creatorAccount,
788
+ createReferral: import_viem4.zeroAddress,
789
+ ...tokenCreationConfig
790
+ };
791
+ } else {
792
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
793
+ }
794
+ };
795
+ function getPremintedLogFromReceipt(receipt) {
796
+ for (const data of receipt.logs) {
797
+ try {
798
+ const decodedLog = (0, import_viem4.decodeEventLog)({
799
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
800
+ eventName: "Preminted",
801
+ ...data
802
+ });
803
+ if (decodedLog.eventName === "Preminted") {
804
+ return decodedLog.args;
805
+ }
806
+ } catch (err) {
807
+ }
808
+ }
809
+ }
675
810
  var PremintClient = class {
676
811
  constructor(chain, publicClient, httpClient2) {
677
812
  this.chain = chain;
678
813
  this.apiClient = new PremintAPIClient(chain.id, httpClient2);
679
814
  this.publicClient = publicClient || (0, import_viem4.createPublicClient)({ chain, transport: (0, import_viem4.http)() });
680
815
  }
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
816
  getDataFromPremintReceipt(receipt) {
692
817
  const premintedLog = getPremintedLogFromReceipt(receipt);
693
818
  return {
@@ -720,36 +845,31 @@ var PremintClient = class {
720
845
  walletClient,
721
846
  uid,
722
847
  collection,
723
- token,
724
- account
848
+ account,
849
+ tokenConfigUpdates
725
850
  }) {
726
- const signatureResponse = await this.apiClient.getSignature({
727
- collection_address: collection.toLowerCase(),
851
+ const {
852
+ premintConfig,
853
+ collection: collectionCreationConfig,
854
+ premintConfigVersion
855
+ } = await this.apiClient.getSignature({
856
+ collectionAddress: collection,
728
857
  uid
729
858
  });
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
- };
859
+ const updatedPremint = applyUpdateToPremint({
860
+ uid: premintConfig.uid,
861
+ version: premintConfig.version,
862
+ tokenConfig: premintConfig.tokenConfig,
863
+ tokenConfigUpdates
864
+ });
741
865
  return await this.signAndSubmitPremint({
742
866
  walletClient,
743
867
  account,
744
- checkSignature: false,
868
+ checkSignature: true,
745
869
  verifyingContract: collection,
746
- uid,
747
- collection: {
748
- ...signerData.collection,
749
- contractAdmin: signerData.collection.contractAdmin
750
- },
751
- premintConfig: signerData.premint,
752
- premintConfigVersion: PremintConfigVersion.V1
870
+ collection: collectionCreationConfig,
871
+ premintConfig: updatedPremint,
872
+ premintConfigVersion
753
873
  });
754
874
  }
755
875
  /**
@@ -772,27 +892,23 @@ var PremintClient = class {
772
892
  account,
773
893
  collection
774
894
  }) {
775
- const signatureResponse = await this.apiClient.getSignature({
776
- collection_address: collection.toLowerCase(),
895
+ const {
896
+ premintConfig,
897
+ premintConfigVersion,
898
+ collection: collectionCreationConfig
899
+ } = await this.apiClient.getSignature({
900
+ collectionAddress: collection,
777
901
  uid
778
902
  });
779
- const signerData = {
780
- ...signatureResponse,
781
- collection: convertCollection(signatureResponse.collection),
782
- premint: {
783
- ...convertPremintV1(signatureResponse.premint),
784
- deleted: true
785
- }
786
- };
903
+ const deletedPremint = markPremintDeleted(premintConfig);
787
904
  return await this.signAndSubmitPremint({
788
905
  walletClient,
789
906
  account,
790
907
  checkSignature: false,
791
908
  verifyingContract: collection,
792
- uid,
793
- collection: signerData.collection,
794
- premintConfig: signerData.premint,
795
- premintConfigVersion: PremintConfigVersion.V1
909
+ collection: collectionCreationConfig,
910
+ premintConfig: deletedPremint,
911
+ premintConfigVersion
796
912
  });
797
913
  }
798
914
  /**
@@ -801,52 +917,14 @@ var PremintClient = class {
801
917
  * @param premintArguments Arguments to premint
802
918
  * @returns
803
919
  */
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
- })
920
+ async signAndSubmitPremint(params) {
921
+ const { premint, verifyingContract } = await signAndSubmitPremint({
922
+ ...params,
923
+ chainId: this.chain.id,
924
+ apiClient: this.apiClient,
925
+ publicClient: this.publicClient
826
926
  });
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);
927
+ const uid = params.premintConfig.uid;
850
928
  return {
851
929
  urls: this.makeUrls({ address: verifyingContract, uid }),
852
930
  uid,
@@ -860,57 +938,53 @@ var PremintClient = class {
860
938
  * @param settings Settings for the new premint
861
939
  * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
862
940
  * @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.
941
+ * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
942
+ * @param setings.premintConfigVersion Premint config version to use, defaults to V2
943
+ * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
869
944
  * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
870
945
  * @returns premint url, uid, newContractAddress, and premint object
871
946
  */
872
947
  async createPremint({
873
- account,
948
+ creatorAccount,
874
949
  collection,
875
- token,
950
+ tokenCreationConfig,
951
+ premintConfigVersion,
876
952
  walletClient,
877
- executionSettings,
953
+ uid,
878
954
  checkSignature = false
879
955
  }) {
880
956
  const newContractAddress = await getPremintCollectionAddress({
881
957
  publicClient: this.publicClient,
882
- collection: convertCollection(collection)
958
+ collection
883
959
  });
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;
960
+ let uidToUse = uid;
961
+ if (typeof uidToUse !== "number") {
962
+ uidToUse = await this.apiClient.getNextUID(newContractAddress);
896
963
  }
897
- if (!uid) {
898
- throw new Error("UID is missing but required");
964
+ const actualVersion = premintConfigVersion || "1" /* V1 */;
965
+ if (!await supportsPremintVersion({
966
+ version: actualVersion,
967
+ publicClient: this.publicClient,
968
+ tokenContract: newContractAddress
969
+ })) {
970
+ throw new Error(
971
+ `Premint version ${actualVersion} not supported by contract`
972
+ );
899
973
  }
900
- let deleted = executionSettings?.deleted || false;
901
- const premintConfig = {
902
- tokenConfig,
903
- uid,
904
- version: 1,
905
- deleted
906
- };
974
+ const premintConfig = makeNewPremint({
975
+ tokenConfig: makeTokenConfigWithDefaults({
976
+ premintConfigVersion: actualVersion,
977
+ tokenCreationConfig,
978
+ creatorAccount
979
+ }),
980
+ uid: uidToUse
981
+ });
907
982
  return await this.signAndSubmitPremint({
908
- uid,
909
983
  verifyingContract: newContractAddress,
910
984
  premintConfig,
911
- premintConfigVersion: PremintConfigVersion.V1,
985
+ premintConfigVersion: actualVersion,
912
986
  checkSignature,
913
- account,
987
+ account: creatorAccount,
914
988
  walletClient,
915
989
  collection
916
990
  });
@@ -922,12 +996,12 @@ var PremintClient = class {
922
996
  * @param uid UID for the desired premint
923
997
  * @returns PremintSignatureGetResponse of premint data from the API
924
998
  */
925
- async getPremintData({
999
+ async getPremintSignature({
926
1000
  address,
927
1001
  uid
928
1002
  }) {
929
1003
  return await this.apiClient.getSignature({
930
- collection_address: address,
1004
+ collectionAddress: address,
931
1005
  uid
932
1006
  });
933
1007
  }
@@ -950,16 +1024,17 @@ var PremintClient = class {
950
1024
  */
951
1025
  async isValidSignature({
952
1026
  signature,
953
- premint,
954
- collection
1027
+ collection,
1028
+ premintConfig,
1029
+ premintConfigVersion
955
1030
  }) {
956
1031
  const { isAuthorized, recoveredAddress } = await isValidSignature({
957
1032
  chainId: this.chain.id,
958
1033
  signature,
959
- premintConfig: convertPremintV1(premint),
960
- premintConfigVersion: PremintConfigVersion.V1,
961
- collection: convertCollection(collection),
962
- publicClient: this.publicClient
1034
+ collection,
1035
+ publicClient: this.publicClient,
1036
+ premintConfig,
1037
+ premintConfigVersion: premintConfigVersion || "1" /* V1 */
963
1038
  });
964
1039
  return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
965
1040
  }
@@ -968,16 +1043,12 @@ var PremintClient = class {
968
1043
  address,
969
1044
  tokenId
970
1045
  }) {
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
- };
1046
+ return makeUrls({
1047
+ uid,
1048
+ address,
1049
+ tokenId,
1050
+ chain: this.chain
1051
+ });
981
1052
  }
982
1053
  /**
983
1054
  * Execute premint on-chain
@@ -992,34 +1063,62 @@ var PremintClient = class {
992
1063
  * @returns receipt, log, zoraURL
993
1064
  */
994
1065
  async makeMintParameters({
995
- data,
1066
+ uid,
1067
+ tokenContract,
996
1068
  account,
997
1069
  mintArguments
998
1070
  }) {
999
1071
  if (mintArguments && mintArguments?.quantityToMint < 1) {
1000
1072
  throw new Error("Quantity to mint cannot be below 1");
1001
1073
  }
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
1074
  if (!account) {
1011
1075
  throw new Error("Wallet not passed in");
1012
1076
  }
1077
+ const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
1078
+ address: tokenContract,
1079
+ uid
1080
+ });
1081
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1013
1082
  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;
1083
+ if (premintConfigVersion === "1" /* V1 */) {
1084
+ return {
1085
+ account,
1086
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1087
+ functionName: "premint",
1088
+ value,
1089
+ address: getPremintExecutorAddress(),
1090
+ args: [
1091
+ collection,
1092
+ premintConfig,
1093
+ signature,
1094
+ numberToMint,
1095
+ mintArguments?.mintComment || ""
1096
+ ]
1097
+ };
1098
+ } else if (premintConfigVersion === "2" /* V2 */) {
1099
+ const toPost = premintConfig;
1100
+ const accountAddress = typeof account === "string" ? account : account.address;
1101
+ return {
1102
+ account,
1103
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1104
+ functionName: "premintV2",
1105
+ value,
1106
+ address: getPremintExecutorAddress(),
1107
+ // args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
1108
+ args: [
1109
+ collection,
1110
+ toPost,
1111
+ signature,
1112
+ numberToMint,
1113
+ {
1114
+ mintComment: mintArguments?.mintComment || "",
1115
+ mintRecipient: mintArguments?.mintRecipient || accountAddress,
1116
+ mintReferral: mintArguments?.mintReferral || import_viem4.zeroAddress
1117
+ }
1118
+ ]
1119
+ };
1120
+ }
1121
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1023
1122
  }
1024
1123
  };
1025
1124
  function createPremintClient({
@@ -1029,6 +1128,74 @@ function createPremintClient({
1029
1128
  }) {
1030
1129
  return new PremintClient(chain, publicClient, httpClient2);
1031
1130
  }
1131
+ function makeUrls({
1132
+ uid,
1133
+ address,
1134
+ tokenId,
1135
+ chain
1136
+ }) {
1137
+ if ((!uid || !tokenId) && !address) {
1138
+ return { explorer: null, zoraCollect: null, zoraManage: null };
1139
+ }
1140
+ const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
1141
+ const network = getApiNetworkConfigForChain(chain.id);
1142
+ return {
1143
+ explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1144
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
1145
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
1146
+ };
1147
+ }
1148
+ async function signAndSubmitPremint({
1149
+ walletClient,
1150
+ verifyingContract,
1151
+ account,
1152
+ checkSignature,
1153
+ collection,
1154
+ chainId,
1155
+ publicClient,
1156
+ apiClient,
1157
+ ...premintConfigAndVersion
1158
+ }) {
1159
+ if (!account) {
1160
+ account = walletClient.account;
1161
+ }
1162
+ if (!account) {
1163
+ throw new Error("No account provided");
1164
+ }
1165
+ const signature = await walletClient.signTypedData({
1166
+ account,
1167
+ ...premintTypedDataDefinition({
1168
+ verifyingContract,
1169
+ ...premintConfigAndVersion,
1170
+ chainId
1171
+ })
1172
+ });
1173
+ if (checkSignature) {
1174
+ const isAuthorized = await isAuthorizedToCreatePremint({
1175
+ collection,
1176
+ signature,
1177
+ publicClient,
1178
+ signer: typeof account === "string" ? account : account.address,
1179
+ collectionAddress: await getPremintCollectionAddress({
1180
+ collection,
1181
+ publicClient
1182
+ }),
1183
+ ...premintConfigAndVersion
1184
+ });
1185
+ if (!isAuthorized) {
1186
+ throw new Error("Not authorized to create premint");
1187
+ }
1188
+ }
1189
+ const premint = await apiClient.postSignature({
1190
+ collection,
1191
+ signature,
1192
+ ...premintConfigAndVersion
1193
+ });
1194
+ return { premint, verifyingContract };
1195
+ }
1196
+ function getDefaultFixedPriceMinterAddress() {
1197
+ return import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999];
1198
+ }
1032
1199
 
1033
1200
  // src/mint/mint-client.ts
1034
1201
  var import_viem5 = require("viem");
@@ -1414,22 +1581,19 @@ function create1155CreatorClient({
1414
1581
  // Annotate the CommonJS export names for ESM import in node:
1415
1582
  0 && (module.exports = {
1416
1583
  DEFAULT_SALE_SETTINGS,
1417
- DefaultMintArguments,
1418
1584
  Errors,
1419
1585
  MintAPIClient,
1420
1586
  PremintAPIClient,
1421
1587
  PremintConfigVersion,
1422
1588
  PreminterDomain,
1423
1589
  ZORA_API_BASE,
1424
- convertCollection,
1425
- convertPremintV1,
1590
+ applyUpdateToPremint,
1426
1591
  create1155CreatorClient,
1427
1592
  create1155TokenSetupArgs,
1428
1593
  createMintClient,
1429
1594
  createPremintClient,
1430
- encodePremintForAPI,
1431
- encodePremintV1ForAPI,
1432
- encodePremintV2ForAPI,
1595
+ defaultTokenConfigV1MintArguments,
1596
+ defaultTokenConfigV2MintArguments,
1433
1597
  getApiNetworkConfigForChain,
1434
1598
  getMintCosts,
1435
1599
  getPremintCollectionAddress,
@@ -1438,11 +1602,16 @@ function create1155CreatorClient({
1438
1602
  getTokenIdFromCreateReceipt,
1439
1603
  isAuthorizedToCreatePremint,
1440
1604
  isValidSignature,
1605
+ makeNewPremint,
1606
+ markPremintDeleted,
1441
1607
  migratePremintConfigToV2,
1442
1608
  premintTypedDataDefinition,
1443
1609
  recoverCreatorFromCreatorAttribution,
1444
1610
  recoverPremintSigner,
1611
+ supportedPremintVersions,
1445
1612
  supportsPremintVersion,
1446
- tryRecoverPremintSigner
1613
+ tryRecoverPremintSigner,
1614
+ v1Types,
1615
+ v2Types
1447
1616
  });
1448
1617
  //# sourceMappingURL=index.cjs.map