@zoralabs/protocol-sdk 0.5.14 → 0.5.16

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 (37) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +42 -2
  4. package/dist/anvil.d.ts +4 -4
  5. package/dist/anvil.d.ts.map +1 -1
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/create/1155-create-helper.d.ts +3 -4
  9. package/dist/create/1155-create-helper.d.ts.map +1 -1
  10. package/dist/index.cjs +534 -375
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +517 -356
  13. package/dist/index.js.map +1 -1
  14. package/dist/mint/mint-api-client.d.ts +14 -6
  15. package/dist/mint/mint-api-client.d.ts.map +1 -1
  16. package/dist/mint/mint-client.d.ts +25 -19
  17. package/dist/mint/mint-client.d.ts.map +1 -1
  18. package/dist/mints/mints-contracts.d.ts +688 -3
  19. package/dist/mints/mints-contracts.d.ts.map +1 -1
  20. package/dist/premint/premint-client.d.ts +111 -1465
  21. package/dist/premint/premint-client.d.ts.map +1 -1
  22. package/dist/premint/preminter.d.ts +2 -1
  23. package/dist/premint/preminter.d.ts.map +1 -1
  24. package/dist/utils.d.ts +6872 -1
  25. package/dist/utils.d.ts.map +1 -1
  26. package/package.json +2 -2
  27. package/src/constants.ts +36 -0
  28. package/src/create/1155-create-helper.test.ts +10 -3
  29. package/src/create/1155-create-helper.ts +8 -7
  30. package/src/mint/mint-api-client.ts +107 -45
  31. package/src/mint/mint-client.test.ts +113 -2
  32. package/src/mint/mint-client.ts +95 -53
  33. package/src/premint/premint-client.test.ts +16 -10
  34. package/src/premint/premint-client.ts +566 -374
  35. package/src/premint/preminter.ts +3 -1
  36. package/src/utils.ts +25 -0
  37. package/test-integration/premint-client.test.ts +2 -2
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/premint/premint-client.ts
2
- import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
2
+ import { decodeEventLog, zeroAddress as zeroAddress2 } from "viem";
3
3
  import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/protocol-deployments";
4
4
 
5
5
  // src/premint/preminter.ts
@@ -26,6 +26,8 @@ async function isAuthorizedToCreatePremint({
26
26
  publicClient,
27
27
  signer
28
28
  }) {
29
+ if (collection.additionalAdmins.length > 0)
30
+ throw new Error("additionalAdmins not supported yet.");
29
31
  return await publicClient.readContract({
30
32
  abi: preminterAbi,
31
33
  address: getPremintExecutorAddress(),
@@ -331,6 +333,41 @@ var zora721Abi = parseAbi([
331
333
  "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
332
334
  "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
333
335
  ]);
336
+ var NFT_SALE_QUERY = `
337
+ fragment SaleStrategy on SalesStrategyConfig {
338
+ type
339
+ fixedPrice {
340
+ address
341
+ pricePerToken
342
+ saleEnd
343
+ saleStart
344
+ maxTokensPerAddress
345
+ }
346
+ erc20Minter {
347
+ address
348
+ pricePerToken
349
+ currency
350
+ saleEnd
351
+ saleStart
352
+ maxTokensPerAddress
353
+ }
354
+ }
355
+
356
+ query ($id: ID!) {
357
+ zoraCreateToken(id: $id) {
358
+ id
359
+ contract {
360
+ mintFeePerQuantity
361
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
362
+ ...SaleStrategy
363
+ }
364
+ }
365
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
366
+ ...SaleStrategy
367
+ }
368
+ }
369
+ }
370
+ `;
334
371
 
335
372
  // src/apis/chain-constants.ts
336
373
  import {
@@ -426,38 +463,13 @@ var MintAPIClient = class {
426
463
  }
427
464
  async getSalesConfigAndTokenInfo({
428
465
  tokenAddress,
429
- tokenId
466
+ tokenId,
467
+ saleType
430
468
  }) {
431
469
  const { retries: retries2, post: post2 } = this.httpClient;
432
470
  return retries2(async () => {
433
471
  const response = await post2(this.networkConfig.subgraphUrl, {
434
- query: `
435
- fragment SaleStrategy on SalesStrategyConfig {
436
- type
437
- fixedPrice {
438
- address
439
- pricePerToken
440
- saleEnd
441
- saleStart
442
- maxTokensPerAddress
443
- }
444
- }
445
-
446
- query ($id: ID!) {
447
- zoraCreateToken(id: $id) {
448
- id
449
- contract {
450
- mintFeePerQuantity
451
- salesStrategies(where: { type: "FIXED_PRICE" }) {
452
- ...SaleStrategy
453
- }
454
- }
455
- salesStrategies(where: { type: "FIXED_PRICE" }) {
456
- ...SaleStrategy
457
- }
458
- }
459
- }
460
- `,
472
+ query: NFT_SALE_QUERY,
461
473
  variables: {
462
474
  id: tokenId !== void 0 ? (
463
475
  // Generic Token ID types all stringify down to the base numeric equivalent.
@@ -469,17 +481,56 @@ var MintAPIClient = class {
469
481
  if (!token) {
470
482
  throw new Error("Cannot find a token to mint");
471
483
  }
472
- const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
473
- const fixedPrice = saleStrategies?.sort(
474
- (a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
475
- )?.find(() => true)?.fixedPrice;
476
- if (!fixedPrice) {
477
- throw new Error("Cannot find fixed price sale strategy");
484
+ const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
485
+ const saleStrategies = allStrategies.sort(
486
+ (a, b) => BigInt(
487
+ a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
488
+ ) > BigInt(
489
+ b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
490
+ ) ? 1 : -1
491
+ );
492
+ let targetStrategy;
493
+ if (!saleType) {
494
+ targetStrategy = saleStrategies[0];
495
+ if (!targetStrategy) {
496
+ throw new Error("Cannot find sale strategy");
497
+ }
498
+ } else {
499
+ const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
500
+ targetStrategy = saleStrategies.find(
501
+ (strategy) => strategy.type === mappedSaleType
502
+ );
503
+ if (!targetStrategy) {
504
+ throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
505
+ }
478
506
  }
479
- return {
480
- fixedPrice,
481
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
482
- };
507
+ if (targetStrategy.type === "FIXED_PRICE") {
508
+ return {
509
+ salesConfig: {
510
+ saleType: "fixedPrice",
511
+ ...targetStrategy.fixedPrice,
512
+ maxTokensPerAddress: BigInt(
513
+ targetStrategy.fixedPrice.maxTokensPerAddress
514
+ ),
515
+ pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
516
+ },
517
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
518
+ };
519
+ }
520
+ if (targetStrategy.type === "ERC_20_MINTER") {
521
+ return {
522
+ salesConfig: {
523
+ saleType: "erc20",
524
+ ...targetStrategy.erc20Minter,
525
+ maxTokensPerAddress: BigInt(
526
+ targetStrategy.erc20Minter.maxTokensPerAddress
527
+ ),
528
+ pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
529
+ },
530
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
531
+ };
532
+ }
533
+ throw new Error("Invalid saleType");
483
534
  });
484
535
  }
485
536
  };
@@ -670,7 +721,18 @@ var PremintAPIClient = class {
670
721
  };
671
722
 
672
723
  // src/utils.ts
724
+ import {
725
+ createPublicClient,
726
+ http
727
+ } from "viem";
673
728
  var makeSimulateContractParamaters = (args) => args;
729
+ function setupClient({ chain, httpClient: httpClient2, publicClient }) {
730
+ return {
731
+ chain,
732
+ httpClient: httpClient2 || httpClient,
733
+ publicClient: publicClient || createPublicClient({ chain, transport: http() })
734
+ };
735
+ }
674
736
 
675
737
  // src/premint/premint-client.ts
676
738
  var defaultTokenConfigV1MintArguments = () => ({
@@ -698,7 +760,7 @@ var makeTokenConfigWithDefaults = ({
698
760
  chainId,
699
761
  premintConfigVersion,
700
762
  tokenCreationConfig,
701
- creatorAccount
763
+ payoutRecipient
702
764
  }) => {
703
765
  if (premintConfigVersion === PremintConfigVersion2.V3) {
704
766
  throw new Error("PremintV3 not supported in SDK");
@@ -708,14 +770,14 @@ var makeTokenConfigWithDefaults = ({
708
770
  return {
709
771
  fixedPriceMinter,
710
772
  ...defaultTokenConfigV1MintArguments(),
711
- royaltyRecipient: creatorAccount,
773
+ royaltyRecipient: payoutRecipient,
712
774
  ...tokenCreationConfig
713
775
  };
714
776
  } else if (premintConfigVersion === PremintConfigVersion2.V2) {
715
777
  return {
716
778
  fixedPriceMinter,
717
779
  ...defaultTokenConfigV2MintArguments(),
718
- payoutRecipient: creatorAccount,
780
+ payoutRecipient,
719
781
  createReferral: zeroAddress2,
720
782
  ...tokenCreationConfig
721
783
  };
@@ -742,7 +804,7 @@ var PremintClient = class {
742
804
  constructor(chain, publicClient, httpClient2) {
743
805
  this.chain = chain;
744
806
  this.apiClient = new PremintAPIClient(chain.id, httpClient2);
745
- this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
807
+ this.publicClient = publicClient;
746
808
  }
747
809
  getDataFromPremintReceipt(receipt) {
748
810
  const premintedLog = getPremintedLogFromReceipt(receipt);
@@ -755,174 +817,45 @@ var PremintClient = class {
755
817
  };
756
818
  }
757
819
  /**
758
- * Update existing premint given collection address and UID of existing premint.
759
- *
760
- * 1. Loads existing premint token
761
- * 2. Updates with settings passed into function
762
- * 3. Increments the version field
763
- * 4. Re-signs the premint
764
- * 5. Uploads the premint to the ZORA API
765
- *
766
- * Updates existing premint
767
- * @param settings Settings for the new premint
768
- * @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
769
- * @param settings.collection Collection information for the mint
770
- * @param settings.walletClient viem wallet client to use to sign
771
- * @param settings.uid UID
772
- * @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
820
+ * Prepares data for updating a premint
773
821
  *
822
+ * @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
823
+ * @returns A PremintReturn. {@link PremintReturn}
774
824
  */
775
- async updatePremint({
776
- walletClient,
777
- uid,
778
- collection,
779
- account,
780
- tokenConfigUpdates
781
- }) {
782
- const {
783
- premintConfig,
784
- collection: collectionCreationConfig,
785
- premintConfigVersion
786
- } = await this.apiClient.getSignature({
787
- collectionAddress: collection,
788
- uid
789
- });
790
- const updatedPremint = applyUpdateToPremint({
791
- uid: premintConfig.uid,
792
- version: premintConfig.version,
793
- tokenConfig: premintConfig.tokenConfig,
794
- tokenConfigUpdates
795
- });
796
- return await this.signAndSubmitPremint({
797
- walletClient,
798
- account,
799
- checkSignature: true,
800
- verifyingContract: collection,
801
- collection: collectionCreationConfig,
802
- premintConfig: updatedPremint,
803
- premintConfigVersion
804
- });
805
- }
806
- /**
807
- * Delete premint.
808
- *
809
- * 1. Loads current premint from collection address with UID
810
- * 2. Increments version and marks as deleted
811
- * 3. Signs new premint version
812
- * 4. Sends to ZORA Premint API
813
- *
814
- * Deletes existing premint
815
- * @param settings.collection collection address
816
- * @param settings.uid UID
817
- * @param settings.walletClient viem wallet client to use to sign
818
- *
819
- */
820
- async deletePremint({
821
- walletClient,
822
- uid,
823
- account,
824
- collection
825
- }) {
826
- const {
827
- premintConfig,
828
- premintConfigVersion,
829
- collection: collectionCreationConfig
830
- } = await this.apiClient.getSignature({
831
- collectionAddress: collection,
832
- uid
833
- });
834
- const deletedPremint = {
835
- ...premintConfig,
836
- version: premintConfig.version + 1,
837
- deleted: true
838
- };
839
- return await this.signAndSubmitPremint({
840
- walletClient,
841
- account,
842
- checkSignature: false,
843
- verifyingContract: collection,
844
- collection: collectionCreationConfig,
845
- premintConfig: deletedPremint,
846
- premintConfigVersion
825
+ async updatePremint(args) {
826
+ return await updatePremint({
827
+ ...args,
828
+ apiClient: this.apiClient,
829
+ publicClient: this.publicClient,
830
+ chainId: this.chain.id
847
831
  });
848
832
  }
849
833
  /**
850
- * Internal function to sign and submit a premint request.
834
+ * Prepares data for deleting a premint
851
835
  *
852
- * @param premintArguments Arguments to premint
853
- * @returns
836
+ * @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
837
+ * @returns A PremintReturn. {@link PremintReturn}
854
838
  */
855
- async signAndSubmitPremint(params) {
856
- const { verifyingContract } = await signAndSubmitPremint({
839
+ async deletePremint(params) {
840
+ return deletePremint({
857
841
  ...params,
858
- chainId: this.chain.id,
859
842
  apiClient: this.apiClient,
860
- publicClient: this.publicClient
843
+ publicClient: this.publicClient,
844
+ chainId: this.chain.id
861
845
  });
862
- const uid = params.premintConfig.uid;
863
- return {
864
- urls: this.makeUrls({ address: verifyingContract, uid }),
865
- uid,
866
- verifyingContract
867
- };
868
846
  }
869
847
  /**
870
- * Create premint
848
+ * Prepares data for creating a premint
871
849
  *
872
- * @param settings Settings for the new premint
873
- * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
874
- * @param settings.collection Collection information for the mint
875
- * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
876
- * @param setings.premintConfigVersion Premint config version to use, defaults to V2
877
- * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
878
- * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
879
- * @returns premint url, uid, newContractAddress, and premint object
850
+ * @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
851
+ * @returns A PremintReturn. {@link PremintReturn}
880
852
  */
881
- async createPremint({
882
- creatorAccount,
883
- collection,
884
- tokenCreationConfig,
885
- premintConfigVersion,
886
- walletClient,
887
- uid,
888
- checkSignature = false
889
- }) {
890
- const newContractAddress = await getPremintCollectionAddress({
891
- publicClient: this.publicClient,
892
- collection
893
- });
894
- let uidToUse = uid;
895
- if (typeof uidToUse !== "number") {
896
- uidToUse = await this.apiClient.getNextUID(newContractAddress);
897
- }
898
- const actualVersion = premintConfigVersion || PremintConfigVersion2.V1;
899
- if (!await supportsPremintVersion({
900
- version: actualVersion,
853
+ async createPremint(parameters) {
854
+ return createPremint({
855
+ ...parameters,
901
856
  publicClient: this.publicClient,
902
- tokenContract: newContractAddress
903
- })) {
904
- throw new Error(
905
- `Premint version ${actualVersion} not supported by contract`
906
- );
907
- }
908
- const premintConfig = makeNewPremint({
909
- tokenConfig: makeTokenConfigWithDefaults({
910
- // @ts-ignore
911
- premintConfigVersion: actualVersion,
912
- tokenCreationConfig,
913
- creatorAccount: typeof creatorAccount === "string" ? creatorAccount : creatorAccount.address,
914
- chainId: this.chain.id
915
- }),
916
- uid: uidToUse
917
- });
918
- return await this.signAndSubmitPremint({
919
- verifyingContract: newContractAddress,
920
- premintConfig,
921
- premintConfigVersion: actualVersion,
922
- checkSignature,
923
- account: creatorAccount,
924
- walletClient,
925
- collection
857
+ apiClient: this.apiClient,
858
+ chainId: this.chain.id
926
859
  });
927
860
  }
928
861
  /**
@@ -999,91 +932,342 @@ var PremintClient = class {
999
932
  });
1000
933
  }
1001
934
  /**
1002
- * Execute premint on-chain
935
+ * Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
936
+ * tokens on that contract for the mint recipient.
1003
937
  *
1004
- * @param settings.data Data from the API for the mint
1005
- * @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
1006
- * @param settings.walletClient WalletClient to send execution from.
1007
- * @param settings.mintArguments User minting arguments.
1008
- * @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
1009
- * @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
1010
- * @param settings.publicClient Optional public client for preflight checks.
938
+ * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
1011
939
  * @returns receipt, log, zoraURL
1012
940
  */
1013
- async makeMintParameters({
1014
- uid,
1015
- tokenContract,
1016
- minterAccount,
1017
- mintArguments
1018
- }) {
1019
- if (mintArguments && mintArguments?.quantityToMint < 1) {
1020
- throw new Error("Quantity to mint cannot be below 1");
1021
- }
1022
- if (!minterAccount) {
1023
- throw new Error("Wallet not passed in");
1024
- }
1025
- const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
1026
- address: tokenContract,
1027
- uid
941
+ async makeMintParameters(parameters) {
942
+ return await makeMintParameters({
943
+ ...parameters,
944
+ apiClient: this.apiClient,
945
+ publicClient: this.publicClient
1028
946
  });
1029
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1030
- if (premintConfigVersion === PremintConfigVersion2.V3) {
1031
- throw new Error("PremintV3 not supported in premint SDK");
1032
- }
1033
- const value = (await getPremintMintCosts({
1034
- tokenContract,
1035
- quantityToMint: numberToMint,
1036
- publicClient: this.publicClient,
1037
- tokenPrice: premintConfig.tokenConfig.pricePerToken
1038
- })).totalCost;
1039
- const mintArgumentsContract = {
1040
- mintComment: mintArguments?.mintComment || "",
1041
- mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1042
- mintRewardsRecipients: makeMintRewardsRecipient({
1043
- mintReferral: mintArguments?.mintReferral,
1044
- platformReferral: mintArguments?.platformReferral
1045
- })
947
+ }
948
+ };
949
+ function createPremintClient(clientConfig) {
950
+ const { chain, httpClient: httpClient2, publicClient } = setupClient(clientConfig);
951
+ return new PremintClient(chain, publicClient, httpClient2);
952
+ }
953
+ function makePremintReturn({
954
+ premintConfig,
955
+ premintConfigVersion,
956
+ collectionAddress,
957
+ collection,
958
+ publicClient,
959
+ apiClient,
960
+ chainId
961
+ }) {
962
+ const typedDataDefinition = premintTypedDataDefinition2({
963
+ verifyingContract: collectionAddress,
964
+ premintConfig,
965
+ premintConfigVersion,
966
+ chainId
967
+ });
968
+ const signAndSubmit = async ({
969
+ walletClient,
970
+ account,
971
+ checkSignature
972
+ }) => {
973
+ const { signature, signerAccount } = await signPremint({
974
+ account,
975
+ walletClient,
976
+ typedDataDefinition
977
+ });
978
+ await submit({
979
+ signature,
980
+ checkSignature,
981
+ signerAccount
982
+ });
983
+ return {
984
+ signature,
985
+ signerAccount
1046
986
  };
1047
- if (premintConfigVersion === PremintConfigVersion2.V1) {
1048
- return makeSimulateContractParamaters({
1049
- account: minterAccount,
1050
- abi: zoraCreator1155PremintExecutorImplABI2,
1051
- functionName: "premintV1",
1052
- value,
1053
- address: getPremintExecutorAddress(),
1054
- args: [
1055
- collection,
1056
- premintConfig,
1057
- signature,
1058
- numberToMint,
1059
- mintArgumentsContract
1060
- ]
1061
- });
1062
- } else if (premintConfigVersion === PremintConfigVersion2.V2) {
1063
- return makeSimulateContractParamaters({
1064
- account: minterAccount,
1065
- abi: zoraCreator1155PremintExecutorImplABI2,
1066
- functionName: "premintV2",
1067
- value,
1068
- address: getPremintExecutorAddress(),
1069
- args: [
1070
- collection,
1071
- premintConfig,
1072
- signature,
1073
- numberToMint,
1074
- mintArgumentsContract
1075
- ]
987
+ };
988
+ const submit = async ({
989
+ signature,
990
+ checkSignature,
991
+ signerAccount
992
+ }) => {
993
+ if (checkSignature) {
994
+ await validateSignature({
995
+ collection: {
996
+ ...collection,
997
+ additionalAdmins: []
998
+ },
999
+ publicClient,
1000
+ signerAccount
1076
1001
  });
1077
1002
  }
1078
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1003
+ await apiClient.postSignature({
1004
+ collection: {
1005
+ ...collection,
1006
+ additionalAdmins: []
1007
+ },
1008
+ signature,
1009
+ premintConfig,
1010
+ premintConfigVersion
1011
+ });
1012
+ };
1013
+ return {
1014
+ premintConfig,
1015
+ premintConfigVersion,
1016
+ typedDataDefinition,
1017
+ collectionAddress,
1018
+ signAndSubmit,
1019
+ submit
1020
+ };
1021
+ }
1022
+ async function signPremint({
1023
+ account,
1024
+ walletClient,
1025
+ typedDataDefinition
1026
+ }) {
1027
+ if (!account) {
1028
+ account = walletClient.account;
1029
+ }
1030
+ if (!account) {
1031
+ throw new Error("No account provided");
1032
+ }
1033
+ const signature = await walletClient.signTypedData({
1034
+ account,
1035
+ ...typedDataDefinition
1036
+ });
1037
+ return {
1038
+ signature,
1039
+ signerAccount: account
1040
+ };
1041
+ }
1042
+ var validateSignature = async ({
1043
+ collection,
1044
+ publicClient,
1045
+ signerAccount
1046
+ }) => {
1047
+ const isAuthorized = await isAuthorizedToCreatePremint({
1048
+ collection,
1049
+ publicClient,
1050
+ signer: typeof signerAccount === "string" ? signerAccount : signerAccount.address,
1051
+ collectionAddress: await getPremintCollectionAddress({
1052
+ collection,
1053
+ publicClient
1054
+ })
1055
+ });
1056
+ if (!isAuthorized) {
1057
+ throw new Error("Not authorized to create premint");
1079
1058
  }
1080
1059
  };
1081
- function createPremintClient({
1082
- chain,
1083
- httpClient: httpClient2,
1060
+ async function createPremint({
1061
+ payoutRecipient: creatorAccount,
1062
+ collection,
1063
+ tokenCreationConfig,
1064
+ premintConfigVersion,
1065
+ uid,
1066
+ publicClient,
1067
+ apiClient,
1068
+ chainId
1069
+ }) {
1070
+ const {
1071
+ premintConfig,
1072
+ premintConfigVersion: actualVersion,
1073
+ collectionAddress
1074
+ } = await prepareCreatePremintConfig({
1075
+ payoutRecipient: creatorAccount,
1076
+ collection,
1077
+ tokenCreationConfig,
1078
+ premintConfigVersion,
1079
+ uid,
1080
+ publicClient,
1081
+ apiClient,
1082
+ chainId
1083
+ });
1084
+ return makePremintReturn({
1085
+ premintConfig,
1086
+ premintConfigVersion: actualVersion,
1087
+ collectionAddress,
1088
+ collection,
1089
+ publicClient,
1090
+ apiClient,
1091
+ chainId
1092
+ });
1093
+ }
1094
+ async function prepareCreatePremintConfig({
1095
+ payoutRecipient,
1096
+ collection,
1097
+ tokenCreationConfig,
1098
+ premintConfigVersion,
1099
+ uid,
1100
+ publicClient,
1101
+ apiClient,
1102
+ chainId
1103
+ }) {
1104
+ const collectionWithAdditionalAdmins = {
1105
+ ...collection,
1106
+ additionalAdmins: collection.additionalAdmins || []
1107
+ };
1108
+ const newContractAddress = await getPremintCollectionAddress({
1109
+ publicClient,
1110
+ collection: collectionWithAdditionalAdmins
1111
+ });
1112
+ let uidToUse = uid;
1113
+ if (typeof uidToUse !== "number") {
1114
+ uidToUse = await apiClient.getNextUID(newContractAddress);
1115
+ }
1116
+ const actualVersion = premintConfigVersion || PremintConfigVersion2.V1;
1117
+ if (!await supportsPremintVersion({
1118
+ version: actualVersion,
1119
+ publicClient,
1120
+ tokenContract: newContractAddress
1121
+ })) {
1122
+ throw new Error(
1123
+ `Premint version ${actualVersion} not supported by contract`
1124
+ );
1125
+ }
1126
+ const premintConfig = makeNewPremint({
1127
+ tokenConfig: makeTokenConfigWithDefaults({
1128
+ // @ts-ignore
1129
+ premintConfigVersion: actualVersion,
1130
+ tokenCreationConfig,
1131
+ payoutRecipient: typeof payoutRecipient === "string" ? payoutRecipient : payoutRecipient.address,
1132
+ chainId
1133
+ }),
1134
+ uid: uidToUse
1135
+ });
1136
+ return {
1137
+ premintConfig,
1138
+ premintConfigVersion: actualVersion,
1139
+ collectionAddress: newContractAddress
1140
+ };
1141
+ }
1142
+ async function updatePremint({
1143
+ uid,
1144
+ collection,
1145
+ tokenConfigUpdates,
1146
+ apiClient,
1147
+ publicClient,
1148
+ chainId
1149
+ }) {
1150
+ const {
1151
+ premintConfig,
1152
+ collection: collectionCreationConfig,
1153
+ premintConfigVersion
1154
+ } = await apiClient.getSignature({
1155
+ collectionAddress: collection,
1156
+ uid
1157
+ });
1158
+ const updatedPremint = applyUpdateToPremint({
1159
+ uid: premintConfig.uid,
1160
+ version: premintConfig.version,
1161
+ tokenConfig: premintConfig.tokenConfig,
1162
+ tokenConfigUpdates
1163
+ });
1164
+ return makePremintReturn({
1165
+ premintConfig: updatedPremint,
1166
+ premintConfigVersion,
1167
+ collectionAddress: collection,
1168
+ collection: collectionCreationConfig,
1169
+ publicClient,
1170
+ apiClient,
1171
+ chainId
1172
+ });
1173
+ }
1174
+ async function deletePremint({
1175
+ uid,
1176
+ collection,
1177
+ publicClient,
1178
+ apiClient,
1179
+ chainId
1180
+ }) {
1181
+ const {
1182
+ premintConfig,
1183
+ premintConfigVersion,
1184
+ collection: collectionCreationConfig
1185
+ } = await apiClient.getSignature({
1186
+ collectionAddress: collection,
1187
+ uid
1188
+ });
1189
+ const deletedPremint = {
1190
+ ...premintConfig,
1191
+ version: premintConfig.version + 1,
1192
+ deleted: true
1193
+ };
1194
+ return makePremintReturn({
1195
+ premintConfig: deletedPremint,
1196
+ premintConfigVersion,
1197
+ collectionAddress: collection,
1198
+ collection: collectionCreationConfig,
1199
+ publicClient,
1200
+ apiClient,
1201
+ chainId
1202
+ });
1203
+ }
1204
+ async function makeMintParameters({
1205
+ uid,
1206
+ tokenContract,
1207
+ minterAccount,
1208
+ mintArguments,
1209
+ apiClient,
1084
1210
  publicClient
1085
1211
  }) {
1086
- return new PremintClient(chain, publicClient, httpClient2);
1212
+ if (mintArguments && mintArguments?.quantityToMint < 1) {
1213
+ throw new Error("Quantity to mint cannot be below 1");
1214
+ }
1215
+ if (!minterAccount) {
1216
+ throw new Error("Wallet not passed in");
1217
+ }
1218
+ const { premintConfig, premintConfigVersion, collection, signature } = await apiClient.getSignature({
1219
+ collectionAddress: tokenContract,
1220
+ uid
1221
+ });
1222
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1223
+ if (premintConfigVersion === PremintConfigVersion2.V3) {
1224
+ throw new Error("PremintV3 not supported in premint SDK");
1225
+ }
1226
+ const value = (await getPremintMintCosts({
1227
+ tokenContract,
1228
+ quantityToMint: numberToMint,
1229
+ publicClient,
1230
+ tokenPrice: premintConfig.tokenConfig.pricePerToken
1231
+ })).totalCost;
1232
+ const mintArgumentsContract = {
1233
+ mintComment: mintArguments?.mintComment || "",
1234
+ mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1235
+ mintRewardsRecipients: makeMintRewardsRecipient({
1236
+ mintReferral: mintArguments?.mintReferral
1237
+ })
1238
+ };
1239
+ if (premintConfigVersion === PremintConfigVersion2.V1) {
1240
+ return makeSimulateContractParamaters({
1241
+ account: minterAccount,
1242
+ abi: zoraCreator1155PremintExecutorImplABI2,
1243
+ functionName: "premintV1",
1244
+ value,
1245
+ address: getPremintExecutorAddress(),
1246
+ args: [
1247
+ collection,
1248
+ premintConfig,
1249
+ signature,
1250
+ numberToMint,
1251
+ mintArgumentsContract
1252
+ ]
1253
+ });
1254
+ } else if (premintConfigVersion === PremintConfigVersion2.V2) {
1255
+ return makeSimulateContractParamaters({
1256
+ account: minterAccount,
1257
+ abi: zoraCreator1155PremintExecutorImplABI2,
1258
+ functionName: "premintV2",
1259
+ value,
1260
+ address: getPremintExecutorAddress(),
1261
+ args: [
1262
+ collection,
1263
+ premintConfig,
1264
+ signature,
1265
+ numberToMint,
1266
+ mintArgumentsContract
1267
+ ]
1268
+ });
1269
+ }
1270
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1087
1271
  }
1088
1272
  function makeUrls({
1089
1273
  uid,
@@ -1102,52 +1286,6 @@ function makeUrls({
1102
1286
  zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
1103
1287
  };
1104
1288
  }
1105
- async function signAndSubmitPremint({
1106
- walletClient,
1107
- verifyingContract,
1108
- account,
1109
- checkSignature,
1110
- collection,
1111
- chainId,
1112
- publicClient,
1113
- apiClient,
1114
- ...premintConfigAndVersion
1115
- }) {
1116
- if (!account) {
1117
- account = walletClient.account;
1118
- }
1119
- if (!account) {
1120
- throw new Error("No account provided");
1121
- }
1122
- const signature = await walletClient.signTypedData({
1123
- account,
1124
- ...premintTypedDataDefinition2({
1125
- verifyingContract,
1126
- ...premintConfigAndVersion,
1127
- chainId
1128
- })
1129
- });
1130
- if (checkSignature) {
1131
- const isAuthorized = await isAuthorizedToCreatePremint({
1132
- collection,
1133
- publicClient,
1134
- signer: typeof account === "string" ? account : account.address,
1135
- collectionAddress: await getPremintCollectionAddress({
1136
- collection,
1137
- publicClient
1138
- })
1139
- });
1140
- if (!isAuthorized) {
1141
- throw new Error("Not authorized to create premint");
1142
- }
1143
- }
1144
- const premint = await apiClient.postSignature({
1145
- collection,
1146
- signature,
1147
- ...premintConfigAndVersion
1148
- });
1149
- return { premint, verifyingContract };
1150
- }
1151
1289
 
1152
1290
  // src/premint/contract-types.ts
1153
1291
  import { PremintConfigVersion as PremintConfigVersionOrig } from "@zoralabs/protocol-deployments";
@@ -1160,13 +1298,13 @@ var PremintConfigVersion3 = ((PremintConfigVersion4) => {
1160
1298
 
1161
1299
  // src/mint/mint-client.ts
1162
1300
  import {
1163
- createPublicClient as createPublicClient2,
1164
1301
  encodeAbiParameters,
1165
1302
  parseAbiParameters,
1166
- zeroAddress as zeroAddress3,
1167
- http as http2
1303
+ zeroAddress as zeroAddress3
1168
1304
  } from "viem";
1169
1305
  import {
1306
+ erc20MinterABI,
1307
+ erc20MinterAddress,
1170
1308
  zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
1171
1309
  zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
1172
1310
  } from "@zoralabs/protocol-deployments";
@@ -1181,30 +1319,24 @@ var Errors = {
1181
1319
  var MintClient = class {
1182
1320
  constructor(chain, publicClient, httpClient2) {
1183
1321
  this.apiClient = new MintAPIClient(chain.id, httpClient2);
1184
- this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
1322
+ this.publicClient = publicClient;
1185
1323
  }
1186
1324
  /**
1187
1325
  * Returns the parameters needed to prepare a transaction mint a token.
1188
- * @param param0.minterAccount The account that will mint the token.
1189
- * @param param0.mintable The mintable token to mint.
1190
- * @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
1191
- * @returns
1326
+ *
1327
+ * @param parameters - Parameters for collecting the token {@link MintTokenParams}
1328
+ * @returns Parameters for simulating/executing the mint transaction
1192
1329
  */
1193
- async makePrepareMintTokenParams({
1194
- ...rest
1195
- }) {
1330
+ async makePrepareMintTokenParams(parameters) {
1196
1331
  return makePrepareMintTokenParams({
1197
- ...rest,
1332
+ ...parameters,
1198
1333
  apiClient: this.apiClient,
1199
1334
  publicClient: this.publicClient
1200
1335
  });
1201
1336
  }
1202
1337
  };
1203
- function createMintClient({
1204
- chain,
1205
- publicClient,
1206
- httpClient: httpClient2
1207
- }) {
1338
+ function createMintClient(clientConfig) {
1339
+ const { chain, publicClient, httpClient: httpClient2 } = setupClient(clientConfig);
1208
1340
  return new MintClient(chain, publicClient, httpClient2);
1209
1341
  }
1210
1342
  async function makePrepareMintTokenParams({
@@ -1212,16 +1344,19 @@ async function makePrepareMintTokenParams({
1212
1344
  apiClient,
1213
1345
  tokenId,
1214
1346
  tokenAddress,
1347
+ mintArguments,
1215
1348
  ...rest
1216
1349
  }) {
1217
1350
  const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
1218
1351
  tokenId,
1219
- tokenAddress
1352
+ tokenAddress,
1353
+ saleType: mintArguments.saleType
1220
1354
  });
1221
1355
  if (tokenId === void 0) {
1222
1356
  return makePrepareMint721TokenParams({
1223
1357
  salesConfigAndTokenInfo,
1224
1358
  tokenAddress,
1359
+ mintArguments,
1225
1360
  ...rest
1226
1361
  });
1227
1362
  }
@@ -1229,6 +1364,7 @@ async function makePrepareMintTokenParams({
1229
1364
  salesConfigAndTokenInfo,
1230
1365
  tokenAddress,
1231
1366
  tokenId,
1367
+ mintArguments,
1232
1368
  ...rest
1233
1369
  });
1234
1370
  }
@@ -1261,7 +1397,7 @@ function getMintCosts({
1261
1397
  quantityToMint
1262
1398
  }) {
1263
1399
  const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
1264
- const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
1400
+ const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
1265
1401
  return {
1266
1402
  mintFee: mintFeeForTokens,
1267
1403
  tokenPurchaseCost,
@@ -1280,24 +1416,49 @@ async function makePrepareMint1155TokenParams({
1280
1416
  salesConfigAndTokenInfo,
1281
1417
  quantityToMint: mintQuantity
1282
1418
  }).totalCost;
1283
- return makeSimulateContractParamaters({
1284
- abi: zoraCreator1155ImplABI2,
1285
- functionName: "mintWithRewards",
1286
- account: minterAccount,
1287
- value: mintValue,
1288
- address: tokenAddress,
1289
- /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1290
- args: [
1291
- salesConfigAndTokenInfo?.fixedPrice.address || zoraCreatorFixedPriceSaleStrategyAddress2[999],
1292
- BigInt(tokenId),
1293
- mintQuantity,
1294
- encodeAbiParameters(parseAbiParameters("address, string"), [
1295
- mintArguments.mintToAddress,
1296
- mintArguments.mintComment || ""
1297
- ]),
1298
- mintArguments.mintReferral || zeroAddress3
1299
- ]
1300
- });
1419
+ switch (salesConfigAndTokenInfo.salesConfig.saleType) {
1420
+ case "fixedPrice":
1421
+ const fixedPriceArgs = mintArguments;
1422
+ return makeSimulateContractParamaters({
1423
+ abi: zoraCreator1155ImplABI2,
1424
+ functionName: "mintWithRewards",
1425
+ account: minterAccount,
1426
+ value: mintValue,
1427
+ address: tokenAddress,
1428
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1429
+ args: [
1430
+ salesConfigAndTokenInfo.salesConfig.address || zoraCreatorFixedPriceSaleStrategyAddress2[999999999],
1431
+ BigInt(tokenId),
1432
+ mintQuantity,
1433
+ encodeAbiParameters(parseAbiParameters("address, string"), [
1434
+ fixedPriceArgs.mintToAddress,
1435
+ fixedPriceArgs.mintComment || ""
1436
+ ]),
1437
+ fixedPriceArgs.mintReferral || zeroAddress3
1438
+ ]
1439
+ });
1440
+ case "erc20":
1441
+ const erc20Args = mintArguments;
1442
+ return makeSimulateContractParamaters({
1443
+ abi: erc20MinterABI,
1444
+ functionName: "mint",
1445
+ account: minterAccount,
1446
+ address: salesConfigAndTokenInfo?.salesConfig.address || erc20MinterAddress[999999999],
1447
+ /* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
1448
+ args: [
1449
+ mintArguments.mintToAddress,
1450
+ mintQuantity,
1451
+ tokenAddress,
1452
+ BigInt(tokenId),
1453
+ salesConfigAndTokenInfo.salesConfig.pricePerToken,
1454
+ salesConfigAndTokenInfo.salesConfig.currency,
1455
+ erc20Args.mintReferral || zeroAddress3,
1456
+ erc20Args.mintComment || ""
1457
+ ]
1458
+ });
1459
+ default:
1460
+ throw new MintError("Unsupported sale type");
1461
+ }
1301
1462
  }
1302
1463
 
1303
1464
  // src/create/1155-create-helper.ts
@@ -1457,9 +1618,8 @@ async function getContractExists(publicClient, contract, account) {
1457
1618
  contractAddress: contract
1458
1619
  };
1459
1620
  }
1460
- function create1155CreatorClient({
1461
- publicClient
1462
- }) {
1621
+ function create1155CreatorClient(clientConfig) {
1622
+ const { publicClient } = setupClient(clientConfig);
1463
1623
  async function createNew1155Token({
1464
1624
  contract,
1465
1625
  tokenMetadataURI,
@@ -1928,6 +2088,7 @@ export {
1928
2088
  makePermitToCollectPremintOrNonPremint,
1929
2089
  makePermitTransferBatchAndTypeData,
1930
2090
  makePermitTransferTypeData,
2091
+ makeUrls,
1931
2092
  migratePremintConfigToV2,
1932
2093
  mintWithEthParams,
1933
2094
  mintsBalanceOfAccountParams,