@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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/premint/premint-client.ts
2
- import { createPublicClient, decodeEventLog, http } from "viem";
2
+ import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
3
3
  import {
4
4
  zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2,
5
5
  zoraCreatorFixedPriceSaleStrategyAddress
@@ -17,8 +17,11 @@ import {
17
17
  hashDomain,
18
18
  keccak256,
19
19
  concat,
20
- recoverAddress
20
+ recoverAddress,
21
+ parseEther
21
22
  } from "viem";
23
+
24
+ // src/premint/contract-types.ts
22
25
  var v1Types = {
23
26
  CreatorAttribution: [
24
27
  { name: "tokenConfig", type: "TokenCreationConfig" },
@@ -68,10 +71,13 @@ var v2Types = {
68
71
  ]
69
72
  };
70
73
  var PreminterDomain = "Preminter";
71
- var PremintConfigVersion = {
72
- V1: "1",
73
- V2: "2"
74
- };
74
+ var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
75
+ PremintConfigVersion2["V1"] = "1";
76
+ PremintConfigVersion2["V2"] = "2";
77
+ return PremintConfigVersion2;
78
+ })(PremintConfigVersion || {});
79
+
80
+ // src/premint/preminter.ts
75
81
  var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
76
82
  var premintTypedDataDefinition = ({
77
83
  verifyingContract,
@@ -85,14 +91,14 @@ var premintTypedDataDefinition = ({
85
91
  version,
86
92
  verifyingContract
87
93
  };
88
- if (version === PremintConfigVersion.V1)
94
+ if (version === "1" /* V1 */)
89
95
  return {
90
96
  domain,
91
97
  types: v1Types,
92
98
  message: premintConfig,
93
99
  primaryType: "CreatorAttribution"
94
100
  };
95
- if (version === PremintConfigVersion.V2) {
101
+ if (version === "2" /* V2 */) {
96
102
  return {
97
103
  domain,
98
104
  types: v2Types,
@@ -111,7 +117,7 @@ async function isAuthorizedToCreatePremint({
111
117
  signature,
112
118
  signer
113
119
  }) {
114
- if (premintConfigVersion === PremintConfigVersion.V1) {
120
+ if (premintConfigVersion === "1" /* V1 */) {
115
121
  const [isValidSignature2] = await publicClient.readContract({
116
122
  abi: zoraCreator1155PremintExecutorImplABI,
117
123
  address: getPremintExecutorAddress(),
@@ -234,14 +240,28 @@ var recoverCreatorFromCreatorAttribution = async ({
234
240
  signature
235
241
  });
236
242
  };
237
- var supportsPremintVersion = async (version, tokenContract, publicClient) => {
238
- const supportedPremintSignatureVersions = await publicClient.readContract({
239
- abi: preminterAbi,
240
- address: getPremintExecutorAddress(),
241
- functionName: "supportedPremintSignatureVersions",
242
- args: [tokenContract]
243
- });
244
- return supportedPremintSignatureVersions.includes(version);
243
+ var supportedPremintVersions = async ({
244
+ tokenContract,
245
+ publicClient
246
+ }) => {
247
+ try {
248
+ return await publicClient.readContract({
249
+ abi: preminterAbi,
250
+ address: getPremintExecutorAddress(),
251
+ functionName: "supportedPremintSignatureVersions",
252
+ args: [tokenContract]
253
+ });
254
+ } catch (e) {
255
+ console.error(e);
256
+ return ["1"];
257
+ }
258
+ };
259
+ var supportsPremintVersion = async ({
260
+ version,
261
+ tokenContract,
262
+ publicClient
263
+ }) => {
264
+ return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
245
265
  };
246
266
  async function getPremintCollectionAddress({
247
267
  collection,
@@ -254,6 +274,77 @@ async function getPremintCollectionAddress({
254
274
  args: [collection]
255
275
  });
256
276
  }
277
+ function markPremintDeleted(premintConfig) {
278
+ return {
279
+ ...premintConfig,
280
+ version: premintConfig.version + 1,
281
+ deleted: true
282
+ };
283
+ }
284
+ function applyUpdateToPremint({
285
+ uid,
286
+ version,
287
+ tokenConfig,
288
+ tokenConfigUpdates
289
+ }) {
290
+ const updatedTokenConfig = {
291
+ ...tokenConfig,
292
+ ...tokenConfigUpdates
293
+ };
294
+ const result = {
295
+ deleted: false,
296
+ uid,
297
+ version: version + 1,
298
+ tokenConfig: updatedTokenConfig
299
+ };
300
+ return result;
301
+ }
302
+ function makeNewPremint({
303
+ tokenConfig,
304
+ uid
305
+ }) {
306
+ return {
307
+ deleted: false,
308
+ uid,
309
+ version: 0,
310
+ tokenConfig
311
+ };
312
+ }
313
+ async function getPremintMintFee({
314
+ tokenContract,
315
+ publicClient
316
+ }) {
317
+ try {
318
+ return await publicClient.readContract({
319
+ address: getPremintExecutorAddress(),
320
+ abi: zoraCreator1155PremintExecutorImplABI,
321
+ functionName: "mintFee",
322
+ args: [tokenContract]
323
+ });
324
+ } catch (e) {
325
+ console.error(e);
326
+ return parseEther("0.000777");
327
+ }
328
+ }
329
+ async function getPremintMintCosts({
330
+ publicClient,
331
+ tokenContract,
332
+ tokenPrice,
333
+ quantityToMint
334
+ }) {
335
+ const mintFee = await getPremintMintFee({ tokenContract, publicClient });
336
+ return {
337
+ mintFee: mintFee * quantityToMint,
338
+ tokenPurchaseCost: tokenPrice * quantityToMint,
339
+ totalCost: (mintFee + tokenPrice) * quantityToMint
340
+ };
341
+ }
342
+ function makeMintRewardsRecipient({
343
+ mintReferral = zeroAddress,
344
+ platformReferral = zeroAddress
345
+ }) {
346
+ return [mintReferral, platformReferral];
347
+ }
257
348
 
258
349
  // src/apis/http-api-base.ts
259
350
  var BadResponseError = class extends Error {
@@ -354,8 +445,8 @@ import {
354
445
  zora,
355
446
  zoraTestnet
356
447
  } from "viem/chains";
357
- import { parseEther } from "viem";
358
- var REWARD_PER_TOKEN = parseEther("0.000777");
448
+ import { parseEther as parseEther2 } from "viem";
449
+ var REWARD_PER_TOKEN = parseEther2("0.000777");
359
450
  var BackendChainNamesLookup = {
360
451
  ZORA_MAINNET: "ZORA-MAINNET",
361
452
  ZORA_GOERLI: "ZORA-GOERLI",
@@ -525,64 +616,22 @@ var getSignature = async ({
525
616
  uid,
526
617
  chain_name,
527
618
  httpClient: { retries: retries2, get: get2 } = httpClient
528
- }) => retries2(
529
- () => get2(
530
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
531
- )
532
- );
533
- var PremintAPIClient = class {
534
- constructor(chainId, httpClient2) {
535
- this.postSignature = async (data) => postSignature({
536
- ...data,
537
- chain_name: this.networkConfig.zoraBackendChainName,
538
- httpClient: this.httpClient
539
- });
540
- this.getNextUID = async (path) => getNextUID({
541
- ...path,
542
- chain_name: this.networkConfig.zoraBackendChainName,
543
- httpClient: this.httpClient
544
- });
545
- this.getSignature = async ({
546
- collection_address,
547
- uid
548
- }) => getSignature({
549
- collection_address,
550
- uid,
551
- chain_name: this.networkConfig.zoraBackendChainName,
552
- httpClient: this.httpClient
553
- });
554
- this.httpClient = httpClient2 || httpClient;
555
- this.networkConfig = getApiNetworkConfigForChain(chainId);
556
- }
557
- };
558
-
559
- // src/premint/premint-client.ts
560
- var DefaultMintArguments = {
561
- maxSupply: OPEN_EDITION_MINT_SIZE,
562
- maxTokensPerAddress: 0n,
563
- pricePerToken: 0n,
564
- mintDuration: BigInt(60 * 60 * 24 * 7),
565
- // 1 week
566
- mintStart: 0n,
567
- royaltyMintSchedule: 0,
568
- royaltyBPS: 1e3
569
- // 10%,
619
+ }) => {
620
+ const result = await retries2(
621
+ () => get2(
622
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
623
+ )
624
+ );
625
+ return {
626
+ ...result,
627
+ // for now - we stub the backend api to simulate returning v1
628
+ premint_config_version: "1" /* V1 */
629
+ };
570
630
  };
571
- function getPremintedLogFromReceipt(receipt) {
572
- for (const data of receipt.logs) {
573
- try {
574
- const decodedLog = decodeEventLog({
575
- abi: zoraCreator1155PremintExecutorImplABI2,
576
- eventName: "Preminted",
577
- ...data
578
- });
579
- if (decodedLog.eventName === "Preminted") {
580
- return decodedLog.args;
581
- }
582
- } catch (err) {
583
- }
584
- }
585
- }
631
+ var convertCollection = (collection) => ({
632
+ ...collection,
633
+ contractAdmin: collection.contractAdmin
634
+ });
586
635
  var convertPremintV1 = (premint) => ({
587
636
  ...premint,
588
637
  tokenConfig: {
@@ -596,10 +645,6 @@ var convertPremintV1 = (premint) => ({
596
645
  maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
597
646
  }
598
647
  });
599
- var convertCollection = (collection) => ({
600
- ...collection,
601
- contractAdmin: collection.contractAdmin
602
- });
603
648
  var encodePremintV1ForAPI = ({
604
649
  tokenConfig,
605
650
  ...premint
@@ -632,30 +677,144 @@ var encodePremintForAPI = ({
632
677
  premintConfig,
633
678
  premintConfigVersion
634
679
  }) => {
635
- if (premintConfigVersion === PremintConfigVersion.V1) {
680
+ if (premintConfigVersion === "1" /* V1 */) {
636
681
  return encodePremintV1ForAPI(premintConfig);
637
682
  }
638
- if (premintConfigVersion === PremintConfigVersion.V2) {
683
+ if (premintConfigVersion === "2" /* V2 */) {
639
684
  return encodePremintV2ForAPI(premintConfig);
640
685
  }
641
686
  throw new Error(`Invalid premint config version ${premintConfigVersion}`);
642
687
  };
688
+ var PremintAPIClient = class {
689
+ constructor(chainId, httpClient2) {
690
+ this.postSignature = async ({
691
+ collection,
692
+ premintConfigVersion,
693
+ premintConfig,
694
+ signature
695
+ }) => {
696
+ if (premintConfigVersion === "1" /* V1 */) {
697
+ const data = {
698
+ premint: encodePremintForAPI({
699
+ premintConfig,
700
+ premintConfigVersion
701
+ }),
702
+ signature,
703
+ collection
704
+ };
705
+ return postSignature({
706
+ ...data,
707
+ chain_name: this.networkConfig.zoraBackendChainName,
708
+ httpClient: this.httpClient
709
+ });
710
+ } else {
711
+ throw new Error("Unsupported premint config version");
712
+ }
713
+ };
714
+ this.getNextUID = async (collectionAddress) => (await getNextUID({
715
+ collection_address: collectionAddress.toLowerCase(),
716
+ chain_name: this.networkConfig.zoraBackendChainName,
717
+ httpClient: this.httpClient
718
+ })).next_uid;
719
+ this.getSignature = async ({
720
+ collectionAddress,
721
+ uid
722
+ }) => {
723
+ const response = await getSignature({
724
+ collection_address: collectionAddress.toLowerCase(),
725
+ uid,
726
+ chain_name: this.networkConfig.zoraBackendChainName,
727
+ httpClient: this.httpClient
728
+ });
729
+ const premintConfigVersion = response.premint_config_version || "1" /* V1 */;
730
+ let premintConfig;
731
+ if (premintConfigVersion === "1" /* V1 */) {
732
+ premintConfig = convertPremintV1(response.premint);
733
+ } else {
734
+ throw new Error(
735
+ `Unsupported premint config version: ${premintConfigVersion}`
736
+ );
737
+ }
738
+ return {
739
+ signature: response.signature,
740
+ collection: convertCollection(response.collection),
741
+ premintConfig,
742
+ premintConfigVersion
743
+ };
744
+ };
745
+ this.httpClient = httpClient2 || httpClient;
746
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
747
+ }
748
+ };
749
+
750
+ // src/premint/premint-client.ts
751
+ var defaultTokenConfigV1MintArguments = () => ({
752
+ maxSupply: OPEN_EDITION_MINT_SIZE,
753
+ maxTokensPerAddress: 0n,
754
+ pricePerToken: 0n,
755
+ mintDuration: BigInt(60 * 60 * 24 * 7),
756
+ // 1 week
757
+ mintStart: 0n,
758
+ royaltyMintSchedule: 0,
759
+ royaltyBPS: 1e3
760
+ // 10%,
761
+ });
762
+ var defaultTokenConfigV2MintArguments = () => ({
763
+ maxSupply: OPEN_EDITION_MINT_SIZE,
764
+ maxTokensPerAddress: 0n,
765
+ pricePerToken: 0n,
766
+ mintDuration: BigInt(60 * 60 * 24 * 7),
767
+ // 1 week
768
+ mintStart: 0n,
769
+ royaltyBPS: 1e3
770
+ // 10%,
771
+ });
772
+ var makeTokenConfigWithDefaults = ({
773
+ premintConfigVersion,
774
+ tokenCreationConfig,
775
+ creatorAccount
776
+ }) => {
777
+ const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
778
+ if (premintConfigVersion === "1" /* V1 */) {
779
+ return {
780
+ fixedPriceMinter,
781
+ ...defaultTokenConfigV1MintArguments(),
782
+ royaltyRecipient: creatorAccount,
783
+ ...tokenCreationConfig
784
+ };
785
+ } else if (premintConfigVersion === "2" /* V2 */) {
786
+ return {
787
+ fixedPriceMinter,
788
+ ...defaultTokenConfigV2MintArguments(),
789
+ payoutRecipient: creatorAccount,
790
+ createReferral: zeroAddress2,
791
+ ...tokenCreationConfig
792
+ };
793
+ } else {
794
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
795
+ }
796
+ };
797
+ function getPremintedLogFromReceipt(receipt) {
798
+ for (const data of receipt.logs) {
799
+ try {
800
+ const decodedLog = decodeEventLog({
801
+ abi: zoraCreator1155PremintExecutorImplABI2,
802
+ eventName: "Preminted",
803
+ ...data
804
+ });
805
+ if (decodedLog.eventName === "Preminted") {
806
+ return decodedLog.args;
807
+ }
808
+ } catch (err) {
809
+ }
810
+ }
811
+ }
643
812
  var PremintClient = class {
644
813
  constructor(chain, publicClient, httpClient2) {
645
814
  this.chain = chain;
646
815
  this.apiClient = new PremintAPIClient(chain.id, httpClient2);
647
816
  this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
648
817
  }
649
- /**
650
- * The fixed price minter address is the same across all chains for our current
651
- * deployer strategy.
652
- * Can be overridden as needed by making a parent class.
653
- *
654
- * @returns Fixed price sale strategy
655
- */
656
- getFixedPriceMinterAddress() {
657
- return zoraCreatorFixedPriceSaleStrategyAddress[999];
658
- }
659
818
  getDataFromPremintReceipt(receipt) {
660
819
  const premintedLog = getPremintedLogFromReceipt(receipt);
661
820
  return {
@@ -688,36 +847,31 @@ var PremintClient = class {
688
847
  walletClient,
689
848
  uid,
690
849
  collection,
691
- token,
692
- account
850
+ account,
851
+ tokenConfigUpdates
693
852
  }) {
694
- const signatureResponse = await this.apiClient.getSignature({
695
- collection_address: collection.toLowerCase(),
853
+ const {
854
+ premintConfig,
855
+ collection: collectionCreationConfig,
856
+ premintConfigVersion
857
+ } = await this.apiClient.getSignature({
858
+ collectionAddress: collection,
696
859
  uid
697
860
  });
698
- const convertedPremint = convertPremintV1(signatureResponse.premint);
699
- const signerData = {
700
- ...signatureResponse,
701
- premint: {
702
- ...convertedPremint,
703
- tokenConfig: {
704
- ...convertedPremint.tokenConfig,
705
- ...token
706
- }
707
- }
708
- };
861
+ const updatedPremint = applyUpdateToPremint({
862
+ uid: premintConfig.uid,
863
+ version: premintConfig.version,
864
+ tokenConfig: premintConfig.tokenConfig,
865
+ tokenConfigUpdates
866
+ });
709
867
  return await this.signAndSubmitPremint({
710
868
  walletClient,
711
869
  account,
712
- checkSignature: false,
870
+ checkSignature: true,
713
871
  verifyingContract: collection,
714
- uid,
715
- collection: {
716
- ...signerData.collection,
717
- contractAdmin: signerData.collection.contractAdmin
718
- },
719
- premintConfig: signerData.premint,
720
- premintConfigVersion: PremintConfigVersion.V1
872
+ collection: collectionCreationConfig,
873
+ premintConfig: updatedPremint,
874
+ premintConfigVersion
721
875
  });
722
876
  }
723
877
  /**
@@ -740,27 +894,23 @@ var PremintClient = class {
740
894
  account,
741
895
  collection
742
896
  }) {
743
- const signatureResponse = await this.apiClient.getSignature({
744
- collection_address: collection.toLowerCase(),
897
+ const {
898
+ premintConfig,
899
+ premintConfigVersion,
900
+ collection: collectionCreationConfig
901
+ } = await this.apiClient.getSignature({
902
+ collectionAddress: collection,
745
903
  uid
746
904
  });
747
- const signerData = {
748
- ...signatureResponse,
749
- collection: convertCollection(signatureResponse.collection),
750
- premint: {
751
- ...convertPremintV1(signatureResponse.premint),
752
- deleted: true
753
- }
754
- };
905
+ const deletedPremint = markPremintDeleted(premintConfig);
755
906
  return await this.signAndSubmitPremint({
756
907
  walletClient,
757
908
  account,
758
909
  checkSignature: false,
759
910
  verifyingContract: collection,
760
- uid,
761
- collection: signerData.collection,
762
- premintConfig: signerData.premint,
763
- premintConfigVersion: PremintConfigVersion.V1
911
+ collection: collectionCreationConfig,
912
+ premintConfig: deletedPremint,
913
+ premintConfigVersion
764
914
  });
765
915
  }
766
916
  /**
@@ -769,52 +919,14 @@ var PremintClient = class {
769
919
  * @param premintArguments Arguments to premint
770
920
  * @returns
771
921
  */
772
- async signAndSubmitPremint({
773
- walletClient,
774
- verifyingContract,
775
- uid,
776
- account,
777
- checkSignature,
778
- collection,
779
- ...premintConfigAndVersion
780
- }) {
781
- if (!account) {
782
- account = walletClient.account;
783
- }
784
- if (!account) {
785
- throw new Error("No account provided");
786
- }
787
- const signature = await walletClient.signTypedData({
788
- account,
789
- ...premintTypedDataDefinition({
790
- verifyingContract,
791
- ...premintConfigAndVersion,
792
- chainId: this.chain.id
793
- })
922
+ async signAndSubmitPremint(params) {
923
+ const { premint, verifyingContract } = await signAndSubmitPremint({
924
+ ...params,
925
+ chainId: this.chain.id,
926
+ apiClient: this.apiClient,
927
+ publicClient: this.publicClient
794
928
  });
795
- if (checkSignature) {
796
- const convertedCollection = convertCollection(collection);
797
- const isAuthorized = await isAuthorizedToCreatePremint({
798
- collection: convertCollection(collection),
799
- signature,
800
- publicClient: this.publicClient,
801
- signer: typeof account === "string" ? account : account.address,
802
- collectionAddress: await this.getCollectionAddress(convertedCollection),
803
- ...premintConfigAndVersion
804
- });
805
- if (!isAuthorized) {
806
- throw new Error("Not authorized to create premint");
807
- }
808
- }
809
- if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) {
810
- throw new Error("premint config v2 not supported yet");
811
- }
812
- const apiData = {
813
- collection,
814
- premint: encodePremintV1ForAPI(premintConfigAndVersion.premintConfig),
815
- signature
816
- };
817
- const premint = await this.apiClient.postSignature(apiData);
929
+ const uid = params.premintConfig.uid;
818
930
  return {
819
931
  urls: this.makeUrls({ address: verifyingContract, uid }),
820
932
  uid,
@@ -828,57 +940,53 @@ var PremintClient = class {
828
940
  * @param settings Settings for the new premint
829
941
  * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
830
942
  * @param settings.collection Collection information for the mint
831
- * @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
832
- * @param settings.publicClient Public client (optional) – instantiated if not passed in with defaults.
833
- * @param settings.walletClient Required wallet client for signing the premint message.
834
- * @param settings.executionSettings Execution settings for premint options
835
- * @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
836
- * @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
943
+ * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
944
+ * @param setings.premintConfigVersion Premint config version to use, defaults to V2
945
+ * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
837
946
  * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
838
947
  * @returns premint url, uid, newContractAddress, and premint object
839
948
  */
840
949
  async createPremint({
841
- account,
950
+ creatorAccount,
842
951
  collection,
843
- token,
952
+ tokenCreationConfig,
953
+ premintConfigVersion,
844
954
  walletClient,
845
- executionSettings,
955
+ uid,
846
956
  checkSignature = false
847
957
  }) {
848
958
  const newContractAddress = await getPremintCollectionAddress({
849
959
  publicClient: this.publicClient,
850
- collection: convertCollection(collection)
960
+ collection
851
961
  });
852
- const tokenConfig = {
853
- ...DefaultMintArguments,
854
- fixedPriceMinter: this.getFixedPriceMinterAddress(),
855
- royaltyRecipient: account,
856
- ...token
857
- };
858
- let uid = executionSettings?.uid;
859
- if (!uid) {
860
- const uidResponse = await this.apiClient.getNextUID({
861
- collection_address: newContractAddress.toLowerCase()
862
- });
863
- uid = uidResponse.next_uid;
962
+ let uidToUse = uid;
963
+ if (typeof uidToUse !== "number") {
964
+ uidToUse = await this.apiClient.getNextUID(newContractAddress);
864
965
  }
865
- if (!uid) {
866
- throw new Error("UID is missing but required");
966
+ const actualVersion = premintConfigVersion || "1" /* V1 */;
967
+ if (!await supportsPremintVersion({
968
+ version: actualVersion,
969
+ publicClient: this.publicClient,
970
+ tokenContract: newContractAddress
971
+ })) {
972
+ throw new Error(
973
+ `Premint version ${actualVersion} not supported by contract`
974
+ );
867
975
  }
868
- let deleted = executionSettings?.deleted || false;
869
- const premintConfig = {
870
- tokenConfig,
871
- uid,
872
- version: 1,
873
- deleted
874
- };
976
+ const premintConfig = makeNewPremint({
977
+ tokenConfig: makeTokenConfigWithDefaults({
978
+ premintConfigVersion: actualVersion,
979
+ tokenCreationConfig,
980
+ creatorAccount
981
+ }),
982
+ uid: uidToUse
983
+ });
875
984
  return await this.signAndSubmitPremint({
876
- uid,
877
985
  verifyingContract: newContractAddress,
878
986
  premintConfig,
879
- premintConfigVersion: PremintConfigVersion.V1,
987
+ premintConfigVersion: actualVersion,
880
988
  checkSignature,
881
- account,
989
+ account: creatorAccount,
882
990
  walletClient,
883
991
  collection
884
992
  });
@@ -890,12 +998,12 @@ var PremintClient = class {
890
998
  * @param uid UID for the desired premint
891
999
  * @returns PremintSignatureGetResponse of premint data from the API
892
1000
  */
893
- async getPremintData({
1001
+ async getPremintSignature({
894
1002
  address,
895
1003
  uid
896
1004
  }) {
897
1005
  return await this.apiClient.getSignature({
898
- collection_address: address,
1006
+ collectionAddress: address,
899
1007
  uid
900
1008
  });
901
1009
  }
@@ -918,16 +1026,17 @@ var PremintClient = class {
918
1026
  */
919
1027
  async isValidSignature({
920
1028
  signature,
921
- premint,
922
- collection
1029
+ collection,
1030
+ premintConfig,
1031
+ premintConfigVersion
923
1032
  }) {
924
1033
  const { isAuthorized, recoveredAddress } = await isValidSignature({
925
1034
  chainId: this.chain.id,
926
1035
  signature,
927
- premintConfig: convertPremintV1(premint),
928
- premintConfigVersion: PremintConfigVersion.V1,
929
- collection: convertCollection(collection),
930
- publicClient: this.publicClient
1036
+ collection,
1037
+ publicClient: this.publicClient,
1038
+ premintConfig,
1039
+ premintConfigVersion: premintConfigVersion || "1" /* V1 */
931
1040
  });
932
1041
  return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
933
1042
  }
@@ -936,16 +1045,24 @@ var PremintClient = class {
936
1045
  address,
937
1046
  tokenId
938
1047
  }) {
939
- if ((!uid || !tokenId) && !address) {
940
- return { explorer: null, zoraCollect: null, zoraManage: null };
941
- }
942
- const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
943
- const network = getApiNetworkConfigForChain(this.chain.id);
944
- return {
945
- explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
946
- zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
947
- zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
948
- };
1048
+ return makeUrls({
1049
+ uid,
1050
+ address,
1051
+ tokenId,
1052
+ chain: this.chain
1053
+ });
1054
+ }
1055
+ async getMintCosts({
1056
+ tokenContract,
1057
+ quantityToMint,
1058
+ tokenCreationConfig
1059
+ }) {
1060
+ return await getPremintMintCosts({
1061
+ publicClient: this.publicClient,
1062
+ quantityToMint,
1063
+ tokenContract,
1064
+ tokenPrice: tokenCreationConfig.pricePerToken
1065
+ });
949
1066
  }
950
1067
  /**
951
1068
  * Execute premint on-chain
@@ -960,34 +1077,70 @@ var PremintClient = class {
960
1077
  * @returns receipt, log, zoraURL
961
1078
  */
962
1079
  async makeMintParameters({
963
- data,
1080
+ uid,
1081
+ tokenContract,
964
1082
  account,
965
1083
  mintArguments
966
1084
  }) {
967
1085
  if (mintArguments && mintArguments?.quantityToMint < 1) {
968
1086
  throw new Error("Quantity to mint cannot be below 1");
969
1087
  }
970
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
971
- const args = [
972
- convertCollection(data.collection),
973
- convertPremintV1(data.premint),
974
- data.signature,
975
- numberToMint,
976
- mintArguments?.mintComment || ""
977
- ];
978
1088
  if (!account) {
979
1089
  throw new Error("Wallet not passed in");
980
1090
  }
981
- const value = numberToMint * REWARD_PER_TOKEN;
982
- const request = {
983
- account,
984
- abi: zoraCreator1155PremintExecutorImplABI2,
985
- functionName: "premint",
986
- value,
987
- address: getPremintExecutorAddress(),
988
- args
989
- };
990
- return request;
1091
+ const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
1092
+ address: tokenContract,
1093
+ uid
1094
+ });
1095
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1096
+ const value = (await getPremintMintCosts({
1097
+ tokenContract,
1098
+ quantityToMint: numberToMint,
1099
+ publicClient: this.publicClient,
1100
+ tokenPrice: premintConfig.tokenConfig.pricePerToken
1101
+ })).totalCost;
1102
+ if (premintConfigVersion === "1" /* V1 */) {
1103
+ return {
1104
+ account,
1105
+ abi: zoraCreator1155PremintExecutorImplABI2,
1106
+ functionName: "premint",
1107
+ value,
1108
+ address: getPremintExecutorAddress(),
1109
+ args: [
1110
+ collection,
1111
+ premintConfig,
1112
+ signature,
1113
+ numberToMint,
1114
+ mintArguments?.mintComment || ""
1115
+ ]
1116
+ };
1117
+ } else if (premintConfigVersion === "2" /* V2 */) {
1118
+ const toPost = premintConfig;
1119
+ const accountAddress = typeof account === "string" ? account : account.address;
1120
+ return {
1121
+ account,
1122
+ abi: zoraCreator1155PremintExecutorImplABI2,
1123
+ functionName: "premintV2",
1124
+ value,
1125
+ address: getPremintExecutorAddress(),
1126
+ // args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
1127
+ args: [
1128
+ collection,
1129
+ toPost,
1130
+ signature,
1131
+ numberToMint,
1132
+ {
1133
+ mintComment: mintArguments?.mintComment || "",
1134
+ mintRecipient: mintArguments?.mintRecipient || accountAddress,
1135
+ mintRewardsRecipients: makeMintRewardsRecipient({
1136
+ mintReferral: mintArguments?.mintReferral,
1137
+ platformReferral: mintArguments?.platformReferral
1138
+ })
1139
+ }
1140
+ ]
1141
+ };
1142
+ }
1143
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
991
1144
  }
992
1145
  };
993
1146
  function createPremintClient({
@@ -997,13 +1150,81 @@ function createPremintClient({
997
1150
  }) {
998
1151
  return new PremintClient(chain, publicClient, httpClient2);
999
1152
  }
1153
+ function makeUrls({
1154
+ uid,
1155
+ address,
1156
+ tokenId,
1157
+ chain
1158
+ }) {
1159
+ if ((!uid || !tokenId) && !address) {
1160
+ return { explorer: null, zoraCollect: null, zoraManage: null };
1161
+ }
1162
+ const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
1163
+ const network = getApiNetworkConfigForChain(chain.id);
1164
+ return {
1165
+ explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1166
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
1167
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
1168
+ };
1169
+ }
1170
+ async function signAndSubmitPremint({
1171
+ walletClient,
1172
+ verifyingContract,
1173
+ account,
1174
+ checkSignature,
1175
+ collection,
1176
+ chainId,
1177
+ publicClient,
1178
+ apiClient,
1179
+ ...premintConfigAndVersion
1180
+ }) {
1181
+ if (!account) {
1182
+ account = walletClient.account;
1183
+ }
1184
+ if (!account) {
1185
+ throw new Error("No account provided");
1186
+ }
1187
+ const signature = await walletClient.signTypedData({
1188
+ account,
1189
+ ...premintTypedDataDefinition({
1190
+ verifyingContract,
1191
+ ...premintConfigAndVersion,
1192
+ chainId
1193
+ })
1194
+ });
1195
+ if (checkSignature) {
1196
+ const isAuthorized = await isAuthorizedToCreatePremint({
1197
+ collection,
1198
+ signature,
1199
+ publicClient,
1200
+ signer: typeof account === "string" ? account : account.address,
1201
+ collectionAddress: await getPremintCollectionAddress({
1202
+ collection,
1203
+ publicClient
1204
+ }),
1205
+ ...premintConfigAndVersion
1206
+ });
1207
+ if (!isAuthorized) {
1208
+ throw new Error("Not authorized to create premint");
1209
+ }
1210
+ }
1211
+ const premint = await apiClient.postSignature({
1212
+ collection,
1213
+ signature,
1214
+ ...premintConfigAndVersion
1215
+ });
1216
+ return { premint, verifyingContract };
1217
+ }
1218
+ function getDefaultFixedPriceMinterAddress() {
1219
+ return zoraCreatorFixedPriceSaleStrategyAddress[999];
1220
+ }
1000
1221
 
1001
1222
  // src/mint/mint-client.ts
1002
1223
  import {
1003
1224
  createPublicClient as createPublicClient2,
1004
1225
  encodeAbiParameters,
1005
1226
  parseAbiParameters,
1006
- zeroAddress as zeroAddress2,
1227
+ zeroAddress as zeroAddress3,
1007
1228
  http as http2
1008
1229
  } from "viem";
1009
1230
  import {
@@ -1092,7 +1313,7 @@ async function makePrepareMint721TokenParams({
1092
1313
  mintArguments.mintToAddress,
1093
1314
  BigInt(mintArguments.quantityToMint),
1094
1315
  mintArguments.mintComment || "",
1095
- mintArguments.mintReferral || zeroAddress2
1316
+ mintArguments.mintReferral || zeroAddress3
1096
1317
  ]
1097
1318
  };
1098
1319
  return result;
@@ -1136,7 +1357,7 @@ async function makePrepareMint1155TokenParams({
1136
1357
  mintArguments.mintToAddress,
1137
1358
  mintArguments.mintComment || ""
1138
1359
  ]),
1139
- mintArguments.mintReferral || zeroAddress2
1360
+ mintArguments.mintReferral || zeroAddress3
1140
1361
  ]
1141
1362
  };
1142
1363
  return result;
@@ -1149,11 +1370,11 @@ import {
1149
1370
  zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
1150
1371
  zoraCreatorFixedPriceSaleStrategyABI
1151
1372
  } from "@zoralabs/protocol-deployments";
1152
- import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress3 } from "viem";
1373
+ import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
1153
1374
  var SALE_END_FOREVER = 18446744073709551615n;
1154
1375
  var ROYALTY_BPS_DEFAULT = 1e3;
1155
1376
  var DEFAULT_SALE_SETTINGS = {
1156
- fundsRecipient: zeroAddress3,
1377
+ fundsRecipient: zeroAddress4,
1157
1378
  // Free Mint
1158
1379
  pricePerToken: 0n,
1159
1380
  // Sale start time – defaults to beginning of unix time
@@ -1395,35 +1616,40 @@ function create1155CreatorClient({
1395
1616
  }
1396
1617
  export {
1397
1618
  DEFAULT_SALE_SETTINGS,
1398
- DefaultMintArguments,
1399
1619
  Errors,
1400
1620
  MintAPIClient,
1401
1621
  PremintAPIClient,
1402
1622
  PremintConfigVersion,
1403
1623
  PreminterDomain,
1404
1624
  ZORA_API_BASE,
1405
- convertCollection,
1406
- convertPremintV1,
1625
+ applyUpdateToPremint,
1407
1626
  create1155CreatorClient,
1408
1627
  create1155TokenSetupArgs,
1409
1628
  createMintClient,
1410
1629
  createPremintClient,
1411
- encodePremintForAPI,
1412
- encodePremintV1ForAPI,
1413
- encodePremintV2ForAPI,
1630
+ defaultTokenConfigV1MintArguments,
1631
+ defaultTokenConfigV2MintArguments,
1414
1632
  getApiNetworkConfigForChain,
1415
1633
  getMintCosts,
1416
1634
  getPremintCollectionAddress,
1417
1635
  getPremintExecutorAddress,
1636
+ getPremintMintCosts,
1637
+ getPremintMintFee,
1418
1638
  getPremintedLogFromReceipt,
1419
1639
  getTokenIdFromCreateReceipt,
1420
1640
  isAuthorizedToCreatePremint,
1421
1641
  isValidSignature,
1642
+ makeMintRewardsRecipient,
1643
+ makeNewPremint,
1644
+ markPremintDeleted,
1422
1645
  migratePremintConfigToV2,
1423
1646
  premintTypedDataDefinition,
1424
1647
  recoverCreatorFromCreatorAttribution,
1425
1648
  recoverPremintSigner,
1649
+ supportedPremintVersions,
1426
1650
  supportsPremintVersion,
1427
- tryRecoverPremintSigner
1651
+ tryRecoverPremintSigner,
1652
+ v1Types,
1653
+ v2Types
1428
1654
  };
1429
1655
  //# sourceMappingURL=index.js.map