@zoralabs/protocol-sdk 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -49,6 +49,41 @@ var zora721Abi = parseAbi([
49
49
  "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
50
50
  "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
51
51
  ]);
52
+ var zora1155LegacyAbi = [
53
+ {
54
+ type: "function",
55
+ name: "mintWithRewards",
56
+ inputs: [
57
+ {
58
+ name: "minter",
59
+ type: "address",
60
+ internalType: "contract IMinter1155"
61
+ },
62
+ {
63
+ name: "tokenId",
64
+ type: "uint256",
65
+ internalType: "uint256"
66
+ },
67
+ {
68
+ name: "quantity",
69
+ type: "uint256",
70
+ internalType: "uint256"
71
+ },
72
+ {
73
+ name: "minterArguments",
74
+ type: "bytes",
75
+ internalType: "bytes"
76
+ },
77
+ {
78
+ name: "mintReferral",
79
+ type: "address",
80
+ internalType: "address"
81
+ }
82
+ ],
83
+ outputs: [],
84
+ stateMutability: "payable"
85
+ }
86
+ ];
52
87
 
53
88
  // src/apis/chain-constants.ts
54
89
  var REWARD_PER_TOKEN = parseEther("0.000777");
@@ -722,6 +757,19 @@ query ($id: ID!) {
722
757
  parseResponseData: (responseData) => responseData?.zoraCreateToken
723
758
  };
724
759
  }
760
+ function buildGetDefaultMintPriceQuery({}) {
761
+ return {
762
+ query: `
763
+ {
764
+ defaultMintPrice(id: "0x0000000000000000000000000000000000000000") {
765
+ pricePerToken
766
+ }
767
+ }
768
+ `,
769
+ variables: {},
770
+ parseResponseData: (responseData) => responseData?.defaultMintPrice?.pricePerToken ? BigInt(responseData?.defaultMintPrice?.pricePerToken) : void 0
771
+ };
772
+ }
725
773
  function buildContractTokensQuery({
726
774
  tokenAddress
727
775
  }) {
@@ -762,6 +810,7 @@ function buildPremintsOfContractQuery({
762
810
  }
763
811
 
764
812
  // src/mint/subgraph-mint-getter.ts
813
+ import * as semver from "semver";
765
814
  var getApiNetworkConfigForChain = (chainId) => {
766
815
  if (!networkConfigByChain[chainId]) {
767
816
  throw new Error(`chain id ${chainId} network not configured `);
@@ -842,8 +891,10 @@ var SubgraphMintGetter = class {
842
891
  if (!token) {
843
892
  throw new Error("Cannot find token");
844
893
  }
894
+ const defaultMintFee = await this.getContractMintFee(token.contract);
845
895
  return parseTokenQueryResult({
846
896
  token,
897
+ defaultMintFee,
847
898
  tokenId,
848
899
  preferredSaleType: saleType
849
900
  });
@@ -851,6 +902,16 @@ var SubgraphMintGetter = class {
851
902
  this.httpClient = httpClient2 || httpClient;
852
903
  this.networkConfig = getApiNetworkConfigForChain(chainId);
853
904
  }
905
+ async getContractMintFee(contract) {
906
+ const storedMintFee = BigInt(contract.mintFeePerQuantity);
907
+ if (!contractUsesMintCardsForMintFee(contract.contractVersion)) {
908
+ return storedMintFee;
909
+ }
910
+ const defaultMintFee = await this.querySubgraphWithRetries(
911
+ buildGetDefaultMintPriceQuery({})
912
+ );
913
+ return defaultMintFee || storedMintFee;
914
+ }
854
915
  async querySubgraphWithRetries({
855
916
  query,
856
917
  variables,
@@ -873,13 +934,15 @@ var SubgraphMintGetter = class {
873
934
  tokenAddress
874
935
  })
875
936
  );
876
- if (!tokens)
937
+ if (!tokens || tokens.length === 0)
877
938
  return [];
939
+ const defaultMintFee = await this.getContractMintFee(tokens[0].contract);
878
940
  return tokens.filter((x) => x.tokenId !== "0").map(
879
941
  (token) => parseTokenQueryResult({
880
942
  token,
881
943
  tokenId: token.tokenId,
882
- preferredSaleType
944
+ preferredSaleType,
945
+ defaultMintFee
883
946
  })
884
947
  );
885
948
  }
@@ -900,14 +963,15 @@ var SubgraphMintGetter = class {
900
963
  function parseTokenQueryResult({
901
964
  token,
902
965
  tokenId,
903
- preferredSaleType
966
+ preferredSaleType,
967
+ defaultMintFee
904
968
  }) {
905
969
  const targetStrategy = getTargetStrategy({
906
970
  tokenId,
907
971
  preferredSaleType,
908
972
  token
909
973
  });
910
- const tokenInfo = parseTokenInfo(token);
974
+ const tokenInfo = parseTokenInfo(token, defaultMintFee);
911
975
  const salesConfig = parseSalesConfig(targetStrategy);
912
976
  if (isErc20SaleStrategy(salesConfig)) {
913
977
  tokenInfo.mintFeePerQuantity = 0n;
@@ -917,7 +981,13 @@ function parseTokenQueryResult({
917
981
  salesConfig
918
982
  };
919
983
  }
920
- function parseTokenInfo(token) {
984
+ var contractUsesMintCardsForMintFee = (contractVersion) => {
985
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
986
+ if (!semVerContractVersion)
987
+ return false;
988
+ return semver.gte(semVerContractVersion, "2.9.0");
989
+ };
990
+ function parseTokenInfo(token, defaultMintFee) {
921
991
  return {
922
992
  contract: {
923
993
  address: token.contract.address,
@@ -930,7 +1000,7 @@ function parseTokenInfo(token) {
930
1000
  creator: token.creator,
931
1001
  totalMinted: BigInt(token.totalMinted),
932
1002
  maxSupply: BigInt(token.maxSupply),
933
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
1003
+ mintFeePerQuantity: defaultMintFee,
934
1004
  contractVersion: token.contract.contractVersion
935
1005
  };
936
1006
  }
@@ -1594,15 +1664,15 @@ import {
1594
1664
  } from "@zoralabs/protocol-deployments";
1595
1665
 
1596
1666
  // src/mint/utils.ts
1597
- import * as semver from "semver";
1667
+ import * as semver2 from "semver";
1598
1668
  var contractSupportsNewMintFunction = (contractVersion) => {
1599
1669
  if (!contractVersion) {
1600
1670
  return false;
1601
1671
  }
1602
- const semVerContractVersion = semver.coerce(contractVersion)?.raw;
1672
+ const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
1603
1673
  if (!semVerContractVersion)
1604
1674
  return false;
1605
- return semver.gte(semVerContractVersion, "2.9.0");
1675
+ return semver2.gte(semVerContractVersion, "2.9.0");
1606
1676
  };
1607
1677
 
1608
1678
  // src/mint/mint-transactions.ts
@@ -1735,7 +1805,7 @@ function makeEthMintCall({
1735
1805
  });
1736
1806
  }
1737
1807
  return makeContractParameters({
1738
- abi: zoraCreator1155ImplABI2,
1808
+ abi: zora1155LegacyAbi,
1739
1809
  functionName: "mintWithRewards",
1740
1810
  account: minterAccount,
1741
1811
  value: mintValue,
@@ -2166,7 +2236,7 @@ import {
2166
2236
  zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
2167
2237
  } from "@zoralabs/protocol-deployments";
2168
2238
  import { encodeFunctionData, zeroAddress as zeroAddress5 } from "viem";
2169
- import * as semver2 from "semver";
2239
+ import * as semver3 from "semver";
2170
2240
  var PERMISSION_BITS = {
2171
2241
  MINTER: 2n ** 2n
2172
2242
  };
@@ -2417,13 +2487,13 @@ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
2417
2487
  if (!contractStandard || !contractVersion) {
2418
2488
  return false;
2419
2489
  }
2420
- const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
2490
+ const semVerContractVersion = semver3.coerce(contractVersion)?.raw;
2421
2491
  if (!semVerContractVersion)
2422
2492
  return false;
2423
2493
  if (contractStandard === "ERC1155") {
2424
- return semver2.gte(semVerContractVersion, "1.3.5");
2494
+ return semver3.gte(semVerContractVersion, "1.3.5");
2425
2495
  } else {
2426
- return semver2.gte(semVerContractVersion, "14.0.0");
2496
+ return semver3.gte(semVerContractVersion, "14.0.0");
2427
2497
  }
2428
2498
  };
2429
2499
 
@@ -3023,7 +3093,7 @@ var equals = (aa, bb) => {
3023
3093
  }
3024
3094
  return true;
3025
3095
  };
3026
- var coerce3 = (o) => {
3096
+ var coerce4 = (o) => {
3027
3097
  if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
3028
3098
  return o;
3029
3099
  if (o instanceof ArrayBuffer)
@@ -3046,7 +3116,7 @@ var create = (code, digest) => {
3046
3116
  return new Digest(code, size, digest, bytes);
3047
3117
  };
3048
3118
  var decode3 = (multihash) => {
3049
- const bytes = coerce3(multihash);
3119
+ const bytes = coerce4(multihash);
3050
3120
  const [code, sizeOffset] = decode2(bytes);
3051
3121
  const [size, digestOffset] = decode2(bytes.subarray(sizeOffset));
3052
3122
  const digest = bytes.subarray(sizeOffset + digestOffset);
@@ -3290,7 +3360,7 @@ var baseX = ({ prefix, name, alphabet }) => {
3290
3360
  prefix,
3291
3361
  name,
3292
3362
  encode: encode3,
3293
- decode: (text) => coerce3(decode5(text))
3363
+ decode: (text) => coerce4(decode5(text))
3294
3364
  });
3295
3365
  };
3296
3366
  var decode4 = (string, alphabet, bitsPerChar, name) => {
@@ -3577,7 +3647,7 @@ var CID = class _CID {
3577
3647
  static decodeFirst(bytes) {
3578
3648
  const specs = _CID.inspectBytes(bytes);
3579
3649
  const prefixSize = specs.size - specs.multihashSize;
3580
- const multihashBytes = coerce3(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
3650
+ const multihashBytes = coerce4(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
3581
3651
  if (multihashBytes.byteLength !== specs.multihashSize) {
3582
3652
  throw new Error("Incorrect length");
3583
3653
  }