@zoralabs/protocol-sdk 0.3.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.
@@ -7,9 +7,9 @@ $ tsup
7
7
  CLI Cleaning output folder
8
8
  CJS Build start
9
9
  ESM Build start
10
- ESM dist/index.js 28.56 KB
11
- ESM dist/index.js.map 56.44 KB
12
- ESM ⚡️ Build success in 23ms
13
- CJS dist/index.cjs 31.12 KB
14
- CJS dist/index.cjs.map 56.67 KB
15
- CJS ⚡️ Build success in 24ms
10
+ CJS dist/index.cjs 35.89 KB
11
+ CJS dist/index.cjs.map 65.52 KB
12
+ CJS ⚡️ Build success in 25ms
13
+ ESM dist/index.js 33.30 KB
14
+ ESM dist/index.js.map 65.40 KB
15
+ ESM ⚡️ Build success in 24ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @zoralabs/protocol-sdk
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 92da3ed: Exporting mint client
8
+ - Updated dependencies [293e2c0]
9
+ - @zoralabs/protocol-deployments@0.0.5
10
+
3
11
  ## 0.3.0
4
12
 
5
13
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ 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
28
  ZORA_API_BASE: () => ZORA_API_BASE,
@@ -29,6 +30,7 @@ __export(src_exports, {
29
30
  convertPremint: () => convertPremint,
30
31
  create1155CreatorClient: () => create1155CreatorClient,
31
32
  create1155TokenSetupArgs: () => create1155TokenSetupArgs,
33
+ createMintClient: () => createMintClient,
32
34
  createPremintClient: () => createPremintClient,
33
35
  encodePremintForAPI: () => encodePremintForAPI,
34
36
  getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
@@ -745,13 +747,169 @@ var MintAPIClient = {
745
747
  getSalesConfigFixedPrice
746
748
  };
747
749
 
748
- // src/create/1155-create-helper.ts
749
- var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
750
+ // src/mint/mint-client.ts
750
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");
751
909
  var SALE_END_FOREVER = 18446744073709551615n;
752
910
  var ROYALTY_BPS_DEFAULT = 1e3;
753
911
  var DEFAULT_SALE_SETTINGS = {
754
- fundsRecipient: import_viem4.zeroAddress,
912
+ fundsRecipient: import_viem5.zeroAddress,
755
913
  // Free Mint
756
914
  pricePerToken: 0n,
757
915
  // Sale start time – defaults to beginning of unix time
@@ -790,33 +948,33 @@ function create1155TokenSetupArgs({
790
948
  ...salesConfig
791
949
  };
792
950
  const setupActions = [
793
- (0, import_viem4.encodeFunctionData)({
794
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
951
+ (0, import_viem5.encodeFunctionData)({
952
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
795
953
  functionName: "assumeLastTokenIdMatches",
796
954
  args: [nextTokenId - 1n]
797
955
  }),
798
- createReferral ? (0, import_viem4.encodeFunctionData)({
799
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
956
+ createReferral ? (0, import_viem5.encodeFunctionData)({
957
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
800
958
  functionName: "setupNewTokenWithCreateReferral",
801
959
  args: [tokenMetadataURI, maxSupply, createReferral]
802
- }) : (0, import_viem4.encodeFunctionData)({
803
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
960
+ }) : (0, import_viem5.encodeFunctionData)({
961
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
804
962
  functionName: "setupNewToken",
805
963
  args: [tokenMetadataURI, maxSupply]
806
964
  }),
807
- (0, import_viem4.encodeFunctionData)({
808
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
965
+ (0, import_viem5.encodeFunctionData)({
966
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
809
967
  functionName: "addPermission",
810
968
  args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
811
969
  }),
812
- (0, import_viem4.encodeFunctionData)({
813
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
970
+ (0, import_viem5.encodeFunctionData)({
971
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
814
972
  functionName: "callSale",
815
973
  args: [
816
974
  nextTokenId,
817
975
  fixedPriceMinterAddress,
818
- (0, import_viem4.encodeFunctionData)({
819
- abi: import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyABI,
976
+ (0, import_viem5.encodeFunctionData)({
977
+ abi: import_protocol_deployments3.zoraCreatorFixedPriceSaleStrategyABI,
820
978
  functionName: "setSale",
821
979
  args: [nextTokenId, salesConfigWithDefaults]
822
980
  })
@@ -825,8 +983,8 @@ function create1155TokenSetupArgs({
825
983
  ];
826
984
  if (mintToCreatorCount) {
827
985
  setupActions.push(
828
- (0, import_viem4.encodeFunctionData)({
829
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
986
+ (0, import_viem5.encodeFunctionData)({
987
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
830
988
  functionName: "adminMint",
831
989
  args: [account, nextTokenId, mintToCreatorCount, "0x"]
832
990
  })
@@ -834,8 +992,8 @@ function create1155TokenSetupArgs({
834
992
  }
835
993
  if (royaltySettings) {
836
994
  setupActions.push(
837
- (0, import_viem4.encodeFunctionData)({
838
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
995
+ (0, import_viem5.encodeFunctionData)({
996
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
839
997
  functionName: "updateRoyaltiesForToken",
840
998
  args: [
841
999
  nextTokenId,
@@ -853,8 +1011,8 @@ function create1155TokenSetupArgs({
853
1011
  var getTokenIdFromCreateReceipt = (receipt) => {
854
1012
  for (const data of receipt.logs) {
855
1013
  try {
856
- const decodedLog = (0, import_viem4.decodeEventLog)({
857
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
1014
+ const decodedLog = (0, import_viem5.decodeEventLog)({
1015
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
858
1016
  eventName: "SetupNewToken",
859
1017
  ...data
860
1018
  });
@@ -870,9 +1028,9 @@ async function getContractExists(publicClient, contract, account) {
870
1028
  let contractExists = false;
871
1029
  if (typeof contract !== "string") {
872
1030
  contractAddress = await publicClient.readContract({
873
- abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
1031
+ abi: import_protocol_deployments3.zoraCreator1155FactoryImplABI,
874
1032
  // Since this address is deterministic we can hardcode a chain id safely here.
875
- address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
1033
+ address: import_protocol_deployments3.zoraCreator1155FactoryImplAddress[999],
876
1034
  functionName: "deterministicContractAddress",
877
1035
  args: [
878
1036
  account,
@@ -883,7 +1041,7 @@ async function getContractExists(publicClient, contract, account) {
883
1041
  });
884
1042
  try {
885
1043
  await publicClient.readContract({
886
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
1044
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
887
1045
  address: contractAddress,
888
1046
  functionName: "contractVersion"
889
1047
  });
@@ -918,14 +1076,14 @@ function create1155CreatorClient({
918
1076
  let nextTokenId = 1n;
919
1077
  if (contractExists) {
920
1078
  nextTokenId = await publicClient.readContract({
921
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
1079
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
922
1080
  functionName: "nextTokenId",
923
1081
  address: contractAddress
924
1082
  });
925
1083
  }
926
1084
  const fixedPriceMinterAddress = await publicClient.readContract({
927
- abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
928
- address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
1085
+ abi: import_protocol_deployments3.zoraCreator1155FactoryImplABI,
1086
+ address: import_protocol_deployments3.zoraCreator1155FactoryImplAddress[999],
929
1087
  functionName: "fixedPriceMinter"
930
1088
  });
931
1089
  let tokenSetupActions = create1155TokenSetupArgs({
@@ -949,10 +1107,10 @@ function create1155CreatorClient({
949
1107
  }
950
1108
  if (!contractExists && typeof contract !== "string") {
951
1109
  const request = {
952
- abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
1110
+ abi: import_protocol_deployments3.zoraCreator1155FactoryImplABI,
953
1111
  functionName: "createContractDeterministic",
954
1112
  account,
955
- address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
1113
+ address: import_protocol_deployments3.zoraCreator1155FactoryImplAddress[999],
956
1114
  args: [
957
1115
  contract.uri,
958
1116
  contract.name,
@@ -974,7 +1132,7 @@ function create1155CreatorClient({
974
1132
  };
975
1133
  } else if (contractExists) {
976
1134
  const request = {
977
- abi: import_protocol_deployments2.zoraCreator1155ImplABI,
1135
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
978
1136
  functionName: "multicall",
979
1137
  account,
980
1138
  address: contractAddress,
@@ -995,6 +1153,7 @@ function create1155CreatorClient({
995
1153
  0 && (module.exports = {
996
1154
  DEFAULT_SALE_SETTINGS,
997
1155
  DefaultMintArguments,
1156
+ Errors,
998
1157
  MintAPIClient,
999
1158
  PremintAPIClient,
1000
1159
  ZORA_API_BASE,
@@ -1002,6 +1161,7 @@ function create1155CreatorClient({
1002
1161
  convertPremint,
1003
1162
  create1155CreatorClient,
1004
1163
  create1155TokenSetupArgs,
1164
+ createMintClient,
1005
1165
  createPremintClient,
1006
1166
  encodePremintForAPI,
1007
1167
  getPremintedLogFromReceipt,