@zoralabs/protocol-sdk 0.5.15 → 0.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +19 -0
  3. package/dist/anvil.d.ts +4 -4
  4. package/dist/anvil.d.ts.map +1 -1
  5. package/dist/apis/generated/premint-api-types.d.ts +9 -2
  6. package/dist/apis/generated/premint-api-types.d.ts.map +1 -1
  7. package/dist/create/1155-create-helper.d.ts +3 -4
  8. package/dist/create/1155-create-helper.d.ts.map +1 -1
  9. package/dist/index.cjs +495 -371
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +478 -352
  14. package/dist/index.js.map +1 -1
  15. package/dist/mint/mint-client.d.ts +22 -17
  16. package/dist/mint/mint-client.d.ts.map +1 -1
  17. package/dist/mints/mints-contracts.d.ts +688 -3
  18. package/dist/mints/mints-contracts.d.ts.map +1 -1
  19. package/dist/premint/contract-types.d.ts +21 -0
  20. package/dist/premint/contract-types.d.ts.map +1 -1
  21. package/dist/premint/conversions.d.ts +10 -22
  22. package/dist/premint/conversions.d.ts.map +1 -1
  23. package/dist/premint/premint-api-client.d.ts +5 -4
  24. package/dist/premint/premint-api-client.d.ts.map +1 -1
  25. package/dist/premint/premint-client.d.ts +122 -1476
  26. package/dist/premint/premint-client.d.ts.map +1 -1
  27. package/dist/premint/preminter.d.ts +29 -16
  28. package/dist/premint/preminter.d.ts.map +1 -1
  29. package/dist/utils.d.ts +6872 -1
  30. package/dist/utils.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/apis/generated/premint-api-types.ts +9 -2
  33. package/src/create/1155-create-helper.test.ts +10 -3
  34. package/src/create/1155-create-helper.ts +8 -7
  35. package/src/index.ts +6 -0
  36. package/src/mint/mint-client.ts +31 -30
  37. package/src/mints/mints-contracts.test.ts +2 -2
  38. package/src/premint/contract-types.ts +32 -1
  39. package/src/premint/conversions.ts +20 -8
  40. package/src/premint/premint-api-client.ts +7 -7
  41. package/src/premint/premint-client.test.ts +112 -88
  42. package/src/premint/premint-client.ts +614 -409
  43. package/src/premint/preminter.test.ts +154 -2
  44. package/src/premint/preminter.ts +87 -36
  45. package/src/utils.ts +25 -0
  46. package/test-integration/premint-client.test.ts +2 -2
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  // src/premint/premint-client.ts
2
- import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
3
- import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/protocol-deployments";
2
+ import { decodeEventLog, zeroAddress as zeroAddress2 } from "viem";
3
+ import {
4
+ encodePremintConfig,
5
+ zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2
6
+ } from "@zoralabs/protocol-deployments";
4
7
 
5
8
  // src/premint/preminter.ts
6
9
  import {
@@ -21,22 +24,21 @@ import {
21
24
  } from "viem";
22
25
  var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
23
26
  async function isAuthorizedToCreatePremint({
24
- collection,
27
+ contractAdmin = zeroAddress,
28
+ additionalAdmins = [],
25
29
  collectionAddress,
26
30
  publicClient,
27
31
  signer
28
32
  }) {
29
- if (collection.additionalAdmins.length > 0)
30
- throw new Error("additionalAdmins not supported yet.");
31
33
  return await publicClient.readContract({
32
34
  abi: preminterAbi,
33
35
  address: getPremintExecutorAddress(),
34
36
  functionName: "isAuthorizedToCreatePremintWithAdditionalAdmins",
35
37
  args: [
36
- signer,
37
- collection.contractAdmin,
38
+ typeof signer === "string" ? signer : signer.address,
39
+ contractAdmin,
38
40
  collectionAddress,
39
- collection.additionalAdmins
41
+ additionalAdmins
40
42
  ]
41
43
  });
42
44
  }
@@ -61,17 +63,14 @@ async function isValidSignature({
61
63
  signature,
62
64
  publicClient,
63
65
  collection,
66
+ collectionAddress,
64
67
  chainId,
65
68
  ...premintConfigAndVersion
66
69
  }) {
67
- const tokenContract = await getPremintCollectionAddress({
68
- collection,
69
- publicClient
70
- });
71
70
  const recoveredAddress = await tryRecoverPremintSigner({
72
71
  ...premintConfigAndVersion,
73
72
  signature,
74
- verifyingContract: tokenContract,
73
+ verifyingContract: collectionAddress,
75
74
  chainId
76
75
  });
77
76
  if (!recoverAddress) {
@@ -81,8 +80,9 @@ async function isValidSignature({
81
80
  }
82
81
  const isAuthorized = await isAuthorizedToCreatePremint({
83
82
  signer: recoveredAddress,
84
- collection,
85
- collectionAddress: tokenContract,
83
+ additionalAdmins: collection?.additionalAdmins,
84
+ contractAdmin: collection?.contractAdmin,
85
+ collectionAddress,
86
86
  publicClient
87
87
  });
88
88
  return {
@@ -163,15 +163,24 @@ var supportsPremintVersion = async ({
163
163
  return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
164
164
  };
165
165
  async function getPremintCollectionAddress({
166
+ publicClient,
166
167
  collection,
167
- publicClient
168
+ collectionAddress
168
169
  }) {
169
- return publicClient.readContract({
170
- address: getPremintExecutorAddress(),
171
- abi: zoraCreator1155PremintExecutorImplABI,
172
- functionName: "getContractAddress",
173
- args: [collection]
174
- });
170
+ if (typeof collection !== "undefined") {
171
+ return publicClient.readContract({
172
+ address: getPremintExecutorAddress(),
173
+ abi: zoraCreator1155PremintExecutorImplABI,
174
+ functionName: "getContractWithAdditionalAdminsAddress",
175
+ args: [
176
+ {
177
+ ...collection,
178
+ additionalAdmins: collection.additionalAdmins || []
179
+ }
180
+ ]
181
+ });
182
+ }
183
+ return collectionAddress;
175
184
  }
176
185
  function applyUpdateToPremint({
177
186
  uid,
@@ -240,6 +249,34 @@ function makeMintRewardsRecipient({
240
249
  function getDefaultFixedPriceMinterAddress(chainId) {
241
250
  return zoraCreatorFixedPriceSaleStrategyAddress[chainId];
242
251
  }
252
+ var emptyContractCreationConfig = () => ({
253
+ contractAdmin: zeroAddress,
254
+ contractURI: "",
255
+ contractName: "",
256
+ additionalAdmins: []
257
+ });
258
+ function defaultAdditionalAdmins(collection) {
259
+ return {
260
+ ...collection,
261
+ additionalAdmins: collection.additionalAdmins || []
262
+ };
263
+ }
264
+ var toContractCreationConfigOrAddress = ({
265
+ collection,
266
+ collectionAddress
267
+ }) => {
268
+ if (typeof collection !== "undefined") {
269
+ return {
270
+ collection
271
+ };
272
+ }
273
+ if (typeof collectionAddress !== "undefined") {
274
+ return {
275
+ collectionAddress
276
+ };
277
+ }
278
+ throw new Error("Must provide either a collection or a collection address");
279
+ };
243
280
 
244
281
  // src/premint/premint-client.ts
245
282
  import {
@@ -539,11 +576,16 @@ var MintAPIClient = class {
539
576
  import {
540
577
  PremintConfigVersion
541
578
  } from "@zoralabs/protocol-deployments";
542
- var convertCollectionFromApi = (collection) => ({
543
- ...collection,
544
- contractAdmin: collection.contractAdmin,
545
- additionalAdmins: []
546
- });
579
+ var convertCollectionFromApi = (collection) => {
580
+ if (!collection)
581
+ return void 0;
582
+ return {
583
+ additionalAdmins: collection.additionalAdmins || [],
584
+ contractAdmin: collection.contractAdmin,
585
+ contractName: collection.contractName,
586
+ contractURI: collection.contractURI
587
+ };
588
+ };
547
589
  var convertPremintFromApi = (premint) => {
548
590
  if (premint.config_version === PremintConfigVersion.V1 || !premint.config_version) {
549
591
  const tokenConfig = premint.tokenConfig;
@@ -591,6 +633,7 @@ var convertPremintFromApi = (premint) => {
591
633
  var convertGetPremintApiResponse = (response) => ({
592
634
  ...convertPremintFromApi(response.premint),
593
635
  collection: convertCollectionFromApi(response.collection),
636
+ collectionAddress: response.collection_address,
594
637
  signature: response.signature
595
638
  });
596
639
  var encodePremintV1ForAPI = ({
@@ -637,6 +680,7 @@ var encodePremintForAPI = ({
637
680
  };
638
681
  var encodePostSignatureInput = ({
639
682
  collection,
683
+ collectionAddress,
640
684
  premintConfigVersion,
641
685
  premintConfig,
642
686
  signature,
@@ -648,6 +692,7 @@ var encodePostSignatureInput = ({
648
692
  }),
649
693
  signature,
650
694
  collection,
695
+ collection_address: collectionAddress,
651
696
  chain_name: networkConfigByChain[chainId].zoraBackendChainName
652
697
  });
653
698
 
@@ -683,13 +728,11 @@ var getSignature = async ({
683
728
  var PremintAPIClient = class {
684
729
  constructor(chainId, httpClient2) {
685
730
  this.postSignature = async ({
686
- collection,
687
731
  signature,
688
- ...premintConfigAndVersion
732
+ ...rest
689
733
  }) => {
690
734
  const data = encodePostSignatureInput({
691
- collection,
692
- ...premintConfigAndVersion,
735
+ ...rest,
693
736
  chainId: this.networkConfig.chainId,
694
737
  signature
695
738
  });
@@ -721,7 +764,18 @@ var PremintAPIClient = class {
721
764
  };
722
765
 
723
766
  // src/utils.ts
767
+ import {
768
+ createPublicClient,
769
+ http
770
+ } from "viem";
724
771
  var makeSimulateContractParamaters = (args) => args;
772
+ function setupClient({ chain, httpClient: httpClient2, publicClient }) {
773
+ return {
774
+ chain,
775
+ httpClient: httpClient2 || httpClient,
776
+ publicClient: publicClient || createPublicClient({ chain, transport: http() })
777
+ };
778
+ }
725
779
 
726
780
  // src/premint/premint-client.ts
727
781
  var defaultTokenConfigV1MintArguments = () => ({
@@ -735,6 +789,37 @@ var defaultTokenConfigV1MintArguments = () => ({
735
789
  royaltyBPS: 1e3
736
790
  // 10%,
737
791
  });
792
+ var pickTokenConfigV1 = (tokenConfig) => ({
793
+ maxSupply: tokenConfig.maxSupply,
794
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
795
+ pricePerToken: tokenConfig.pricePerToken,
796
+ mintDuration: tokenConfig.mintDuration,
797
+ mintStart: tokenConfig.mintStart,
798
+ royaltyBPS: tokenConfig.royaltyBPS,
799
+ tokenURI: tokenConfig.tokenURI,
800
+ royaltyRecipient: tokenConfig.payoutRecipient
801
+ });
802
+ var pickTokenConfigV2 = (tokenConfig) => ({
803
+ maxSupply: tokenConfig.maxSupply,
804
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
805
+ pricePerToken: tokenConfig.pricePerToken,
806
+ mintDuration: tokenConfig.mintDuration,
807
+ mintStart: tokenConfig.mintStart,
808
+ royaltyBPS: tokenConfig.royaltyBPS,
809
+ tokenURI: tokenConfig.tokenURI,
810
+ payoutRecipient: tokenConfig.payoutRecipient,
811
+ createReferral: tokenConfig.createReferral || zeroAddress2
812
+ });
813
+ var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
814
+ ...pickTokenConfigV1(tokenConfig),
815
+ ...defaultTokenConfigV1MintArguments(),
816
+ fixedPriceMinter
817
+ });
818
+ var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
819
+ ...pickTokenConfigV2(tokenConfig),
820
+ ...defaultTokenConfigV2MintArguments(),
821
+ fixedPriceMinter
822
+ });
738
823
  var defaultTokenConfigV2MintArguments = () => ({
739
824
  maxSupply: OPEN_EDITION_MINT_SIZE,
740
825
  maxTokensPerAddress: 0n,
@@ -747,32 +832,29 @@ var defaultTokenConfigV2MintArguments = () => ({
747
832
  });
748
833
  var makeTokenConfigWithDefaults = ({
749
834
  chainId,
750
- premintConfigVersion,
751
835
  tokenCreationConfig,
752
- creatorAccount
836
+ supportedPremintVersions: supportedPremintVersions2
753
837
  }) => {
754
- if (premintConfigVersion === PremintConfigVersion2.V3) {
755
- throw new Error("PremintV3 not supported in SDK");
756
- }
757
- const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
758
- if (premintConfigVersion === PremintConfigVersion2.V1) {
759
- return {
760
- fixedPriceMinter,
761
- ...defaultTokenConfigV1MintArguments(),
762
- royaltyRecipient: creatorAccount,
763
- ...tokenCreationConfig
764
- };
765
- } else if (premintConfigVersion === PremintConfigVersion2.V2) {
838
+ const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
839
+ if (!supportedPremintVersions2.includes(PremintConfigVersion2.V2)) {
840
+ if (tokenCreationConfig.createReferral) {
841
+ throw new Error("Contract does not support create referral");
842
+ }
766
843
  return {
767
- fixedPriceMinter,
768
- ...defaultTokenConfigV2MintArguments(),
769
- payoutRecipient: creatorAccount,
770
- createReferral: zeroAddress2,
771
- ...tokenCreationConfig
844
+ premintConfigVersion: PremintConfigVersion2.V1,
845
+ tokenConfig: tokenConfigV1WithDefault(
846
+ tokenCreationConfig,
847
+ fixedPriceMinter
848
+ )
772
849
  };
773
- } else {
774
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
775
850
  }
851
+ return {
852
+ premintConfigVersion: PremintConfigVersion2.V2,
853
+ tokenConfig: tokenConfigV2WithDefault(
854
+ tokenCreationConfig,
855
+ fixedPriceMinter
856
+ )
857
+ };
776
858
  };
777
859
  function getPremintedLogFromReceipt(receipt) {
778
860
  for (const data of receipt.logs) {
@@ -793,7 +875,7 @@ var PremintClient = class {
793
875
  constructor(chain, publicClient, httpClient2) {
794
876
  this.chain = chain;
795
877
  this.apiClient = new PremintAPIClient(chain.id, httpClient2);
796
- this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
878
+ this.publicClient = publicClient;
797
879
  }
798
880
  getDataFromPremintReceipt(receipt) {
799
881
  const premintedLog = getPremintedLogFromReceipt(receipt);
@@ -806,174 +888,45 @@ var PremintClient = class {
806
888
  };
807
889
  }
808
890
  /**
809
- * Update existing premint given collection address and UID of existing premint.
810
- *
811
- * 1. Loads existing premint token
812
- * 2. Updates with settings passed into function
813
- * 3. Increments the version field
814
- * 4. Re-signs the premint
815
- * 5. Uploads the premint to the ZORA API
816
- *
817
- * Updates existing premint
818
- * @param settings Settings for the new premint
819
- * @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
820
- * @param settings.collection Collection information for the mint
821
- * @param settings.walletClient viem wallet client to use to sign
822
- * @param settings.uid UID
823
- * @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
891
+ * Prepares data for updating a premint
824
892
  *
893
+ * @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
894
+ * @returns A PremintReturn. {@link PremintReturn}
825
895
  */
826
- async updatePremint({
827
- walletClient,
828
- uid,
829
- collection,
830
- account,
831
- tokenConfigUpdates
832
- }) {
833
- const {
834
- premintConfig,
835
- collection: collectionCreationConfig,
836
- premintConfigVersion
837
- } = await this.apiClient.getSignature({
838
- collectionAddress: collection,
839
- uid
840
- });
841
- const updatedPremint = applyUpdateToPremint({
842
- uid: premintConfig.uid,
843
- version: premintConfig.version,
844
- tokenConfig: premintConfig.tokenConfig,
845
- tokenConfigUpdates
846
- });
847
- return await this.signAndSubmitPremint({
848
- walletClient,
849
- account,
850
- checkSignature: true,
851
- verifyingContract: collection,
852
- collection: collectionCreationConfig,
853
- premintConfig: updatedPremint,
854
- premintConfigVersion
855
- });
856
- }
857
- /**
858
- * Delete premint.
859
- *
860
- * 1. Loads current premint from collection address with UID
861
- * 2. Increments version and marks as deleted
862
- * 3. Signs new premint version
863
- * 4. Sends to ZORA Premint API
864
- *
865
- * Deletes existing premint
866
- * @param settings.collection collection address
867
- * @param settings.uid UID
868
- * @param settings.walletClient viem wallet client to use to sign
869
- *
870
- */
871
- async deletePremint({
872
- walletClient,
873
- uid,
874
- account,
875
- collection
876
- }) {
877
- const {
878
- premintConfig,
879
- premintConfigVersion,
880
- collection: collectionCreationConfig
881
- } = await this.apiClient.getSignature({
882
- collectionAddress: collection,
883
- uid
884
- });
885
- const deletedPremint = {
886
- ...premintConfig,
887
- version: premintConfig.version + 1,
888
- deleted: true
889
- };
890
- return await this.signAndSubmitPremint({
891
- walletClient,
892
- account,
893
- checkSignature: false,
894
- verifyingContract: collection,
895
- collection: collectionCreationConfig,
896
- premintConfig: deletedPremint,
897
- premintConfigVersion
896
+ async updatePremint(args) {
897
+ return await updatePremint({
898
+ ...args,
899
+ apiClient: this.apiClient,
900
+ publicClient: this.publicClient,
901
+ chainId: this.chain.id
898
902
  });
899
903
  }
900
904
  /**
901
- * Internal function to sign and submit a premint request.
905
+ * Prepares data for deleting a premint
902
906
  *
903
- * @param premintArguments Arguments to premint
904
- * @returns
907
+ * @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
908
+ * @returns A PremintReturn. {@link PremintReturn}
905
909
  */
906
- async signAndSubmitPremint(params) {
907
- const { verifyingContract } = await signAndSubmitPremint({
910
+ async deletePremint(params) {
911
+ return deletePremint({
908
912
  ...params,
909
- chainId: this.chain.id,
910
913
  apiClient: this.apiClient,
911
- publicClient: this.publicClient
914
+ publicClient: this.publicClient,
915
+ chainId: this.chain.id
912
916
  });
913
- const uid = params.premintConfig.uid;
914
- return {
915
- urls: this.makeUrls({ address: verifyingContract, uid }),
916
- uid,
917
- verifyingContract
918
- };
919
917
  }
920
918
  /**
921
- * Create premint
919
+ * Prepares data for creating a premint
922
920
  *
923
- * @param settings Settings for the new premint
924
- * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
925
- * @param settings.collection Collection information for the mint
926
- * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
927
- * @param setings.premintConfigVersion Premint config version to use, defaults to V2
928
- * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
929
- * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
930
- * @returns premint url, uid, newContractAddress, and premint object
921
+ * @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
922
+ * @returns A PremintReturn. {@link PremintReturn}
931
923
  */
932
- async createPremint({
933
- creatorAccount,
934
- collection,
935
- tokenCreationConfig,
936
- premintConfigVersion,
937
- walletClient,
938
- uid,
939
- checkSignature = false
940
- }) {
941
- const newContractAddress = await getPremintCollectionAddress({
924
+ async createPremint(parameters) {
925
+ return createPremint({
926
+ ...parameters,
942
927
  publicClient: this.publicClient,
943
- collection
944
- });
945
- let uidToUse = uid;
946
- if (typeof uidToUse !== "number") {
947
- uidToUse = await this.apiClient.getNextUID(newContractAddress);
948
- }
949
- const actualVersion = premintConfigVersion || PremintConfigVersion2.V1;
950
- if (!await supportsPremintVersion({
951
- version: actualVersion,
952
- publicClient: this.publicClient,
953
- tokenContract: newContractAddress
954
- })) {
955
- throw new Error(
956
- `Premint version ${actualVersion} not supported by contract`
957
- );
958
- }
959
- const premintConfig = makeNewPremint({
960
- tokenConfig: makeTokenConfigWithDefaults({
961
- // @ts-ignore
962
- premintConfigVersion: actualVersion,
963
- tokenCreationConfig,
964
- creatorAccount: typeof creatorAccount === "string" ? creatorAccount : creatorAccount.address,
965
- chainId: this.chain.id
966
- }),
967
- uid: uidToUse
968
- });
969
- return await this.signAndSubmitPremint({
970
- verifyingContract: newContractAddress,
971
- premintConfig,
972
- premintConfigVersion: actualVersion,
973
- checkSignature,
974
- account: creatorAccount,
975
- walletClient,
976
- collection
928
+ apiClient: this.apiClient,
929
+ chainId: this.chain.id
977
930
  });
978
931
  }
979
932
  /**
@@ -1011,17 +964,22 @@ var PremintClient = class {
1011
964
  */
1012
965
  async isValidSignature({
1013
966
  signature,
1014
- collection,
1015
967
  premintConfig,
1016
- premintConfigVersion
968
+ premintConfigVersion,
969
+ ...collectionAndOrAddress
1017
970
  }) {
971
+ const collectionAddressToUse = await getPremintCollectionAddress({
972
+ ...collectionAndOrAddress,
973
+ publicClient: this.publicClient
974
+ });
1018
975
  const { isAuthorized, recoveredAddress } = await isValidSignature({
1019
976
  chainId: this.chain.id,
1020
977
  signature,
1021
- collection,
1022
978
  publicClient: this.publicClient,
1023
979
  premintConfig,
1024
- premintConfigVersion: premintConfigVersion || PremintConfigVersion2.V1
980
+ premintConfigVersion: premintConfigVersion || PremintConfigVersion2.V1,
981
+ collectionAddress: collectionAddressToUse,
982
+ collection: collectionAndOrAddress.collection
1025
983
  });
1026
984
  return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
1027
985
  }
@@ -1050,91 +1008,308 @@ var PremintClient = class {
1050
1008
  });
1051
1009
  }
1052
1010
  /**
1053
- * Execute premint on-chain
1011
+ * Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
1012
+ * tokens on that contract for the mint recipient.
1054
1013
  *
1055
- * @param settings.data Data from the API for the mint
1056
- * @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
1057
- * @param settings.walletClient WalletClient to send execution from.
1058
- * @param settings.mintArguments User minting arguments.
1059
- * @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
1060
- * @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
1061
- * @param settings.publicClient Optional public client for preflight checks.
1014
+ * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
1062
1015
  * @returns receipt, log, zoraURL
1063
1016
  */
1064
- async makeMintParameters({
1065
- uid,
1066
- tokenContract,
1067
- minterAccount,
1068
- mintArguments
1069
- }) {
1070
- if (mintArguments && mintArguments?.quantityToMint < 1) {
1071
- throw new Error("Quantity to mint cannot be below 1");
1072
- }
1073
- if (!minterAccount) {
1074
- throw new Error("Wallet not passed in");
1075
- }
1076
- const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
1077
- address: tokenContract,
1078
- uid
1017
+ async makeMintParameters(parameters) {
1018
+ return await makeMintParameters({
1019
+ ...parameters,
1020
+ apiClient: this.apiClient,
1021
+ publicClient: this.publicClient
1079
1022
  });
1080
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1081
- if (premintConfigVersion === PremintConfigVersion2.V3) {
1082
- throw new Error("PremintV3 not supported in premint SDK");
1083
- }
1084
- const value = (await getPremintMintCosts({
1085
- tokenContract,
1086
- quantityToMint: numberToMint,
1087
- publicClient: this.publicClient,
1088
- tokenPrice: premintConfig.tokenConfig.pricePerToken
1089
- })).totalCost;
1090
- const mintArgumentsContract = {
1091
- mintComment: mintArguments?.mintComment || "",
1092
- mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1093
- mintRewardsRecipients: makeMintRewardsRecipient({
1094
- mintReferral: mintArguments?.mintReferral,
1095
- platformReferral: mintArguments?.platformReferral
1096
- })
1023
+ }
1024
+ };
1025
+ function createPremintClient(clientConfig) {
1026
+ const { chain, httpClient: httpClient2, publicClient } = setupClient(clientConfig);
1027
+ return new PremintClient(chain, publicClient, httpClient2);
1028
+ }
1029
+ function makePremintReturn({
1030
+ premintConfig,
1031
+ premintConfigVersion,
1032
+ publicClient,
1033
+ apiClient,
1034
+ chainId,
1035
+ ...collectionAndAddress
1036
+ }) {
1037
+ const { collection, collectionAddress } = collectionAndAddress;
1038
+ const typedDataDefinition = premintTypedDataDefinition2({
1039
+ verifyingContract: collectionAddress,
1040
+ premintConfig,
1041
+ premintConfigVersion,
1042
+ chainId
1043
+ });
1044
+ const signAndSubmit = async ({
1045
+ walletClient,
1046
+ account,
1047
+ checkSignature
1048
+ }) => {
1049
+ const { signature, signerAccount } = await signPremint({
1050
+ account,
1051
+ walletClient,
1052
+ typedDataDefinition
1053
+ });
1054
+ await submit({
1055
+ signature,
1056
+ checkSignature,
1057
+ signerAccount
1058
+ });
1059
+ return {
1060
+ signature,
1061
+ signerAccount
1097
1062
  };
1098
- if (premintConfigVersion === PremintConfigVersion2.V1) {
1099
- return makeSimulateContractParamaters({
1100
- account: minterAccount,
1101
- abi: zoraCreator1155PremintExecutorImplABI2,
1102
- functionName: "premintV1",
1103
- value,
1104
- address: getPremintExecutorAddress(),
1105
- args: [
1106
- collection,
1107
- premintConfig,
1108
- signature,
1109
- numberToMint,
1110
- mintArgumentsContract
1111
- ]
1112
- });
1113
- } else if (premintConfigVersion === PremintConfigVersion2.V2) {
1114
- return makeSimulateContractParamaters({
1115
- account: minterAccount,
1116
- abi: zoraCreator1155PremintExecutorImplABI2,
1117
- functionName: "premintV2",
1118
- value,
1119
- address: getPremintExecutorAddress(),
1120
- args: [
1121
- collection,
1122
- premintConfig,
1123
- signature,
1124
- numberToMint,
1125
- mintArgumentsContract
1126
- ]
1063
+ };
1064
+ const submit = async ({
1065
+ signature,
1066
+ checkSignature,
1067
+ signerAccount
1068
+ }) => {
1069
+ if (checkSignature) {
1070
+ const isAuthorized = await isAuthorizedToCreatePremint({
1071
+ collectionAddress,
1072
+ additionalAdmins: collection?.additionalAdmins,
1073
+ contractAdmin: collection?.contractAdmin,
1074
+ publicClient,
1075
+ signer: signerAccount
1127
1076
  });
1077
+ if (!isAuthorized) {
1078
+ throw new Error("Not authorized to create premint");
1079
+ }
1128
1080
  }
1129
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1081
+ await apiClient.postSignature({
1082
+ ...toContractCreationConfigOrAddress(collectionAndAddress),
1083
+ signature,
1084
+ premintConfig,
1085
+ premintConfigVersion
1086
+ });
1087
+ };
1088
+ return {
1089
+ premintConfig,
1090
+ premintConfigVersion,
1091
+ typedDataDefinition,
1092
+ collectionAddress,
1093
+ signAndSubmit,
1094
+ submit
1095
+ };
1096
+ }
1097
+ async function signPremint({
1098
+ account,
1099
+ walletClient,
1100
+ typedDataDefinition
1101
+ }) {
1102
+ if (!account) {
1103
+ account = walletClient.account;
1130
1104
  }
1131
- };
1132
- function createPremintClient({
1133
- chain,
1134
- httpClient: httpClient2,
1105
+ if (!account) {
1106
+ throw new Error("No account provided");
1107
+ }
1108
+ const signature = await walletClient.signTypedData({
1109
+ account,
1110
+ ...typedDataDefinition
1111
+ });
1112
+ return {
1113
+ signature,
1114
+ signerAccount: account
1115
+ };
1116
+ }
1117
+ async function createPremint({
1118
+ tokenCreationConfig,
1119
+ uid,
1120
+ publicClient,
1121
+ apiClient,
1122
+ chainId,
1123
+ ...collectionOrAddress
1124
+ }) {
1125
+ const {
1126
+ premintConfig,
1127
+ premintConfigVersion,
1128
+ collectionAddress: collectionAddressToUse
1129
+ } = await prepareCreatePremintConfig({
1130
+ ...collectionOrAddress,
1131
+ tokenCreationConfig,
1132
+ uid,
1133
+ publicClient,
1134
+ apiClient,
1135
+ chainId
1136
+ });
1137
+ return makePremintReturn({
1138
+ premintConfig,
1139
+ premintConfigVersion,
1140
+ collectionAddress: collectionAddressToUse,
1141
+ collection: collectionOrAddress.collection,
1142
+ publicClient,
1143
+ apiClient,
1144
+ chainId
1145
+ });
1146
+ }
1147
+ async function prepareCreatePremintConfig({
1148
+ tokenCreationConfig,
1149
+ uid,
1150
+ publicClient,
1151
+ apiClient,
1152
+ chainId,
1153
+ ...collectionOrAddress
1154
+ }) {
1155
+ const newContractAddress = await getPremintCollectionAddress({
1156
+ publicClient,
1157
+ ...collectionOrAddress
1158
+ });
1159
+ let uidToUse = uid;
1160
+ if (typeof uidToUse !== "number") {
1161
+ uidToUse = await apiClient.getNextUID(newContractAddress);
1162
+ }
1163
+ const supportedVersions = await supportedPremintVersions({
1164
+ tokenContract: newContractAddress,
1165
+ publicClient
1166
+ });
1167
+ const tokenConfigAndVersion = makeTokenConfigWithDefaults({
1168
+ tokenCreationConfig,
1169
+ chainId,
1170
+ supportedPremintVersions: supportedVersions
1171
+ });
1172
+ const premintConfig = makeNewPremint({
1173
+ ...tokenConfigAndVersion,
1174
+ uid: uidToUse
1175
+ });
1176
+ const premintConfigAndVersion = {
1177
+ premintConfig,
1178
+ premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
1179
+ };
1180
+ return {
1181
+ ...premintConfigAndVersion,
1182
+ collectionAddress: newContractAddress
1183
+ };
1184
+ }
1185
+ async function updatePremint({
1186
+ uid,
1187
+ collection,
1188
+ tokenConfigUpdates,
1189
+ apiClient,
1190
+ publicClient,
1191
+ chainId
1192
+ }) {
1193
+ const {
1194
+ premintConfig,
1195
+ collection: collectionCreationConfig,
1196
+ premintConfigVersion
1197
+ } = await apiClient.getSignature({
1198
+ collectionAddress: collection,
1199
+ uid
1200
+ });
1201
+ const updatedPremint = applyUpdateToPremint({
1202
+ uid: premintConfig.uid,
1203
+ version: premintConfig.version,
1204
+ tokenConfig: premintConfig.tokenConfig,
1205
+ tokenConfigUpdates
1206
+ });
1207
+ return makePremintReturn({
1208
+ premintConfig: updatedPremint,
1209
+ premintConfigVersion,
1210
+ collectionAddress: collection,
1211
+ collection: collectionCreationConfig,
1212
+ publicClient,
1213
+ apiClient,
1214
+ chainId
1215
+ });
1216
+ }
1217
+ async function deletePremint({
1218
+ uid,
1219
+ collection,
1220
+ publicClient,
1221
+ apiClient,
1222
+ chainId
1223
+ }) {
1224
+ const {
1225
+ premintConfig,
1226
+ premintConfigVersion,
1227
+ collection: collectionCreationConfig,
1228
+ collectionAddress
1229
+ } = await apiClient.getSignature({
1230
+ collectionAddress: collection,
1231
+ uid
1232
+ });
1233
+ const deletedPremint = {
1234
+ ...premintConfig,
1235
+ version: premintConfig.version + 1,
1236
+ deleted: true
1237
+ };
1238
+ return makePremintReturn({
1239
+ premintConfig: deletedPremint,
1240
+ premintConfigVersion,
1241
+ collectionAddress,
1242
+ collection: collectionCreationConfig,
1243
+ publicClient,
1244
+ apiClient,
1245
+ chainId
1246
+ });
1247
+ }
1248
+ async function makeMintParameters({
1249
+ uid,
1250
+ tokenContract,
1251
+ minterAccount,
1252
+ mintArguments,
1253
+ firstMinter,
1254
+ apiClient,
1135
1255
  publicClient
1136
1256
  }) {
1137
- return new PremintClient(chain, publicClient, httpClient2);
1257
+ if (mintArguments && mintArguments?.quantityToMint < 1) {
1258
+ throw new Error("Quantity to mint cannot be below 1");
1259
+ }
1260
+ if (!minterAccount) {
1261
+ throw new Error("Wallet not passed in");
1262
+ }
1263
+ const {
1264
+ premintConfig,
1265
+ premintConfigVersion,
1266
+ collection,
1267
+ collectionAddress,
1268
+ signature
1269
+ } = await apiClient.getSignature({
1270
+ collectionAddress: tokenContract,
1271
+ uid
1272
+ });
1273
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1274
+ if (premintConfigVersion === PremintConfigVersion2.V3) {
1275
+ throw new Error("PremintV3 not supported in premint SDK");
1276
+ }
1277
+ const value = (await getPremintMintCosts({
1278
+ tokenContract,
1279
+ quantityToMint: numberToMint,
1280
+ publicClient,
1281
+ tokenPrice: premintConfig.tokenConfig.pricePerToken
1282
+ })).totalCost;
1283
+ const mintArgumentsContract = {
1284
+ mintComment: mintArguments?.mintComment || "",
1285
+ mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1286
+ mintRewardsRecipients: makeMintRewardsRecipient({
1287
+ mintReferral: mintArguments?.mintReferral
1288
+ })
1289
+ };
1290
+ const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
1291
+ const collectionAddressToSubmit = collection ? zeroAddress2 : collectionAddress;
1292
+ const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
1293
+ return makeSimulateContractParamaters({
1294
+ account: minterAccount,
1295
+ abi: zoraCreator1155PremintExecutorImplABI2,
1296
+ functionName: "premint",
1297
+ value,
1298
+ address: getPremintExecutorAddress(),
1299
+ args: [
1300
+ collectionOrEmpty,
1301
+ collectionAddressToSubmit,
1302
+ encodePremintConfig({
1303
+ premintConfig,
1304
+ premintConfigVersion
1305
+ }),
1306
+ signature,
1307
+ numberToMint,
1308
+ mintArgumentsContract,
1309
+ firstMinterToSubmit,
1310
+ zeroAddress2
1311
+ ]
1312
+ });
1138
1313
  }
1139
1314
  function makeUrls({
1140
1315
  uid,
@@ -1153,55 +1328,11 @@ function makeUrls({
1153
1328
  zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
1154
1329
  };
1155
1330
  }
1156
- async function signAndSubmitPremint({
1157
- walletClient,
1158
- verifyingContract,
1159
- account,
1160
- checkSignature,
1161
- collection,
1162
- chainId,
1163
- publicClient,
1164
- apiClient,
1165
- ...premintConfigAndVersion
1166
- }) {
1167
- if (!account) {
1168
- account = walletClient.account;
1169
- }
1170
- if (!account) {
1171
- throw new Error("No account provided");
1172
- }
1173
- const signature = await walletClient.signTypedData({
1174
- account,
1175
- ...premintTypedDataDefinition2({
1176
- verifyingContract,
1177
- ...premintConfigAndVersion,
1178
- chainId
1179
- })
1180
- });
1181
- if (checkSignature) {
1182
- const isAuthorized = await isAuthorizedToCreatePremint({
1183
- collection,
1184
- publicClient,
1185
- signer: typeof account === "string" ? account : account.address,
1186
- collectionAddress: await getPremintCollectionAddress({
1187
- collection,
1188
- publicClient
1189
- })
1190
- });
1191
- if (!isAuthorized) {
1192
- throw new Error("Not authorized to create premint");
1193
- }
1194
- }
1195
- const premint = await apiClient.postSignature({
1196
- collection,
1197
- signature,
1198
- ...premintConfigAndVersion
1199
- });
1200
- return { premint, verifyingContract };
1201
- }
1202
1331
 
1203
1332
  // src/premint/contract-types.ts
1204
- import { PremintConfigVersion as PremintConfigVersionOrig } from "@zoralabs/protocol-deployments";
1333
+ import {
1334
+ PremintConfigVersion as PremintConfigVersionOrig
1335
+ } from "@zoralabs/protocol-deployments";
1205
1336
  var PremintConfigVersion3 = ((PremintConfigVersion4) => {
1206
1337
  PremintConfigVersion4[PremintConfigVersion4["V1"] = PremintConfigVersionOrig.V1] = "V1";
1207
1338
  PremintConfigVersion4[PremintConfigVersion4["V2"] = PremintConfigVersionOrig.V2] = "V2";
@@ -1211,11 +1342,9 @@ var PremintConfigVersion3 = ((PremintConfigVersion4) => {
1211
1342
 
1212
1343
  // src/mint/mint-client.ts
1213
1344
  import {
1214
- createPublicClient as createPublicClient2,
1215
1345
  encodeAbiParameters,
1216
1346
  parseAbiParameters,
1217
- zeroAddress as zeroAddress3,
1218
- http as http2
1347
+ zeroAddress as zeroAddress3
1219
1348
  } from "viem";
1220
1349
  import {
1221
1350
  erc20MinterABI,
@@ -1234,30 +1363,24 @@ var Errors = {
1234
1363
  var MintClient = class {
1235
1364
  constructor(chain, publicClient, httpClient2) {
1236
1365
  this.apiClient = new MintAPIClient(chain.id, httpClient2);
1237
- this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
1366
+ this.publicClient = publicClient;
1238
1367
  }
1239
1368
  /**
1240
1369
  * Returns the parameters needed to prepare a transaction mint a token.
1241
- * @param param0.minterAccount The account that will mint the token.
1242
- * @param param0.mintable The mintable token to mint.
1243
- * @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
1244
- * @returns
1370
+ *
1371
+ * @param parameters - Parameters for collecting the token {@link MintTokenParams}
1372
+ * @returns Parameters for simulating/executing the mint transaction
1245
1373
  */
1246
- async makePrepareMintTokenParams({
1247
- ...rest
1248
- }) {
1374
+ async makePrepareMintTokenParams(parameters) {
1249
1375
  return makePrepareMintTokenParams({
1250
- ...rest,
1376
+ ...parameters,
1251
1377
  apiClient: this.apiClient,
1252
1378
  publicClient: this.publicClient
1253
1379
  });
1254
1380
  }
1255
1381
  };
1256
- function createMintClient({
1257
- chain,
1258
- publicClient,
1259
- httpClient: httpClient2
1260
- }) {
1382
+ function createMintClient(clientConfig) {
1383
+ const { chain, publicClient, httpClient: httpClient2 } = setupClient(clientConfig);
1261
1384
  return new MintClient(chain, publicClient, httpClient2);
1262
1385
  }
1263
1386
  async function makePrepareMintTokenParams({
@@ -1539,9 +1662,8 @@ async function getContractExists(publicClient, contract, account) {
1539
1662
  contractAddress: contract
1540
1663
  };
1541
1664
  }
1542
- function create1155CreatorClient({
1543
- publicClient
1544
- }) {
1665
+ function create1155CreatorClient(clientConfig) {
1666
+ const { publicClient } = setupClient(clientConfig);
1545
1667
  async function createNew1155Token({
1546
1668
  contract,
1547
1669
  tokenMetadataURI,
@@ -1986,8 +2108,10 @@ export {
1986
2108
  createMintClient,
1987
2109
  createPremintClient,
1988
2110
  decodeCallFailedError,
2111
+ defaultAdditionalAdmins,
1989
2112
  defaultTokenConfigV1MintArguments,
1990
2113
  defaultTokenConfigV2MintArguments,
2114
+ emptyContractCreationConfig,
1991
2115
  encodeCollectOnManager,
1992
2116
  encodePostSignatureInput,
1993
2117
  encodePremintForAPI,
@@ -2010,6 +2134,7 @@ export {
2010
2134
  makePermitToCollectPremintOrNonPremint,
2011
2135
  makePermitTransferBatchAndTypeData,
2012
2136
  makePermitTransferTypeData,
2137
+ makeUrls,
2013
2138
  migratePremintConfigToV2,
2014
2139
  mintWithEthParams,
2015
2140
  mintsBalanceOfAccountParams,
@@ -2019,6 +2144,7 @@ export {
2019
2144
  sumBalances,
2020
2145
  supportedPremintVersions,
2021
2146
  supportsPremintVersion,
2147
+ toContractCreationConfigOrAddress,
2022
2148
  tryRecoverPremintSigner,
2023
2149
  unwrapAndForwardEthPermitAndTypedDataDefinition
2024
2150
  };