@zoralabs/protocol-sdk 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -22,14 +22,16 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  DEFAULT_SALE_SETTINGS: () => DEFAULT_SALE_SETTINGS,
24
24
  DefaultMintArguments: () => DefaultMintArguments,
25
+ Errors: () => Errors,
25
26
  MintAPIClient: () => MintAPIClient,
26
27
  PremintAPIClient: () => PremintAPIClient,
27
- PremintClient: () => PremintClient,
28
28
  ZORA_API_BASE: () => ZORA_API_BASE,
29
29
  convertCollection: () => convertCollection,
30
30
  convertPremint: () => convertPremint,
31
+ create1155CreatorClient: () => create1155CreatorClient,
31
32
  create1155TokenSetupArgs: () => create1155TokenSetupArgs,
32
- createNew1155Token: () => createNew1155Token,
33
+ createMintClient: () => createMintClient,
34
+ createPremintClient: () => createPremintClient,
33
35
  encodePremintForAPI: () => encodePremintForAPI,
34
36
  getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
35
37
  getSalesConfigFixedPrice: () => getSalesConfigFixedPrice,
@@ -381,6 +383,16 @@ var PremintClient = class extends ClientBase {
381
383
  getFixedPriceMinterAddress() {
382
384
  return import_protocol_deployments.zoraCreatorFixedPriceSaleStrategyAddress[999];
383
385
  }
386
+ getDataFromPremintReceipt(receipt) {
387
+ const premintedLog = getPremintedLogFromReceipt(receipt);
388
+ return {
389
+ premintedLog,
390
+ urls: this.makeUrls({
391
+ address: premintedLog?.contractAddress,
392
+ tokenId: premintedLog?.tokenId
393
+ })
394
+ };
395
+ }
384
396
  /**
385
397
  * Update existing premint given collection address and UID of existing premint.
386
398
  *
@@ -669,14 +681,11 @@ var PremintClient = class extends ClientBase {
669
681
  * @param settings.publicClient Optional public client for preflight checks.
670
682
  * @returns receipt, log, zoraURL
671
683
  */
672
- async executePremintWithWallet({
684
+ async executePremint({
673
685
  data,
674
686
  account,
675
- walletClient,
676
- mintArguments,
677
- publicClient
687
+ mintArguments
678
688
  }) {
679
- publicClient = this.getPublicClient(publicClient);
680
689
  if (mintArguments && mintArguments?.quantityToMint < 1) {
681
690
  throw new Error("Quantity to mint cannot be below 1");
682
691
  }
@@ -689,34 +698,29 @@ var PremintClient = class extends ClientBase {
689
698
  numberToMint,
690
699
  mintArguments?.mintComment || ""
691
700
  ];
692
- if (!account) {
693
- account = walletClient.account;
694
- }
695
701
  if (!account) {
696
702
  throw new Error("Wallet not passed in");
697
703
  }
698
704
  const value = numberToMint * REWARD_PER_TOKEN;
699
- const { request } = await publicClient.simulateContract({
705
+ const request = {
700
706
  account,
701
707
  abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
702
708
  functionName: "premint",
703
709
  value,
704
710
  address: targetAddress,
705
711
  args
706
- });
707
- const hash = await walletClient.writeContract(request);
708
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
709
- const premintedLog = getPremintedLogFromReceipt(receipt);
712
+ };
710
713
  return {
711
- receipt,
712
- premintedLog,
713
- urls: this.makeUrls({
714
- address: premintedLog?.contractAddress,
715
- tokenId: premintedLog?.tokenId
716
- })
714
+ request
717
715
  };
718
716
  }
719
717
  };
718
+ function createPremintClient({
719
+ chain,
720
+ premintAPIClient
721
+ }) {
722
+ return new PremintClient(chain, premintAPIClient);
723
+ }
720
724
 
721
725
  // src/mint/mint-api-client.ts
722
726
  function encodeQueryParameters(params) {
@@ -743,13 +747,169 @@ var MintAPIClient = {
743
747
  getSalesConfigFixedPrice
744
748
  };
745
749
 
746
- // src/create/1155-create-helper.ts
747
- var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
750
+ // src/mint/mint-client.ts
748
751
  var import_viem4 = require("viem");
752
+ var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
753
+ var MintError = class extends Error {
754
+ };
755
+ var MintInactiveError = class extends Error {
756
+ };
757
+ var Errors = {
758
+ MintError,
759
+ MintInactiveError
760
+ };
761
+ var zora721Abi = (0, import_viem4.parseAbi)([
762
+ "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
763
+ "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
764
+ ]);
765
+ var MintClient = class extends ClientBase {
766
+ constructor(chain, apiClient) {
767
+ super(chain);
768
+ if (!apiClient) {
769
+ apiClient = MintAPIClient;
770
+ }
771
+ this.apiClient = apiClient;
772
+ }
773
+ async getMintable({
774
+ tokenContract,
775
+ tokenId
776
+ }) {
777
+ return this.apiClient.getMintable(
778
+ {
779
+ chain_name: this.network.zoraBackendChainName,
780
+ collection_address: tokenContract
781
+ },
782
+ { token_id: tokenId?.toString() }
783
+ );
784
+ }
785
+ async makePrepareMintTokenParams({
786
+ publicClient,
787
+ minterAccount,
788
+ mintable,
789
+ mintArguments
790
+ }) {
791
+ if (!mintable) {
792
+ throw new MintError("No mintable found");
793
+ }
794
+ if (!mintable.is_active) {
795
+ throw new MintInactiveError("Minting token is inactive");
796
+ }
797
+ if (!mintable.mint_context) {
798
+ throw new MintError("No minting context data from zora API");
799
+ }
800
+ if (!["zora_create", "zora_create_1155"].includes(
801
+ mintable.mint_context?.mint_context_type
802
+ )) {
803
+ throw new MintError(
804
+ `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
805
+ );
806
+ }
807
+ const thisPublicClient = this.getPublicClient(publicClient);
808
+ if (mintable.mint_context.mint_context_type === "zora_create_1155") {
809
+ return {
810
+ simulateContractParameters: await this.prepareMintZora1155({
811
+ publicClient: thisPublicClient,
812
+ mintArguments,
813
+ sender: minterAccount,
814
+ mintable
815
+ })
816
+ };
817
+ }
818
+ if (mintable.mint_context.mint_context_type === "zora_create") {
819
+ return {
820
+ simulateContractParameters: await this.prepareMintZora721({
821
+ publicClient: thisPublicClient,
822
+ mintArguments,
823
+ sender: minterAccount,
824
+ mintable
825
+ })
826
+ };
827
+ }
828
+ throw new Error("Mintable type not found or recognized.");
829
+ }
830
+ async prepareMintZora1155({
831
+ mintable,
832
+ sender,
833
+ publicClient,
834
+ mintArguments
835
+ }) {
836
+ const mintQuantity = BigInt(mintArguments.quantityToMint);
837
+ const address = mintable.collection.address;
838
+ const mintFee = await publicClient.readContract({
839
+ abi: import_protocol_deployments2.zoraCreator1155ImplABI,
840
+ functionName: "mintFee",
841
+ address
842
+ });
843
+ const tokenFixedPriceMinter = await this.apiClient.getSalesConfigFixedPrice(
844
+ {
845
+ contractAddress: mintable.contract_address,
846
+ tokenId: mintable.token_id,
847
+ subgraphUrl: this.network.subgraphUrl
848
+ }
849
+ );
850
+ const result = {
851
+ abi: import_protocol_deployments2.zoraCreator1155ImplABI,
852
+ functionName: "mintWithRewards",
853
+ account: sender,
854
+ value: (mintFee + BigInt(mintable.cost.native_price.raw)) * mintQuantity,
855
+ address,
856
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
857
+ args: [
858
+ tokenFixedPriceMinter || import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999],
859
+ BigInt(mintable.token_id),
860
+ mintQuantity,
861
+ (0, import_viem4.encodeAbiParameters)((0, import_viem4.parseAbiParameters)("address, string"), [
862
+ mintArguments.mintToAddress,
863
+ mintArguments.mintComment || ""
864
+ ]),
865
+ mintArguments.mintReferral || import_viem4.zeroAddress
866
+ ]
867
+ };
868
+ return result;
869
+ }
870
+ async prepareMintZora721({
871
+ mintable,
872
+ publicClient,
873
+ sender,
874
+ mintArguments
875
+ }) {
876
+ const [_, mintFee] = await publicClient.readContract({
877
+ abi: zora721Abi,
878
+ address: mintable.contract_address,
879
+ functionName: "zoraFeeForAmount",
880
+ args: [BigInt(mintArguments.quantityToMint)]
881
+ });
882
+ const result = {
883
+ abi: zora721Abi,
884
+ address: mintable.contract_address,
885
+ account: sender,
886
+ functionName: "mintWithRewards",
887
+ value: mintFee + BigInt(mintable.cost.native_price.raw) * BigInt(mintArguments.quantityToMint),
888
+ /* args: mint recipient, quantity to mint, mint comment, mintReferral */
889
+ args: [
890
+ mintArguments.mintToAddress,
891
+ BigInt(mintArguments.quantityToMint),
892
+ mintArguments.mintComment || "",
893
+ mintArguments.mintReferral || import_viem4.zeroAddress
894
+ ]
895
+ };
896
+ return result;
897
+ }
898
+ };
899
+ function createMintClient({
900
+ chain,
901
+ mintAPIClient
902
+ }) {
903
+ return new MintClient(chain, mintAPIClient);
904
+ }
905
+
906
+ // src/create/1155-create-helper.ts
907
+ var import_protocol_deployments3 = require("@zoralabs/protocol-deployments");
908
+ var import_viem5 = require("viem");
749
909
  var SALE_END_FOREVER = 18446744073709551615n;
750
910
  var ROYALTY_BPS_DEFAULT = 1e3;
751
911
  var DEFAULT_SALE_SETTINGS = {
752
- fundsRecipient: import_viem4.zeroAddress,
912
+ fundsRecipient: import_viem5.zeroAddress,
753
913
  // Free Mint
754
914
  pricePerToken: 0n,
755
915
  // Sale start time – defaults to beginning of unix time
@@ -788,33 +948,33 @@ function create1155TokenSetupArgs({
788
948
  ...salesConfig
789
949
  };
790
950
  const setupActions = [
791
- (0, import_viem4.encodeFunctionData)({
792
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
793
- functionName: "addPermission",
794
- args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
795
- }),
796
- (0, import_viem4.encodeFunctionData)({
797
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
951
+ (0, import_viem5.encodeFunctionData)({
952
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
798
953
  functionName: "assumeLastTokenIdMatches",
799
954
  args: [nextTokenId - 1n]
800
955
  }),
801
- createReferral ? (0, import_viem4.encodeFunctionData)({
802
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
956
+ createReferral ? (0, import_viem5.encodeFunctionData)({
957
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
803
958
  functionName: "setupNewTokenWithCreateReferral",
804
959
  args: [tokenMetadataURI, maxSupply, createReferral]
805
- }) : (0, import_viem4.encodeFunctionData)({
806
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
960
+ }) : (0, import_viem5.encodeFunctionData)({
961
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
807
962
  functionName: "setupNewToken",
808
963
  args: [tokenMetadataURI, maxSupply]
809
964
  }),
810
- (0, import_viem4.encodeFunctionData)({
811
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
965
+ (0, import_viem5.encodeFunctionData)({
966
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
967
+ functionName: "addPermission",
968
+ args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
969
+ }),
970
+ (0, import_viem5.encodeFunctionData)({
971
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
812
972
  functionName: "callSale",
813
973
  args: [
814
974
  nextTokenId,
815
975
  fixedPriceMinterAddress,
816
- (0, import_viem4.encodeFunctionData)({
817
- abi: import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyABI,
976
+ (0, import_viem5.encodeFunctionData)({
977
+ abi: import_protocol_deployments3.zoraCreatorFixedPriceSaleStrategyABI,
818
978
  functionName: "setSale",
819
979
  args: [nextTokenId, salesConfigWithDefaults]
820
980
  })
@@ -823,8 +983,8 @@ function create1155TokenSetupArgs({
823
983
  ];
824
984
  if (mintToCreatorCount) {
825
985
  setupActions.push(
826
- (0, import_viem4.encodeFunctionData)({
827
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
986
+ (0, import_viem5.encodeFunctionData)({
987
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
828
988
  functionName: "adminMint",
829
989
  args: [account, nextTokenId, mintToCreatorCount, "0x"]
830
990
  })
@@ -832,8 +992,8 @@ function create1155TokenSetupArgs({
832
992
  }
833
993
  if (royaltySettings) {
834
994
  setupActions.push(
835
- (0, import_viem4.encodeFunctionData)({
836
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
995
+ (0, import_viem5.encodeFunctionData)({
996
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
837
997
  functionName: "updateRoyaltiesForToken",
838
998
  args: [
839
999
  nextTokenId,
@@ -851,8 +1011,8 @@ function create1155TokenSetupArgs({
851
1011
  var getTokenIdFromCreateReceipt = (receipt) => {
852
1012
  for (const data of receipt.logs) {
853
1013
  try {
854
- const decodedLog = (0, import_viem4.decodeEventLog)({
855
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
1014
+ const decodedLog = (0, import_viem5.decodeEventLog)({
1015
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
856
1016
  eventName: "SetupNewToken",
857
1017
  ...data
858
1018
  });
@@ -868,9 +1028,9 @@ async function getContractExists(publicClient, contract, account) {
868
1028
  let contractExists = false;
869
1029
  if (typeof contract !== "string") {
870
1030
  contractAddress = await publicClient.readContract({
871
- abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
1031
+ abi: import_protocol_deployments3.zoraCreator1155FactoryImplABI,
872
1032
  // Since this address is deterministic we can hardcode a chain id safely here.
873
- address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
1033
+ address: import_protocol_deployments3.zoraCreator1155FactoryImplAddress[999],
874
1034
  functionName: "deterministicContractAddress",
875
1035
  args: [
876
1036
  account,
@@ -881,7 +1041,7 @@ async function getContractExists(publicClient, contract, account) {
881
1041
  });
882
1042
  try {
883
1043
  await publicClient.readContract({
884
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
1044
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
885
1045
  address: contractAddress,
886
1046
  functionName: "contractVersion"
887
1047
  });
@@ -895,108 +1055,114 @@ async function getContractExists(publicClient, contract, account) {
895
1055
  contractAddress: contract
896
1056
  };
897
1057
  }
898
- async function createNew1155Token({
899
- publicClient,
900
- contract,
901
- tokenMetadataURI,
902
- mintToCreatorCount = 1,
903
- salesConfig = {},
904
- maxSupply,
905
- account,
906
- royaltySettings,
907
- getAdditionalSetupActions
1058
+ function create1155CreatorClient({
1059
+ publicClient
908
1060
  }) {
909
- const { contractExists, contractAddress } = await getContractExists(
910
- publicClient,
1061
+ async function createNew1155Token({
911
1062
  contract,
912
- account
913
- );
914
- let nextTokenId = 1n;
915
- if (contractExists) {
916
- nextTokenId = await publicClient.readContract({
917
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
918
- functionName: "nextTokenId",
919
- address: contractAddress
920
- });
921
- }
922
- const fixedPriceMinterAddress = await publicClient.readContract({
923
- abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
924
- address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
925
- functionName: "fixedPriceMinter"
926
- });
927
- let tokenSetupActions = create1155TokenSetupArgs({
928
1063
  tokenMetadataURI,
929
- nextTokenId,
930
- salesConfig,
1064
+ mintToCreatorCount = 1,
1065
+ salesConfig = {},
931
1066
  maxSupply,
932
- fixedPriceMinterAddress,
933
1067
  account,
934
- mintToCreatorCount,
935
- royaltySettings
936
- });
937
- if (getAdditionalSetupActions) {
938
- tokenSetupActions = [
939
- ...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
940
- ...tokenSetupActions
941
- ];
942
- }
943
- if (!contractAddress && typeof contract === "string") {
944
- throw new Error("Invariant: contract cannot be missing and an address");
945
- }
946
- if (!contractExists && typeof contract !== "string") {
947
- const { request } = await publicClient.simulateContract({
948
- abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
949
- functionName: "createContractDeterministic",
950
- account,
951
- address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
952
- args: [
953
- contract.uri,
954
- contract.name,
955
- {
956
- // deprecated
957
- royaltyMintSchedule: 0,
958
- royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
959
- royaltyRecipient: royaltySettings?.royaltyRecipient || account
960
- },
961
- contract.defaultAdmin || account,
962
- tokenSetupActions
963
- ]
1068
+ royaltySettings,
1069
+ getAdditionalSetupActions
1070
+ }) {
1071
+ const { contractExists, contractAddress } = await getContractExists(
1072
+ publicClient,
1073
+ contract,
1074
+ account
1075
+ );
1076
+ let nextTokenId = 1n;
1077
+ if (contractExists) {
1078
+ nextTokenId = await publicClient.readContract({
1079
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
1080
+ functionName: "nextTokenId",
1081
+ address: contractAddress
1082
+ });
1083
+ }
1084
+ const fixedPriceMinterAddress = await publicClient.readContract({
1085
+ abi: import_protocol_deployments3.zoraCreator1155FactoryImplABI,
1086
+ address: import_protocol_deployments3.zoraCreator1155FactoryImplAddress[999],
1087
+ functionName: "fixedPriceMinter"
964
1088
  });
965
- return {
966
- send: (walletClient) => walletClient.writeContract(request),
967
- tokenSetupActions,
968
- contractAddress,
969
- contractExists
970
- };
971
- } else if (contractExists) {
972
- const { request } = await publicClient.simulateContract({
973
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
974
- functionName: "multicall",
1089
+ let tokenSetupActions = create1155TokenSetupArgs({
1090
+ tokenMetadataURI,
1091
+ nextTokenId,
1092
+ salesConfig,
1093
+ maxSupply,
1094
+ fixedPriceMinterAddress,
975
1095
  account,
976
- address: contractAddress,
977
- args: [tokenSetupActions]
1096
+ mintToCreatorCount,
1097
+ royaltySettings
978
1098
  });
979
- return {
980
- send: (walletClient) => walletClient.writeContract(request),
981
- tokenSetupActions,
982
- contractAddress,
983
- contractExists
984
- };
1099
+ if (getAdditionalSetupActions) {
1100
+ tokenSetupActions = [
1101
+ ...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
1102
+ ...tokenSetupActions
1103
+ ];
1104
+ }
1105
+ if (!contractAddress && typeof contract === "string") {
1106
+ throw new Error("Invariant: contract cannot be missing and an address");
1107
+ }
1108
+ if (!contractExists && typeof contract !== "string") {
1109
+ const request = {
1110
+ abi: import_protocol_deployments3.zoraCreator1155FactoryImplABI,
1111
+ functionName: "createContractDeterministic",
1112
+ account,
1113
+ address: import_protocol_deployments3.zoraCreator1155FactoryImplAddress[999],
1114
+ args: [
1115
+ contract.uri,
1116
+ contract.name,
1117
+ {
1118
+ // deprecated
1119
+ royaltyMintSchedule: 0,
1120
+ royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1121
+ royaltyRecipient: royaltySettings?.royaltyRecipient || account
1122
+ },
1123
+ contract.defaultAdmin || account,
1124
+ tokenSetupActions
1125
+ ]
1126
+ };
1127
+ return {
1128
+ request,
1129
+ tokenSetupActions,
1130
+ contractAddress,
1131
+ contractExists
1132
+ };
1133
+ } else if (contractExists) {
1134
+ const request = {
1135
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
1136
+ functionName: "multicall",
1137
+ account,
1138
+ address: contractAddress,
1139
+ args: [tokenSetupActions]
1140
+ };
1141
+ return {
1142
+ request,
1143
+ tokenSetupActions,
1144
+ contractAddress,
1145
+ contractExists
1146
+ };
1147
+ }
1148
+ throw new Error("Unsupported contract argument type");
985
1149
  }
986
- throw new Error("Unsupported contract argument type");
1150
+ return { createNew1155Token };
987
1151
  }
988
1152
  // Annotate the CommonJS export names for ESM import in node:
989
1153
  0 && (module.exports = {
990
1154
  DEFAULT_SALE_SETTINGS,
991
1155
  DefaultMintArguments,
1156
+ Errors,
992
1157
  MintAPIClient,
993
1158
  PremintAPIClient,
994
- PremintClient,
995
1159
  ZORA_API_BASE,
996
1160
  convertCollection,
997
1161
  convertPremint,
1162
+ create1155CreatorClient,
998
1163
  create1155TokenSetupArgs,
999
- createNew1155Token,
1164
+ createMintClient,
1165
+ createPremintClient,
1000
1166
  encodePremintForAPI,
1001
1167
  getPremintedLogFromReceipt,
1002
1168
  getSalesConfigFixedPrice,