@zoralabs/protocol-sdk 0.7.6 → 0.9.0

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 (80) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +17 -0
  3. package/dist/allow-list/allow-list-client.d.ts +26 -0
  4. package/dist/allow-list/allow-list-client.d.ts.map +1 -0
  5. package/dist/allow-list/types.d.ts +14 -0
  6. package/dist/allow-list/types.d.ts.map +1 -0
  7. package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
  8. package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
  9. package/dist/apis/http-api-base.d.ts.map +1 -1
  10. package/dist/apis/subgraph-querier.d.ts +18 -0
  11. package/dist/apis/subgraph-querier.d.ts.map +1 -0
  12. package/dist/create/1155-create-helper.d.ts +14 -11
  13. package/dist/create/1155-create-helper.d.ts.map +1 -1
  14. package/dist/create/contract-setup.d.ts +13 -8
  15. package/dist/create/contract-setup.d.ts.map +1 -1
  16. package/dist/create/minter-defaults.d.ts +5 -0
  17. package/dist/create/minter-defaults.d.ts.map +1 -0
  18. package/dist/create/minter-setup.d.ts +14 -0
  19. package/dist/create/minter-setup.d.ts.map +1 -0
  20. package/dist/create/token-setup.d.ts +4 -19
  21. package/dist/create/token-setup.d.ts.map +1 -1
  22. package/dist/create/types.d.ts +53 -13
  23. package/dist/create/types.d.ts.map +1 -1
  24. package/dist/create/update.d.ts +15 -0
  25. package/dist/create/update.d.ts.map +1 -0
  26. package/dist/index.cjs +1660 -1246
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1681 -1264
  31. package/dist/index.js.map +1 -1
  32. package/dist/ipfs/token-metadata.d.ts +1 -0
  33. package/dist/ipfs/token-metadata.d.ts.map +1 -1
  34. package/dist/mint/mint-client.d.ts +2 -6
  35. package/dist/mint/mint-client.d.ts.map +1 -1
  36. package/dist/mint/mint-queries.d.ts +3 -1
  37. package/dist/mint/mint-queries.d.ts.map +1 -1
  38. package/dist/mint/mint-transactions.d.ts +9 -7
  39. package/dist/mint/mint-transactions.d.ts.map +1 -1
  40. package/dist/mint/subgraph-mint-getter.d.ts +5 -4
  41. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  42. package/dist/mint/subgraph-queries.d.ts +42 -15
  43. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  44. package/dist/mint/types.d.ts +32 -13
  45. package/dist/mint/types.d.ts.map +1 -1
  46. package/dist/sdk.d.ts +2 -1
  47. package/dist/sdk.d.ts.map +1 -1
  48. package/dist/sparks/sparks-contracts.d.ts +96 -96
  49. package/dist/types.d.ts +1 -1
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/utils.d.ts +1 -8
  52. package/dist/utils.d.ts.map +1 -1
  53. package/package.json +2 -3
  54. package/src/allow-list/allow-list-client.ts +105 -0
  55. package/src/allow-list/types.ts +15 -0
  56. package/src/apis/generated/allow-list-api-types.ts +288 -0
  57. package/src/apis/http-api-base.ts +12 -0
  58. package/src/apis/subgraph-querier.ts +38 -0
  59. package/src/create/1155-create-helper.test.ts +269 -113
  60. package/src/create/1155-create-helper.ts +204 -90
  61. package/src/create/contract-setup.ts +54 -44
  62. package/src/create/minter-defaults.test.ts +21 -0
  63. package/src/create/minter-defaults.ts +134 -0
  64. package/src/create/minter-setup.ts +293 -0
  65. package/src/create/token-setup.ts +14 -190
  66. package/src/create/types.ts +94 -25
  67. package/src/create/update.ts +93 -0
  68. package/src/index.ts +4 -0
  69. package/src/ipfs/token-metadata.ts +18 -0
  70. package/src/mint/mint-client.test.ts +219 -15
  71. package/src/mint/mint-client.ts +2 -34
  72. package/src/mint/mint-queries.ts +34 -13
  73. package/src/mint/mint-transactions.ts +104 -17
  74. package/src/mint/subgraph-mint-getter.ts +107 -50
  75. package/src/mint/subgraph-queries.ts +67 -37
  76. package/src/mint/types.ts +55 -16
  77. package/src/premint/premint-client.test.ts +6 -5
  78. package/src/sdk.ts +5 -2
  79. package/src/types.ts +1 -1
  80. package/src/utils.ts +1 -25
package/dist/index.js CHANGED
@@ -710,8 +710,8 @@ var require_gte = __commonJS({
710
710
  "../../node_modules/.pnpm/semver@7.6.3/node_modules/semver/functions/gte.js"(exports, module) {
711
711
  "use strict";
712
712
  var compare = require_compare();
713
- var gte4 = (a, b, loose) => compare(a, b, loose) >= 0;
714
- module.exports = gte4;
713
+ var gte3 = (a, b, loose) => compare(a, b, loose) >= 0;
714
+ module.exports = gte3;
715
715
  }
716
716
  });
717
717
 
@@ -732,7 +732,7 @@ var require_cmp = __commonJS({
732
732
  var eq = require_eq();
733
733
  var neq = require_neq();
734
734
  var gt = require_gt();
735
- var gte4 = require_gte();
735
+ var gte3 = require_gte();
736
736
  var lt = require_lt();
737
737
  var lte = require_lte();
738
738
  var cmp = (a, op, b, loose) => {
@@ -762,7 +762,7 @@ var require_cmp = __commonJS({
762
762
  case ">":
763
763
  return gt(a, b, loose);
764
764
  case ">=":
765
- return gte4(a, b, loose);
765
+ return gte3(a, b, loose);
766
766
  case "<":
767
767
  return lt(a, b, loose);
768
768
  case "<=":
@@ -782,7 +782,7 @@ var require_coerce = __commonJS({
782
782
  var SemVer = require_semver();
783
783
  var parse = require_parse();
784
784
  var { safeRe: re, t } = require_re();
785
- var coerce5 = (version, options) => {
785
+ var coerce4 = (version, options) => {
786
786
  if (version instanceof SemVer) {
787
787
  return version;
788
788
  }
@@ -817,7 +817,7 @@ var require_coerce = __commonJS({
817
817
  const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
818
818
  return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
819
819
  };
820
- module.exports = coerce5;
820
+ module.exports = coerce4;
821
821
  }
822
822
  });
823
823
 
@@ -1518,7 +1518,7 @@ var require_outside = __commonJS({
1518
1518
  var gt = require_gt();
1519
1519
  var lt = require_lt();
1520
1520
  var lte = require_lte();
1521
- var gte4 = require_gte();
1521
+ var gte3 = require_gte();
1522
1522
  var outside = (version, range, hilo, options) => {
1523
1523
  version = new SemVer(version, options);
1524
1524
  range = new Range(range, options);
@@ -1533,7 +1533,7 @@ var require_outside = __commonJS({
1533
1533
  break;
1534
1534
  case "<":
1535
1535
  gtfn = lt;
1536
- ltefn = gte4;
1536
+ ltefn = gte3;
1537
1537
  ltfn = gt;
1538
1538
  comp = "<";
1539
1539
  ecomp = "<=";
@@ -1849,10 +1849,10 @@ var require_semver2 = __commonJS({
1849
1849
  var lt = require_lt();
1850
1850
  var eq = require_eq();
1851
1851
  var neq = require_neq();
1852
- var gte4 = require_gte();
1852
+ var gte3 = require_gte();
1853
1853
  var lte = require_lte();
1854
1854
  var cmp = require_cmp();
1855
- var coerce5 = require_coerce();
1855
+ var coerce4 = require_coerce();
1856
1856
  var Comparator = require_comparator();
1857
1857
  var Range = require_range();
1858
1858
  var satisfies = require_satisfies();
@@ -1887,10 +1887,10 @@ var require_semver2 = __commonJS({
1887
1887
  lt,
1888
1888
  eq,
1889
1889
  neq,
1890
- gte: gte4,
1890
+ gte: gte3,
1891
1891
  lte,
1892
1892
  cmp,
1893
- coerce: coerce5,
1893
+ coerce: coerce4,
1894
1894
  Comparator,
1895
1895
  Range,
1896
1896
  satisfies,
@@ -2534,14 +2534,20 @@ var get = async (url) => {
2534
2534
  return await response.json();
2535
2535
  };
2536
2536
  var post = async (url, data) => {
2537
+ const controller = new AbortController();
2538
+ const { signal } = controller;
2539
+ const timeout = 30 * 60 * 1e3;
2540
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
2537
2541
  const response = await fetch(url, {
2538
2542
  method: "POST",
2539
2543
  headers: {
2540
2544
  "content-type": "application/json",
2541
2545
  accept: "application/json"
2542
2546
  },
2543
- body: JSON.stringify(data)
2547
+ body: JSON.stringify(data),
2548
+ signal
2544
2549
  });
2550
+ clearTimeout(timeoutId);
2545
2551
  if (response.status !== 200) {
2546
2552
  let json;
2547
2553
  try {
@@ -2577,36 +2583,26 @@ var httpClient = {
2577
2583
  retries
2578
2584
  };
2579
2585
 
2580
- // src/mint/types.ts
2581
- var isOnChainMint = (mint2) => mint2.mintType !== "premint";
2582
- var is1155Mint = (mint2) => mint2.mintType === "1155";
2583
- function isErc20SaleStrategy(salesConfig) {
2584
- return salesConfig.saleType === "erc20";
2585
- }
2586
-
2587
- // src/utils.ts
2588
- var makeContractParameters = (args) => args;
2589
- function mintRecipientOrAccount({
2590
- mintRecipient,
2591
- minterAccount
2592
- }) {
2593
- return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
2594
- }
2595
- async function querySubgraphWithRetries({
2596
- httpClient: httpClient2,
2597
- subgraphUrl,
2598
- query,
2599
- variables
2600
- }) {
2601
- const { retries: retries2, post: post2 } = httpClient2;
2602
- const result = await retries2(async () => {
2603
- return await post2(subgraphUrl, {
2604
- query,
2605
- variables
2586
+ // src/apis/subgraph-querier.ts
2587
+ var SubgraphQuerier = class {
2588
+ constructor(httpClient2) {
2589
+ this.httpClient = httpClient2;
2590
+ }
2591
+ async query({
2592
+ subgraphUrl,
2593
+ query,
2594
+ variables
2595
+ }) {
2596
+ const { retries: retries2, post: post2 } = this.httpClient;
2597
+ const result = await retries2(async () => {
2598
+ return await post2(subgraphUrl, {
2599
+ query,
2600
+ variables
2601
+ });
2606
2602
  });
2607
- });
2608
- return result?.data;
2609
- }
2603
+ return result?.data;
2604
+ }
2605
+ };
2610
2606
 
2611
2607
  // src/mint/subgraph-queries.ts
2612
2608
  var NFT_SALE_STRATEGY_FRAGMENT = `
@@ -2627,6 +2623,23 @@ fragment SaleStrategy on SalesStrategyConfig {
2627
2623
  saleStart
2628
2624
  maxTokensPerAddress
2629
2625
  }
2626
+ presale {
2627
+ address
2628
+ presaleStart
2629
+ presaleEnd
2630
+ merkleRoot
2631
+ }
2632
+ zoraTimedMinter {
2633
+ address
2634
+ mintFee
2635
+ saleStart
2636
+ saleEnd
2637
+ erc20Z {
2638
+ id
2639
+ pool
2640
+ }
2641
+ secondaryActivated
2642
+ }
2630
2643
  }`;
2631
2644
  var TOKEN_FRAGMENT = `
2632
2645
  fragment Token on ZoraCreateToken {
@@ -2636,7 +2649,7 @@ fragment Token on ZoraCreateToken {
2636
2649
  totalMinted
2637
2650
  maxSupply
2638
2651
  tokenStandard
2639
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
2652
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
2640
2653
  ...SaleStrategy
2641
2654
  }
2642
2655
  contract {
@@ -2645,7 +2658,7 @@ fragment Token on ZoraCreateToken {
2645
2658
  contractVersion
2646
2659
  contractURI
2647
2660
  name
2648
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
2661
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
2649
2662
  ...SaleStrategy
2650
2663
  }
2651
2664
  }
@@ -2676,19 +2689,6 @@ query ($id: ID!) {
2676
2689
  parseResponseData: (responseData) => responseData?.zoraCreateToken
2677
2690
  };
2678
2691
  }
2679
- function buildGetDefaultMintPriceQuery({}) {
2680
- return {
2681
- query: `
2682
- {
2683
- defaultMintPrice(id: "0x0000000000000000000000000000000000000000") {
2684
- pricePerToken
2685
- }
2686
- }
2687
- `,
2688
- variables: {},
2689
- parseResponseData: (responseData) => responseData?.defaultMintPrice?.pricePerToken ? BigInt(responseData?.defaultMintPrice?.pricePerToken) : void 0
2690
- };
2691
- }
2692
2692
  function buildContractTokensQuery({
2693
2693
  tokenAddress
2694
2694
  }) {
@@ -2729,14 +2729,13 @@ function buildPremintsOfContractQuery({
2729
2729
  }
2730
2730
 
2731
2731
  // src/mint/subgraph-mint-getter.ts
2732
- var semver = __toESM(require_semver2(), 1);
2733
2732
  var getApiNetworkConfigForChain = (chainId) => {
2734
2733
  if (!networkConfigByChain[chainId]) {
2735
2734
  throw new Error(`chain id ${chainId} network not configured `);
2736
2735
  }
2737
2736
  return networkConfigByChain[chainId];
2738
2737
  };
2739
- function parseSalesConfig(targetStrategy) {
2738
+ function parseSalesConfig(targetStrategy, contractMintFee) {
2740
2739
  if (targetStrategy.type === "FIXED_PRICE")
2741
2740
  return {
2742
2741
  saleType: "fixedPrice",
@@ -2744,7 +2743,8 @@ function parseSalesConfig(targetStrategy) {
2744
2743
  maxTokensPerAddress: BigInt(
2745
2744
  targetStrategy.fixedPrice.maxTokensPerAddress
2746
2745
  ),
2747
- pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
2746
+ pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken),
2747
+ mintFeePerQuantity: contractMintFee
2748
2748
  };
2749
2749
  if (targetStrategy.type === "ERC_20_MINTER") {
2750
2750
  return {
@@ -2753,31 +2753,72 @@ function parseSalesConfig(targetStrategy) {
2753
2753
  maxTokensPerAddress: BigInt(
2754
2754
  targetStrategy.erc20Minter.maxTokensPerAddress
2755
2755
  ),
2756
- pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
2756
+ pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
2757
+ mintFeePerQuantity: 0n
2758
+ };
2759
+ }
2760
+ if (targetStrategy.type === "PRESALE") {
2761
+ return {
2762
+ saleType: "allowlist",
2763
+ address: targetStrategy.presale.address,
2764
+ merkleRoot: targetStrategy.presale.merkleRoot,
2765
+ saleStart: targetStrategy.presale.presaleStart,
2766
+ saleEnd: targetStrategy.presale.presaleEnd,
2767
+ mintFeePerQuantity: contractMintFee
2768
+ };
2769
+ }
2770
+ if (targetStrategy.type === "ZORA_TIMED") {
2771
+ return {
2772
+ saleType: "timed",
2773
+ address: targetStrategy.zoraTimedMinter.address,
2774
+ mintFee: BigInt(targetStrategy.zoraTimedMinter.mintFee),
2775
+ saleStart: targetStrategy.zoraTimedMinter.saleStart,
2776
+ saleEnd: targetStrategy.zoraTimedMinter.saleEnd,
2777
+ erc20Z: targetStrategy.zoraTimedMinter.erc20Z.id,
2778
+ pool: targetStrategy.zoraTimedMinter.erc20Z.pool,
2779
+ secondaryActivated: targetStrategy.zoraTimedMinter.secondaryActivated,
2780
+ mintFeePerQuantity: BigInt(targetStrategy.zoraTimedMinter.mintFee)
2757
2781
  };
2758
2782
  }
2759
2783
  throw new Error("Unknown saleType");
2760
2784
  }
2761
2785
  function getSaleEnd(a) {
2762
- return BigInt(
2763
- a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
2764
- );
2786
+ if (a.type === "FIXED_PRICE")
2787
+ return BigInt(a.fixedPrice.saleEnd);
2788
+ if (a.type === "ERC_20_MINTER")
2789
+ return BigInt(a.erc20Minter.saleEnd);
2790
+ if (a.type === "ZORA_TIMED")
2791
+ return BigInt(a.zoraTimedMinter.saleEnd);
2792
+ return BigInt(a.presale.presaleEnd);
2793
+ }
2794
+ function strategyIsStillValid(strategy, blockTime) {
2795
+ if (strategy.type === "FIXED_PRICE") {
2796
+ return BigInt(strategy.fixedPrice.saleEnd) > blockTime;
2797
+ }
2798
+ if (strategy.type === "ERC_20_MINTER") {
2799
+ return BigInt(strategy.erc20Minter.saleEnd) > blockTime;
2800
+ }
2801
+ if (strategy.type === "ZORA_TIMED") {
2802
+ return BigInt(strategy.zoraTimedMinter.saleEnd) > blockTime;
2803
+ }
2804
+ return BigInt(strategy.presale.presaleEnd) > blockTime;
2765
2805
  }
2766
2806
  function getTargetStrategy({
2767
2807
  tokenId,
2768
2808
  preferredSaleType,
2769
- token
2809
+ token,
2810
+ blockTime
2770
2811
  }) {
2771
2812
  const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
2772
- const saleStrategies = allStrategies.sort(
2813
+ const stillValidSalesStrategies = allStrategies.filter(
2814
+ (strategy) => strategyIsStillValid(strategy, blockTime)
2815
+ );
2816
+ const saleStrategies = stillValidSalesStrategies.sort(
2773
2817
  (a, b) => getSaleEnd(a) > getSaleEnd(b) ? 1 : -1
2774
2818
  );
2775
2819
  let targetStrategy;
2776
2820
  if (!preferredSaleType) {
2777
- targetStrategy = saleStrategies[0];
2778
- if (!targetStrategy) {
2779
- throw new Error("Cannot find sale strategy");
2780
- }
2821
+ return saleStrategies[0];
2781
2822
  } else {
2782
2823
  const mappedSaleType = preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
2783
2824
  targetStrategy = saleStrategies.find(
@@ -2795,11 +2836,12 @@ function getTargetStrategy({
2795
2836
  return targetStrategy;
2796
2837
  }
2797
2838
  var SubgraphMintGetter = class {
2798
- constructor(chainId, httpClient2) {
2839
+ constructor(chainId, subgraphQuerier) {
2799
2840
  this.getMintable = async ({
2800
2841
  tokenAddress,
2801
2842
  tokenId,
2802
- preferredSaleType: saleType
2843
+ preferredSaleType: saleType,
2844
+ blockTime
2803
2845
  }) => {
2804
2846
  const token = await this.querySubgraphWithRetries(
2805
2847
  buildNftTokenSalesQuery({
@@ -2815,29 +2857,22 @@ var SubgraphMintGetter = class {
2815
2857
  token,
2816
2858
  defaultMintFee,
2817
2859
  tokenId,
2818
- preferredSaleType: saleType
2860
+ preferredSaleType: saleType,
2861
+ blockTime
2819
2862
  });
2820
2863
  };
2821
- this.httpClient = httpClient2 || httpClient;
2864
+ this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
2822
2865
  this.networkConfig = getApiNetworkConfigForChain(chainId);
2823
2866
  }
2824
2867
  async getContractMintFee(contract) {
2825
- const storedMintFee = BigInt(contract.mintFeePerQuantity);
2826
- if (!contractUsesMintCardsForMintFee(contract.contractVersion)) {
2827
- return storedMintFee;
2828
- }
2829
- const defaultMintFee = await this.querySubgraphWithRetries(
2830
- buildGetDefaultMintPriceQuery({})
2831
- );
2832
- return defaultMintFee || storedMintFee;
2868
+ return BigInt(contract.mintFeePerQuantity);
2833
2869
  }
2834
2870
  async querySubgraphWithRetries({
2835
2871
  query,
2836
2872
  variables,
2837
2873
  parseResponseData
2838
2874
  }) {
2839
- const responseData = await querySubgraphWithRetries({
2840
- httpClient: this.httpClient,
2875
+ const responseData = await this.subgraphQuerier.query({
2841
2876
  subgraphUrl: this.networkConfig.subgraphUrl,
2842
2877
  query,
2843
2878
  variables
@@ -2846,7 +2881,8 @@ var SubgraphMintGetter = class {
2846
2881
  }
2847
2882
  async getContractMintable({
2848
2883
  tokenAddress,
2849
- preferredSaleType
2884
+ preferredSaleType,
2885
+ blockTime
2850
2886
  }) {
2851
2887
  const tokens = await this.querySubgraphWithRetries(
2852
2888
  buildContractTokensQuery({
@@ -2861,7 +2897,8 @@ var SubgraphMintGetter = class {
2861
2897
  token,
2862
2898
  tokenId: token.tokenId,
2863
2899
  preferredSaleType,
2864
- defaultMintFee
2900
+ defaultMintFee,
2901
+ blockTime
2865
2902
  })
2866
2903
  );
2867
2904
  }
@@ -2879,34 +2916,49 @@ var SubgraphMintGetter = class {
2879
2916
  })) || [];
2880
2917
  }
2881
2918
  };
2882
- function parseTokenQueryResult({
2919
+ function getTargetStrategyAndMintFee({
2883
2920
  token,
2884
2921
  tokenId,
2885
2922
  preferredSaleType,
2886
- defaultMintFee
2923
+ defaultMintFee,
2924
+ blockTime
2887
2925
  }) {
2888
2926
  const targetStrategy = getTargetStrategy({
2889
2927
  tokenId,
2890
2928
  preferredSaleType,
2929
+ token,
2930
+ blockTime
2931
+ });
2932
+ if (!targetStrategy)
2933
+ return void 0;
2934
+ const salesConfig = parseSalesConfig(targetStrategy, defaultMintFee);
2935
+ return salesConfig;
2936
+ }
2937
+ function parseTokenQueryResult({
2938
+ token,
2939
+ tokenId,
2940
+ preferredSaleType,
2941
+ defaultMintFee,
2942
+ blockTime
2943
+ }) {
2944
+ const salesConfig = getTargetStrategyAndMintFee({
2945
+ token,
2946
+ tokenId,
2947
+ preferredSaleType,
2948
+ defaultMintFee,
2949
+ blockTime
2950
+ });
2951
+ const tokenInfo = parseTokenInfo({
2891
2952
  token
2892
2953
  });
2893
- const tokenInfo = parseTokenInfo(token, defaultMintFee);
2894
- const salesConfig = parseSalesConfig(targetStrategy);
2895
- if (isErc20SaleStrategy(salesConfig)) {
2896
- tokenInfo.mintFeePerQuantity = 0n;
2897
- }
2898
2954
  return {
2899
2955
  ...tokenInfo,
2900
2956
  salesConfig
2901
2957
  };
2902
2958
  }
2903
- var contractUsesMintCardsForMintFee = (contractVersion) => {
2904
- const semVerContractVersion = semver.coerce(contractVersion)?.raw;
2905
- if (!semVerContractVersion)
2906
- return false;
2907
- return semver.gte(semVerContractVersion, "2.9.0");
2908
- };
2909
- function parseTokenInfo(token, defaultMintFee) {
2959
+ function parseTokenInfo({
2960
+ token
2961
+ }) {
2910
2962
  return {
2911
2963
  contract: {
2912
2964
  address: token.contract.address,
@@ -2919,11 +2971,19 @@ function parseTokenInfo(token, defaultMintFee) {
2919
2971
  creator: token.creator,
2920
2972
  totalMinted: BigInt(token.totalMinted),
2921
2973
  maxSupply: BigInt(token.maxSupply),
2922
- mintFeePerQuantity: defaultMintFee,
2923
2974
  contractVersion: token.contract.contractVersion
2924
2975
  };
2925
2976
  }
2926
2977
 
2978
+ // src/utils.ts
2979
+ var makeContractParameters = (args) => args;
2980
+ function mintRecipientOrAccount({
2981
+ mintRecipient,
2982
+ minterAccount
2983
+ }) {
2984
+ return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
2985
+ }
2986
+
2927
2987
  // src/premint/premint-client.ts
2928
2988
  var defaultTokenConfigV1MintArguments = () => ({
2929
2989
  maxSupply: OPEN_EDITION_MINT_SIZE,
@@ -3571,6 +3631,16 @@ var PremintAPIClient = class {
3571
3631
  }
3572
3632
  };
3573
3633
 
3634
+ // src/mint/types.ts
3635
+ var isOnChainMint = (mint2) => mint2.mintType !== "premint";
3636
+ var is1155Mint = (mint2) => mint2.mintType === "1155";
3637
+ function isErc20SaleStrategy(salesConfig) {
3638
+ return salesConfig.saleType === "erc20";
3639
+ }
3640
+
3641
+ // src/mint/mint-queries.ts
3642
+ import { zeroAddress as zeroAddress4 } from "viem";
3643
+
3574
3644
  // src/mint/mint-transactions.ts
3575
3645
  import {
3576
3646
  encodeAbiParameters,
@@ -3579,19 +3649,20 @@ import {
3579
3649
  } from "viem";
3580
3650
  import {
3581
3651
  erc20MinterABI,
3582
- zoraCreator1155ImplABI as zoraCreator1155ImplABI2
3652
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
3653
+ zoraTimedSaleStrategyABI
3583
3654
  } from "@zoralabs/protocol-deployments";
3584
3655
 
3585
3656
  // src/mint/utils.ts
3586
- var semver2 = __toESM(require_semver2(), 1);
3657
+ var semver = __toESM(require_semver2(), 1);
3587
3658
  var contractSupportsNewMintFunction = (contractVersion) => {
3588
3659
  if (!contractVersion) {
3589
3660
  return false;
3590
3661
  }
3591
- const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
3662
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
3592
3663
  if (!semVerContractVersion)
3593
3664
  return false;
3594
- return semver2.gte(semVerContractVersion, "2.9.0");
3665
+ return semver.gte(semVerContractVersion, "2.9.0");
3595
3666
  };
3596
3667
 
3597
3668
  // src/mint/mint-transactions.ts
@@ -3621,12 +3692,13 @@ function makePrepareMint1155TokenParams({
3621
3692
  mintComment,
3622
3693
  mintReferral,
3623
3694
  mintRecipient,
3624
- quantityToMint
3695
+ quantityToMint,
3696
+ allowListEntry
3625
3697
  }) {
3626
3698
  const mintQuantity = BigInt(quantityToMint || 1);
3627
3699
  const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
3628
3700
  const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
3629
- if (saleType === "fixedPrice") {
3701
+ if (saleType === "fixedPrice" || saleType === "allowlist") {
3630
3702
  return makeEthMintCall({
3631
3703
  mintComment,
3632
3704
  minterAccount,
@@ -3635,7 +3707,26 @@ function makePrepareMint1155TokenParams({
3635
3707
  mintTo,
3636
3708
  salesConfigAndTokenInfo,
3637
3709
  tokenContract,
3638
- tokenId
3710
+ tokenId,
3711
+ allowListEntry
3712
+ });
3713
+ }
3714
+ if (saleType === "timed") {
3715
+ return makeContractParameters({
3716
+ abi: zoraTimedSaleStrategyABI,
3717
+ functionName: "mint",
3718
+ account: minterAccount,
3719
+ address: salesConfigAndTokenInfo.salesConfig.address,
3720
+ value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
3721
+ /* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
3722
+ args: [
3723
+ mintTo,
3724
+ mintQuantity,
3725
+ tokenContract,
3726
+ BigInt(tokenId),
3727
+ mintReferral || zeroAddress3,
3728
+ mintComment || ""
3729
+ ]
3639
3730
  });
3640
3731
  }
3641
3732
  if (saleType === "erc20") {
@@ -3670,9 +3761,9 @@ function makePrepareMint721TokenParams({
3670
3761
  }) {
3671
3762
  const actualQuantityToMint = BigInt(quantityToMint || 1);
3672
3763
  const mintValue = parseMintCosts({
3673
- mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
3674
3764
  salesConfig: salesConfigAndTokenInfo.salesConfig,
3675
- quantityToMint: actualQuantityToMint
3765
+ quantityToMint: actualQuantityToMint,
3766
+ allowListEntry: void 0
3676
3767
  }).totalCostEth;
3677
3768
  return makeContractParameters({
3678
3769
  abi: zora721Abi,
@@ -3688,6 +3779,29 @@ function makePrepareMint721TokenParams({
3688
3779
  ]
3689
3780
  });
3690
3781
  }
3782
+ function makeFixedPriceMinterArguments({
3783
+ mintTo,
3784
+ mintComment
3785
+ }) {
3786
+ return encodeAbiParameters(parseAbiParameters("address, string"), [
3787
+ mintTo,
3788
+ mintComment || ""
3789
+ ]);
3790
+ }
3791
+ function makeAllowListMinterArguments({
3792
+ mintTo,
3793
+ allowListEntry
3794
+ }) {
3795
+ return encodeAbiParameters(
3796
+ parseAbiParameters("address, uint256, uint256, bytes32[]"),
3797
+ [
3798
+ mintTo,
3799
+ BigInt(allowListEntry.maxCanMint),
3800
+ allowListEntry.price,
3801
+ allowListEntry.proof
3802
+ ]
3803
+ );
3804
+ }
3691
3805
  function makeEthMintCall({
3692
3806
  tokenContract,
3693
3807
  tokenId,
@@ -3696,17 +3810,25 @@ function makeEthMintCall({
3696
3810
  mintComment,
3697
3811
  mintReferral,
3698
3812
  mintQuantity,
3699
- mintTo
3813
+ mintTo,
3814
+ allowListEntry
3700
3815
  }) {
3701
3816
  const mintValue = parseMintCosts({
3702
- mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
3703
3817
  salesConfig: salesConfigAndTokenInfo.salesConfig,
3704
- quantityToMint: mintQuantity
3818
+ quantityToMint: mintQuantity,
3819
+ allowListEntry
3705
3820
  }).totalCostEth;
3706
- const minterArguments = encodeAbiParameters(
3707
- parseAbiParameters("address, string"),
3708
- [mintTo, mintComment || ""]
3709
- );
3821
+ const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
3822
+ let minterArguments;
3823
+ if (saleType === "fixedPrice") {
3824
+ minterArguments = makeFixedPriceMinterArguments({ mintTo, mintComment });
3825
+ } else if (saleType === "allowlist") {
3826
+ if (!allowListEntry)
3827
+ throw new Error("Missing allowListEntry");
3828
+ minterArguments = makeAllowListMinterArguments({ mintTo, allowListEntry });
3829
+ } else {
3830
+ throw new Error("Unsupported sale type");
3831
+ }
3710
3832
  if (contractSupportsNewMintFunction(salesConfigAndTokenInfo.contractVersion)) {
3711
3833
  return makeContractParameters({
3712
3834
  abi: zoraCreator1155ImplABI2,
@@ -3739,13 +3861,21 @@ function makeEthMintCall({
3739
3861
  ]
3740
3862
  });
3741
3863
  }
3864
+ function paidMintCost(salesConfig, allowListEntry) {
3865
+ if (salesConfig.saleType === "erc20" || salesConfig.saleType === "fixedPrice") {
3866
+ return salesConfig.pricePerToken;
3867
+ }
3868
+ if (allowListEntry)
3869
+ return allowListEntry.price;
3870
+ return 0n;
3871
+ }
3742
3872
  function parseMintCosts({
3743
3873
  salesConfig,
3744
- mintFeePerQuantity,
3745
- quantityToMint
3874
+ quantityToMint,
3875
+ allowListEntry
3746
3876
  }) {
3747
- const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
3748
- const tokenPurchaseCost = BigInt(salesConfig.pricePerToken) * quantityToMint;
3877
+ const mintFeeForTokens = salesConfig.mintFeePerQuantity * quantityToMint;
3878
+ const tokenPurchaseCost = paidMintCost(salesConfig, allowListEntry) * quantityToMint;
3749
3879
  const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig) ? salesConfig.currency : void 0;
3750
3880
  const totalPurchaseCostEth = totalPurchaseCostCurrency ? 0n : tokenPurchaseCost;
3751
3881
  return {
@@ -3757,7 +3887,6 @@ function parseMintCosts({
3757
3887
  }
3758
3888
 
3759
3889
  // src/mint/mint-queries.ts
3760
- import { zeroAddress as zeroAddress4 } from "viem";
3761
3890
  async function getMint({
3762
3891
  params,
3763
3892
  mintGetter,
@@ -3767,10 +3896,12 @@ async function getMint({
3767
3896
  const { tokenContract } = params;
3768
3897
  if (isOnChainMint(params)) {
3769
3898
  const tokenId = is1155Mint(params) ? params.tokenId : void 0;
3899
+ const blockTime = (await publicClient.getBlock()).timestamp;
3770
3900
  const result = await mintGetter.getMintable({
3771
3901
  tokenId,
3772
3902
  tokenAddress: tokenContract,
3773
- preferredSaleType: params.preferredSaleType
3903
+ preferredSaleType: params.preferredSaleType,
3904
+ blockTime
3774
3905
  });
3775
3906
  return toMintableReturn(result);
3776
3907
  }
@@ -3831,6 +3962,7 @@ async function getMintsOfContract({
3831
3962
  }
3832
3963
  async function getMintCosts({
3833
3964
  params,
3965
+ allowListEntry,
3834
3966
  mintGetter,
3835
3967
  premintGetter,
3836
3968
  publicClient
@@ -3838,14 +3970,19 @@ async function getMintCosts({
3838
3970
  const { quantityMinted: quantityToMint, collection } = params;
3839
3971
  if (isOnChainMint(params)) {
3840
3972
  const tokenId = is1155Mint(params) ? params.tokenId : void 0;
3973
+ const blockTime = (await publicClient.getBlock()).timestamp;
3841
3974
  const salesConfigAndTokenInfo = await mintGetter.getMintable({
3842
3975
  tokenId,
3843
- tokenAddress: collection
3976
+ tokenAddress: collection,
3977
+ blockTime
3844
3978
  });
3979
+ if (!salesConfigAndTokenInfo.salesConfig) {
3980
+ throw new Error("No valid sales config found for token");
3981
+ }
3845
3982
  return parseMintCosts({
3846
- mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
3847
3983
  salesConfig: salesConfigAndTokenInfo.salesConfig,
3848
- quantityToMint: BigInt(quantityToMint)
3984
+ quantityToMint: BigInt(quantityToMint),
3985
+ allowListEntry
3849
3986
  });
3850
3987
  }
3851
3988
  return getPremintMintCostsWithUnknownTokenPrice({
@@ -3901,7 +4038,6 @@ function parsePremint({
3901
4038
  return {
3902
4039
  creator: premint.signer,
3903
4040
  maxSupply: premint.premint.premintConfig.tokenConfig.maxSupply,
3904
- mintFeePerQuantity: mintFee,
3905
4041
  mintType: "premint",
3906
4042
  uid: premint.premint.premintConfig.uid,
3907
4043
  contract: {
@@ -3915,21 +4051,30 @@ function parsePremint({
3915
4051
  duration: premint.premint.premintConfig.tokenConfig.mintDuration,
3916
4052
  maxTokensPerAddress: premint.premint.premintConfig.tokenConfig.maxTokensPerAddress,
3917
4053
  pricePerToken: premint.premint.premintConfig.tokenConfig.pricePerToken,
3918
- saleType: "premint"
4054
+ saleType: "premint",
4055
+ mintFeePerQuantity: mintFee
3919
4056
  }
3920
4057
  };
3921
4058
  }
3922
4059
  throw new Error("Invalid premint config version");
3923
4060
  }
3924
- var makeOnchainPrepareMint = (result) => (params) => ({
3925
- parameters: makeOnchainMintCall({ token: result, mintParams: params }),
3926
- erc20Approval: getRequiredErc20Approvals(params, result),
3927
- costs: parseMintCosts({
3928
- salesConfig: result.salesConfig,
3929
- quantityToMint: BigInt(params.quantityToMint),
3930
- mintFeePerQuantity: result.mintFeePerQuantity
3931
- })
3932
- });
4061
+ var makeOnchainPrepareMint = (result) => (params) => {
4062
+ if (!result.salesConfig) {
4063
+ throw new Error("No valid sales config found for token");
4064
+ }
4065
+ return {
4066
+ parameters: makeOnchainMintCall({
4067
+ token: result,
4068
+ mintParams: params
4069
+ }),
4070
+ erc20Approval: getRequiredErc20Approvals(params, result),
4071
+ costs: parseMintCosts({
4072
+ salesConfig: result.salesConfig,
4073
+ quantityToMint: BigInt(params.quantityToMint),
4074
+ allowListEntry: params.allowListEntry
4075
+ })
4076
+ };
4077
+ };
3933
4078
  function toMintableReturn(result) {
3934
4079
  return { token: result, prepareMint: makeOnchainPrepareMint(result) };
3935
4080
  }
@@ -3940,9 +4085,9 @@ var makePremintPrepareMint = (mintable, mintFee, premint) => (params) => ({
3940
4085
  premint
3941
4086
  }),
3942
4087
  costs: parseMintCosts({
3943
- mintFeePerQuantity: mintFee,
3944
4088
  quantityToMint: BigInt(params.quantityToMint),
3945
- salesConfig: mintable.salesConfig
4089
+ salesConfig: mintable.salesConfig,
4090
+ allowListEntry: params.allowListEntry
3946
4091
  })
3947
4092
  });
3948
4093
  function toPremintMintReturn({
@@ -3956,7 +4101,7 @@ function toPremintMintReturn({
3956
4101
  };
3957
4102
  }
3958
4103
  function getRequiredErc20Approvals(params, result) {
3959
- if (result.salesConfig.saleType !== "erc20")
4104
+ if (result.salesConfig?.saleType !== "erc20")
3960
4105
  return void 0;
3961
4106
  return {
3962
4107
  quantity: result.salesConfig.pricePerToken * BigInt(params.quantityToMint),
@@ -4062,29 +4207,12 @@ async function mint({
4062
4207
  mintReferral: parameters.mintReferral
4063
4208
  });
4064
4209
  }
4065
- async function collectOnchain({
4066
- chainId,
4067
- mintGetter,
4068
- ...parameters
4069
- }) {
4070
- const { tokenContract, preferredSaleType: saleType } = parameters;
4071
- const tokenId = is1155Mint(parameters) ? parameters.tokenId : void 0;
4072
- const salesConfigAndTokenInfo = await mintGetter.getMintable({
4073
- tokenId,
4074
- tokenAddress: tokenContract,
4075
- preferredSaleType: saleType
4076
- });
4077
- return makeOnchainMintCall({
4078
- mintParams: parameters,
4079
- token: salesConfigAndTokenInfo
4080
- });
4081
- }
4082
4210
 
4083
4211
  // src/create/1155-create-helper.ts
4084
4212
  import {
4085
4213
  zoraCreator1155FactoryImplABI as zoraCreator1155FactoryImplABI2,
4086
4214
  zoraCreator1155FactoryImplAddress as zoraCreator1155FactoryImplAddress2,
4087
- zoraCreator1155ImplABI as zoraCreator1155ImplABI5
4215
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI6
4088
4216
  } from "@zoralabs/protocol-deployments";
4089
4217
  import { decodeEventLog as decodeEventLog2 } from "viem";
4090
4218
 
@@ -4102,1125 +4230,399 @@ function new1155ContractVersion(chainId) {
4102
4230
  }
4103
4231
  return address.CONTRACT_1155_IMPL_VERSION;
4104
4232
  }
4105
- async function getContractInfo({
4233
+ async function getContractInfoExistingContract({
4106
4234
  publicClient,
4107
- chainId,
4108
- contract,
4109
- account
4235
+ contractAddress
4110
4236
  }) {
4111
- const contractAddress = typeof contract === "string" ? contract : await publicClient.readContract({
4112
- abi: zoraCreator1155FactoryImplABI,
4113
- // Since this address is deterministic we can hardcode a chain id safely here.
4114
- address: zoraCreator1155FactoryImplAddress[chainId],
4115
- functionName: "deterministicContractAddress",
4116
- args: [
4117
- account,
4118
- contract.uri,
4119
- contract.name,
4120
- contract.defaultAdmin || account
4121
- ]
4122
- });
4123
4237
  let contractVersion;
4124
- let contractExists;
4125
4238
  try {
4126
4239
  contractVersion = await publicClient.readContract({
4127
4240
  abi: zoraCreator1155ImplABI3,
4128
4241
  address: contractAddress,
4129
4242
  functionName: "contractVersion"
4130
4243
  });
4131
- contractExists = true;
4132
4244
  } catch (e) {
4133
- contractVersion = new1155ContractVersion(chainId);
4134
- contractExists = false;
4245
+ throw new Error(`Contract does not exist at ${contractAddress}`);
4135
4246
  }
4136
- const nextTokenId = contractExists ? await publicClient.readContract({
4247
+ const nextTokenId = await publicClient.readContract({
4137
4248
  address: contractAddress,
4138
4249
  abi: zoraCreator1155ImplABI3,
4139
4250
  functionName: "nextTokenId"
4140
- }) : 1n;
4251
+ });
4252
+ const contractName = await publicClient.readContract({
4253
+ address: contractAddress,
4254
+ abi: zoraCreator1155ImplABI3,
4255
+ functionName: "name"
4256
+ });
4141
4257
  return {
4142
- contractExists,
4143
- contractAddress,
4144
4258
  contractVersion,
4259
+ contractName,
4145
4260
  nextTokenId
4146
4261
  };
4147
4262
  }
4148
-
4149
- // src/create/token-setup.ts
4150
- var semver3 = __toESM(require_semver2(), 1);
4151
- import {
4152
- erc20MinterABI as erc20MinterABI2,
4153
- erc20MinterAddress as erc20MinterAddresses,
4154
- zoraCreator1155ImplABI as zoraCreator1155ImplABI4,
4155
- zoraCreatorFixedPriceSaleStrategyABI,
4156
- zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
4157
- } from "@zoralabs/protocol-deployments";
4158
- import { encodeFunctionData, zeroAddress as zeroAddress5 } from "viem";
4159
- var PERMISSION_BITS = {
4160
- MINTER: 2n ** 2n
4161
- };
4162
- var saleSettingsOrDefault = (saleSettings) => {
4163
- const SALE_END_FOREVER = 18446744073709551615n;
4164
- const DEFAULT_SALE_SETTINGS = {
4165
- currency: zeroAddress5,
4166
- // Free Mint
4167
- pricePerToken: 0n,
4168
- // Sale start time – defaults to beginning of unix time
4169
- saleStart: 0n,
4170
- // This is the end of uint64, plenty of time
4171
- saleEnd: SALE_END_FOREVER,
4172
- // 0 Here means no limit
4173
- maxTokensPerAddress: 0n
4174
- };
4175
- return {
4176
- ...DEFAULT_SALE_SETTINGS,
4177
- ...saleSettings
4178
- };
4179
- };
4180
- function applyNew1155Defaults(props, ownerAddress) {
4181
- const { payoutRecipient: fundsRecipient } = props;
4182
- const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== zeroAddress5 ? fundsRecipient : ownerAddress;
4183
- return {
4184
- payoutRecipient: fundsRecipientOrOwner,
4185
- createReferral: props.createReferral || zeroAddress5,
4186
- maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
4187
- royaltyBPS: props.royaltyBPS || 1e3,
4188
- salesConfig: saleSettingsOrDefault(props.salesConfig),
4189
- tokenMetadataURI: props.tokenMetadataURI
4190
- };
4191
- }
4192
- function setupErc20Minter({
4193
- pricePerToken,
4194
- chainId,
4195
- tokenId: nextTokenId,
4196
- currency,
4197
- saleStart,
4198
- saleEnd,
4199
- maxTokensPerAddress: mintLimit,
4200
- fundsRecipient
4263
+ async function getDeterministicContractAddress({
4264
+ publicClient,
4265
+ account,
4266
+ setupActions,
4267
+ contract,
4268
+ chainId
4201
4269
  }) {
4202
- const erc20MinterAddress = erc20MinterAddresses[chainId];
4203
- if (!erc20MinterAddress)
4204
- throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
4205
- const erc20MinterApproval = encodeFunctionData({
4206
- abi: zoraCreator1155ImplABI4,
4207
- functionName: "addPermission",
4208
- args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
4209
- });
4210
- const saleData = encodeFunctionData({
4211
- abi: erc20MinterABI2,
4212
- functionName: "setSale",
4270
+ const contractAddress = await publicClient.readContract({
4271
+ abi: zoraCreator1155FactoryImplABI,
4272
+ address: zoraCreator1155FactoryImplAddress[chainId],
4273
+ functionName: "deterministicContractAddressWithSetupActions",
4213
4274
  args: [
4214
- BigInt(nextTokenId),
4215
- {
4216
- saleStart: saleStart || BigInt(0),
4217
- saleEnd: saleEnd || BigInt(0),
4218
- maxTokensPerAddress: BigInt(mintLimit || 0),
4219
- pricePerToken,
4220
- fundsRecipient,
4221
- currency
4222
- }
4275
+ account,
4276
+ contract.uri,
4277
+ contract.name,
4278
+ contract.defaultAdmin || account,
4279
+ setupActions
4223
4280
  ]
4224
4281
  });
4225
- const callSale = encodeFunctionData({
4226
- abi: zoraCreator1155ImplABI4,
4227
- functionName: "callSale",
4228
- args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
4229
- });
4230
- return {
4231
- minter: erc20MinterAddress,
4232
- setupActions: [erc20MinterApproval, callSale]
4233
- };
4282
+ return contractAddress;
4234
4283
  }
4235
- function setupFixedPriceMinter({
4236
- pricePerToken: price,
4237
- tokenId: nextTokenId,
4238
- chainId,
4239
- saleStart,
4240
- saleEnd,
4241
- maxTokensPerAddress: mintLimit,
4242
- fundsRecipient
4243
- }) {
4244
- const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress2[chainId];
4245
- const fixedPriceApproval = encodeFunctionData({
4246
- abi: zoraCreator1155ImplABI4,
4247
- functionName: "addPermission",
4248
- args: [
4249
- BigInt(nextTokenId),
4250
- fixedPriceStrategyAddress,
4251
- PERMISSION_BITS.MINTER
4252
- ]
4253
- });
4254
- const saleData = encodeFunctionData({
4255
- abi: zoraCreatorFixedPriceSaleStrategyABI,
4256
- functionName: "setSale",
4257
- args: [
4258
- BigInt(nextTokenId),
4259
- {
4260
- pricePerToken: price,
4261
- saleStart: saleStart || BigInt(0),
4262
- saleEnd: saleEnd || BigInt(0),
4263
- maxTokensPerAddress: BigInt(mintLimit || 0),
4264
- fundsRecipient
4265
- }
4266
- ]
4267
- });
4268
- const callSale = encodeFunctionData({
4269
- abi: zoraCreator1155ImplABI4,
4270
- functionName: "callSale",
4271
- args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
4272
- });
4273
- return {
4274
- minter: fixedPriceStrategyAddress,
4275
- setupActions: [fixedPriceApproval, callSale]
4276
- };
4277
- }
4278
- function setupMinters({ salesConfig, ...rest }) {
4279
- if (!salesConfig)
4280
- throw new Error("No sales config for token");
4281
- const { currency: currencyAddress } = salesConfig;
4282
- if (currencyAddress === zeroAddress5) {
4283
- return setupFixedPriceMinter({
4284
- ...salesConfig,
4285
- ...rest
4286
- });
4287
- } else {
4288
- return setupErc20Minter({
4289
- ...salesConfig,
4290
- ...rest
4291
- });
4292
- }
4284
+
4285
+ // src/create/token-setup.ts
4286
+ var semver2 = __toESM(require_semver2(), 1);
4287
+ import { zoraCreator1155ImplABI as zoraCreator1155ImplABI5 } from "@zoralabs/protocol-deployments";
4288
+ import { encodeFunctionData as encodeFunctionData2, zeroAddress as zeroAddress5 } from "viem";
4289
+
4290
+ // src/ipfs/arweave.ts
4291
+ function isArweaveURL(url) {
4292
+ return url && typeof url === "string" ? url.startsWith("ar://") : false;
4293
4293
  }
4294
- function buildSetupNewToken({
4295
- tokenURI,
4296
- maxSupply = OPEN_EDITION_MINT_SIZE,
4297
- createReferral = zeroAddress5,
4298
- contractVersion
4299
- }) {
4300
- if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
4301
- return encodeFunctionData({
4302
- abi: zoraCreator1155ImplABI4,
4303
- functionName: "setupNewTokenWithCreateReferral",
4304
- args: [tokenURI, BigInt(maxSupply), createReferral]
4305
- });
4294
+
4295
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
4296
+ var empty = new Uint8Array(0);
4297
+ function equals(aa, bb) {
4298
+ if (aa === bb)
4299
+ return true;
4300
+ if (aa.byteLength !== bb.byteLength) {
4301
+ return false;
4306
4302
  }
4307
- if (createReferral !== zeroAddress5) {
4308
- throw new Error(
4309
- "Contract does not support create referral, but one was provided"
4310
- );
4303
+ for (let ii = 0; ii < aa.byteLength; ii++) {
4304
+ if (aa[ii] !== bb[ii]) {
4305
+ return false;
4306
+ }
4311
4307
  }
4312
- return encodeFunctionData({
4313
- abi: zoraCreator1155ImplABI4,
4314
- functionName: "setupNewToken",
4315
- args: [tokenURI, BigInt(maxSupply)]
4316
- });
4308
+ return true;
4317
4309
  }
4318
- function setupRoyaltyConfig({
4319
- royaltyBPS,
4320
- royaltyRecipient,
4321
- nextTokenId
4322
- }) {
4323
- if (royaltyBPS > 0 && royaltyRecipient != zeroAddress5) {
4324
- return encodeFunctionData({
4325
- abi: zoraCreator1155ImplABI4,
4326
- functionName: "updateRoyaltiesForToken",
4327
- args: [
4328
- nextTokenId,
4329
- {
4330
- royaltyBPS,
4331
- royaltyRecipient,
4332
- royaltyMintSchedule: 0
4333
- }
4334
- ]
4335
- });
4310
+ function coerce2(o) {
4311
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
4312
+ return o;
4313
+ if (o instanceof ArrayBuffer)
4314
+ return new Uint8Array(o);
4315
+ if (ArrayBuffer.isView(o)) {
4316
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
4336
4317
  }
4337
- return null;
4318
+ throw new Error("Unknown type, must be binary type");
4338
4319
  }
4339
- function makeAdminMintCall({
4340
- ownerAddress,
4341
- mintQuantity,
4342
- nextTokenId
4343
- }) {
4344
- if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
4345
- return null;
4320
+
4321
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
4322
+ function base2(ALPHABET, name) {
4323
+ if (ALPHABET.length >= 255) {
4324
+ throw new TypeError("Alphabet too long");
4346
4325
  }
4347
- return encodeFunctionData({
4348
- abi: zoraCreator1155ImplABI4,
4349
- functionName: "adminMint",
4350
- args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
4351
- });
4352
- }
4353
- function constructCreate1155TokenCalls(props) {
4354
- const {
4355
- chainId,
4356
- nextTokenId,
4357
- mintToCreatorCount,
4358
- ownerAddress,
4359
- contractVersion
4360
- } = props;
4361
- const new1155TokenPropsWithDefaults = applyNew1155Defaults(
4362
- props,
4363
- ownerAddress
4364
- );
4365
- const verifyTokenIdExpected = encodeFunctionData({
4366
- abi: zoraCreator1155ImplABI4,
4367
- functionName: "assumeLastTokenIdMatches",
4368
- args: [nextTokenId - 1n]
4369
- });
4370
- const setupNewToken = buildSetupNewToken({
4371
- tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
4372
- maxSupply: new1155TokenPropsWithDefaults.maxSupply,
4373
- createReferral: new1155TokenPropsWithDefaults.createReferral,
4374
- contractVersion
4375
- });
4376
- const royaltyConfig = setupRoyaltyConfig({
4377
- royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
4378
- royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
4379
- nextTokenId
4380
- });
4381
- const { minter, setupActions: mintersSetup } = setupMinters({
4382
- tokenId: nextTokenId,
4383
- chainId,
4384
- fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
4385
- salesConfig: new1155TokenPropsWithDefaults.salesConfig
4386
- });
4387
- const adminMintCall = makeAdminMintCall({
4388
- ownerAddress,
4389
- mintQuantity: mintToCreatorCount,
4390
- nextTokenId
4391
- });
4392
- const setupActions = [
4393
- verifyTokenIdExpected,
4394
- setupNewToken,
4395
- ...mintersSetup,
4396
- royaltyConfig,
4397
- adminMintCall
4398
- ].filter((item) => item !== null);
4399
- return {
4400
- setupActions,
4401
- minter,
4402
- newToken: new1155TokenPropsWithDefaults
4403
- };
4404
- }
4405
- var contractSupportsMintRewards = (contractVersion, contractStandard) => {
4406
- if (!contractStandard || !contractVersion) {
4407
- return false;
4326
+ var BASE_MAP = new Uint8Array(256);
4327
+ for (var j = 0; j < BASE_MAP.length; j++) {
4328
+ BASE_MAP[j] = 255;
4408
4329
  }
4409
- const semVerContractVersion = semver3.coerce(contractVersion)?.raw;
4410
- if (!semVerContractVersion)
4411
- return false;
4412
- if (contractStandard === "ERC1155") {
4413
- return semver3.gte(semVerContractVersion, "1.3.5");
4414
- } else {
4415
- return semver3.gte(semVerContractVersion, "14.0.0");
4330
+ for (var i = 0; i < ALPHABET.length; i++) {
4331
+ var x = ALPHABET.charAt(i);
4332
+ var xc = x.charCodeAt(0);
4333
+ if (BASE_MAP[xc] !== 255) {
4334
+ throw new TypeError(x + " is ambiguous");
4335
+ }
4336
+ BASE_MAP[xc] = i;
4416
4337
  }
4417
- };
4418
-
4419
- // src/create/1155-create-helper.ts
4420
- var ROYALTY_BPS_DEFAULT = 1e3;
4421
- var getTokenIdFromCreateReceipt = (receipt) => {
4422
- for (const data of receipt.logs) {
4423
- try {
4424
- const decodedLog = decodeEventLog2({
4425
- abi: zoraCreator1155ImplABI5,
4426
- eventName: "SetupNewToken",
4427
- ...data
4428
- });
4429
- if (decodedLog && decodedLog.eventName === "SetupNewToken") {
4430
- return decodedLog.args.tokenId;
4338
+ var BASE = ALPHABET.length;
4339
+ var LEADER = ALPHABET.charAt(0);
4340
+ var FACTOR = Math.log(BASE) / Math.log(256);
4341
+ var iFACTOR = Math.log(256) / Math.log(BASE);
4342
+ function encode3(source) {
4343
+ if (source instanceof Uint8Array)
4344
+ ;
4345
+ else if (ArrayBuffer.isView(source)) {
4346
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
4347
+ } else if (Array.isArray(source)) {
4348
+ source = Uint8Array.from(source);
4349
+ }
4350
+ if (!(source instanceof Uint8Array)) {
4351
+ throw new TypeError("Expected Uint8Array");
4352
+ }
4353
+ if (source.length === 0) {
4354
+ return "";
4355
+ }
4356
+ var zeroes = 0;
4357
+ var length2 = 0;
4358
+ var pbegin = 0;
4359
+ var pend = source.length;
4360
+ while (pbegin !== pend && source[pbegin] === 0) {
4361
+ pbegin++;
4362
+ zeroes++;
4363
+ }
4364
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
4365
+ var b58 = new Uint8Array(size);
4366
+ while (pbegin !== pend) {
4367
+ var carry = source[pbegin];
4368
+ var i2 = 0;
4369
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
4370
+ carry += 256 * b58[it1] >>> 0;
4371
+ b58[it1] = carry % BASE >>> 0;
4372
+ carry = carry / BASE >>> 0;
4431
4373
  }
4432
- } catch (err) {
4374
+ if (carry !== 0) {
4375
+ throw new Error("Non-zero carry");
4376
+ }
4377
+ length2 = i2;
4378
+ pbegin++;
4379
+ }
4380
+ var it2 = size - length2;
4381
+ while (it2 !== size && b58[it2] === 0) {
4382
+ it2++;
4383
+ }
4384
+ var str = LEADER.repeat(zeroes);
4385
+ for (; it2 < size; ++it2) {
4386
+ str += ALPHABET.charAt(b58[it2]);
4433
4387
  }
4388
+ return str;
4434
4389
  }
4435
- };
4436
- function makeCreateContractAndTokenCall({
4437
- contractExists,
4438
- contractAddress,
4439
- contract,
4440
- account,
4441
- royaltyBPS,
4442
- tokenSetupActions,
4443
- fundsRecipient
4444
- }) {
4445
- if (!contractAddress && typeof contract === "string") {
4446
- throw new Error("Invariant: contract cannot be missing and an address");
4447
- }
4448
- if (!contractExists) {
4449
- if (typeof contract === "string") {
4450
- throw new Error("Invariant: expected contract object");
4390
+ function decodeUnsafe(source) {
4391
+ if (typeof source !== "string") {
4392
+ throw new TypeError("Expected String");
4451
4393
  }
4452
- const accountAddress = typeof account === "string" ? account : account.address;
4453
- return makeContractParameters({
4454
- abi: zoraCreator1155FactoryImplABI2,
4455
- functionName: "createContractDeterministic",
4456
- account,
4457
- address: zoraCreator1155FactoryImplAddress2[999],
4458
- args: [
4459
- contract.uri,
4460
- contract.name,
4461
- {
4462
- // deprecated
4463
- royaltyMintSchedule: 0,
4464
- royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
4465
- royaltyRecipient: fundsRecipient || accountAddress
4466
- },
4467
- contract.defaultAdmin || accountAddress,
4468
- tokenSetupActions
4469
- ]
4470
- });
4471
- }
4472
- return makeContractParameters({
4473
- abi: zoraCreator1155ImplABI5,
4474
- functionName: "multicall",
4475
- account,
4476
- address: contractAddress,
4477
- args: [tokenSetupActions]
4478
- });
4479
- }
4480
- var Create1155Client = class {
4481
- constructor({
4482
- chainId,
4483
- publicClient
4484
- }) {
4485
- this.chainId = chainId;
4486
- this.publicClient = publicClient;
4394
+ if (source.length === 0) {
4395
+ return new Uint8Array();
4396
+ }
4397
+ var psz = 0;
4398
+ if (source[psz] === " ") {
4399
+ return;
4400
+ }
4401
+ var zeroes = 0;
4402
+ var length2 = 0;
4403
+ while (source[psz] === LEADER) {
4404
+ zeroes++;
4405
+ psz++;
4406
+ }
4407
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
4408
+ var b256 = new Uint8Array(size);
4409
+ while (source[psz]) {
4410
+ var carry = BASE_MAP[source.charCodeAt(psz)];
4411
+ if (carry === 255) {
4412
+ return;
4413
+ }
4414
+ var i2 = 0;
4415
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
4416
+ carry += BASE * b256[it3] >>> 0;
4417
+ b256[it3] = carry % 256 >>> 0;
4418
+ carry = carry / 256 >>> 0;
4419
+ }
4420
+ if (carry !== 0) {
4421
+ throw new Error("Non-zero carry");
4422
+ }
4423
+ length2 = i2;
4424
+ psz++;
4425
+ }
4426
+ if (source[psz] === " ") {
4427
+ return;
4428
+ }
4429
+ var it4 = size - length2;
4430
+ while (it4 !== size && b256[it4] === 0) {
4431
+ it4++;
4432
+ }
4433
+ var vch = new Uint8Array(zeroes + (size - it4));
4434
+ var j2 = zeroes;
4435
+ while (it4 !== size) {
4436
+ vch[j2++] = b256[it4++];
4437
+ }
4438
+ return vch;
4487
4439
  }
4488
- async createNew1155Token(props) {
4489
- return createNew1155Token({
4490
- ...props,
4491
- publicClient: this.publicClient,
4492
- chainId: this.chainId
4493
- });
4440
+ function decode5(string) {
4441
+ var buffer = decodeUnsafe(string);
4442
+ if (buffer) {
4443
+ return buffer;
4444
+ }
4445
+ throw new Error(`Non-${name} character`);
4494
4446
  }
4495
- };
4496
- async function createNew1155Token({
4497
- contract,
4498
- account,
4499
- getAdditionalSetupActions,
4500
- token: tokenConfig,
4501
- publicClient,
4502
- chainId
4503
- }) {
4504
- const { contractExists, contractAddress, nextTokenId, contractVersion } = await getContractInfo({
4505
- publicClient,
4506
- chainId,
4507
- contract,
4508
- account
4509
- });
4510
- const {
4511
- minter,
4512
- newToken,
4513
- setupActions: tokenSetupActions
4514
- } = constructCreate1155TokenCalls({
4515
- chainId,
4516
- ownerAddress: account,
4517
- contractVersion,
4518
- nextTokenId,
4519
- ...tokenConfig
4520
- });
4521
- const setupActions = getAdditionalSetupActions ? [
4522
- ...getAdditionalSetupActions({
4523
- tokenId: nextTokenId,
4524
- contractAddress
4525
- }),
4526
- ...tokenSetupActions
4527
- ] : tokenSetupActions;
4528
- const request = makeCreateContractAndTokenCall({
4529
- contractExists,
4530
- contractAddress,
4531
- contract,
4532
- account,
4533
- tokenSetupActions: setupActions,
4534
- royaltyBPS: tokenConfig.royaltyBPS,
4535
- fundsRecipient: tokenConfig.payoutRecipient
4536
- });
4537
4447
  return {
4538
- parameters: request,
4539
- tokenSetupActions,
4540
- collectionAddress: contractAddress,
4541
- contractExists,
4542
- newTokenId: nextTokenId,
4543
- newToken,
4544
- minter
4448
+ encode: encode3,
4449
+ decodeUnsafe,
4450
+ decode: decode5
4545
4451
  };
4546
4452
  }
4453
+ var src = base2;
4454
+ var _brrp__multiformats_scope_baseX = src;
4455
+ var base_x_default = _brrp__multiformats_scope_baseX;
4547
4456
 
4548
- // src/sparks/mints-queries.ts
4549
- var getMintsAccountBalanceWithPriceQuery = (account) => {
4550
- const query = `
4551
- query GetMintAccountBalances($account: String!) {
4552
- mintAccountBalances(where: { account: $account }) {
4553
- balance
4554
- mintToken {
4555
- id
4556
- pricePerToken
4557
- }
4558
- }
4457
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
4458
+ var Encoder = class {
4459
+ constructor(name, prefix, baseEncode) {
4460
+ __publicField(this, "name");
4461
+ __publicField(this, "prefix");
4462
+ __publicField(this, "baseEncode");
4463
+ this.name = name;
4464
+ this.prefix = prefix;
4465
+ this.baseEncode = baseEncode;
4466
+ }
4467
+ encode(bytes) {
4468
+ if (bytes instanceof Uint8Array) {
4469
+ return `${this.prefix}${this.baseEncode(bytes)}`;
4470
+ } else {
4471
+ throw Error("Unknown type, must be binary type");
4559
4472
  }
4560
- `;
4561
- return {
4562
- query,
4563
- variables: { account }
4564
- };
4473
+ }
4565
4474
  };
4566
- var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
4567
- const parsed = mintAccountBalances.map((r) => {
4568
- return {
4569
- tokenId: BigInt(r.mintToken.id),
4570
- quantity: BigInt(r.balance),
4571
- pricePerToken: BigInt(r.mintToken.pricePerToken)
4572
- };
4573
- });
4574
- const sorted = parsed.sort((a, b) => {
4575
- if (a.pricePerToken < b.pricePerToken) {
4576
- return -1;
4475
+ var Decoder = class {
4476
+ constructor(name, prefix, baseDecode) {
4477
+ __publicField(this, "name");
4478
+ __publicField(this, "prefix");
4479
+ __publicField(this, "baseDecode");
4480
+ __publicField(this, "prefixCodePoint");
4481
+ this.name = name;
4482
+ this.prefix = prefix;
4483
+ if (prefix.codePointAt(0) === void 0) {
4484
+ throw new Error("Invalid prefix character");
4577
4485
  }
4578
- return 1;
4579
- });
4580
- let remainingQuantity = quantityToCollect;
4581
- const tokenIds = [];
4582
- const quantities = [];
4583
- while (remainingQuantity > 0) {
4584
- const next = sorted.shift();
4585
- if (!next) {
4586
- throw new Error("Not enough MINTs to collect with");
4486
+ this.prefixCodePoint = prefix.codePointAt(0);
4487
+ this.baseDecode = baseDecode;
4488
+ }
4489
+ decode(text) {
4490
+ if (typeof text === "string") {
4491
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
4492
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
4493
+ }
4494
+ return this.baseDecode(text.slice(this.prefix.length));
4495
+ } else {
4496
+ throw Error("Can only multibase decode strings");
4587
4497
  }
4588
- const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
4589
- tokenIds.push(next.tokenId);
4590
- quantities.push(quantityToUse);
4591
- remainingQuantity -= quantityToUse;
4592
4498
  }
4593
- return {
4594
- tokenIds,
4595
- quantities
4596
- };
4499
+ or(decoder) {
4500
+ return or(this, decoder);
4501
+ }
4597
4502
  };
4598
- var sumBalances = (mintAccountBalances) => {
4599
- return mintAccountBalances.reduce((acc, curr) => {
4600
- return acc + BigInt(curr.balance);
4601
- }, BigInt(0));
4503
+ var ComposedDecoder = class {
4504
+ constructor(decoders) {
4505
+ __publicField(this, "decoders");
4506
+ this.decoders = decoders;
4507
+ }
4508
+ or(decoder) {
4509
+ return or(this, decoder);
4510
+ }
4511
+ decode(input) {
4512
+ const prefix = input[0];
4513
+ const decoder = this.decoders[prefix];
4514
+ if (decoder != null) {
4515
+ return decoder.decode(input);
4516
+ } else {
4517
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
4518
+ }
4519
+ }
4602
4520
  };
4603
-
4604
- // src/sparks/sparks-contracts.ts
4605
- import {
4606
- mintsSafeTransferBatchTypedDataDefinition,
4607
- mintsSafeTransferTypedDataDefinition,
4608
- zoraMints1155Config,
4609
- zoraMintsManagerImplABI,
4610
- zoraMintsManagerImplAddress,
4611
- zoraMintsManagerImplConfig,
4612
- zoraSparksManagerImplABI,
4613
- zoraSparksManagerImplAddress
4614
- } from "@zoralabs/protocol-deployments";
4615
- import {
4616
- decodeErrorResult,
4617
- encodeFunctionData as encodeFunctionData2,
4618
- zeroAddress as zeroAddress6
4619
- } from "viem";
4620
- var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
4621
- var mintWithEthParams = ({
4622
- tokenId,
4623
- quantity,
4624
- recipient,
4625
- chainId,
4626
- pricePerMint,
4627
- account
4628
- }) => makeContractParameters({
4629
- abi: zoraSparksManagerImplABI,
4630
- address: zoraSparksManagerImplAddress[chainId],
4631
- functionName: "mintWithEth",
4632
- args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
4633
- value: pricePerMint * quantity,
4634
- account
4635
- });
4636
- var getPaidMintValue = (quantities, pricePerMint) => {
4637
- if (!pricePerMint || pricePerMint === 0n)
4638
- return;
4639
- return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
4640
- };
4641
- var mintsBalanceOfAccountParams = ({
4642
- account,
4643
- chainId
4644
- }) => ({
4645
- abi: zoraMints1155Config.abi,
4646
- address: zoraMints1155Config.address[chainId],
4647
- functionName: "balanceOfAccount",
4648
- args: [account]
4649
- });
4650
- var encodeCollectOnManager = ({
4651
- zoraCreator1155Contract,
4652
- minter,
4653
- zoraCreator1155TokenId,
4654
- mintArguments
4655
- }) => encodeFunctionData2({
4656
- abi: zoraMintsManagerImplConfig.abi,
4657
- functionName: "collect",
4658
- args: [
4659
- zoraCreator1155Contract,
4660
- minter,
4661
- zoraCreator1155TokenId,
4662
- mintArguments
4663
- ]
4664
- });
4665
- function collectWithMintsParams({
4666
- tokenIds,
4667
- quantities,
4668
- chainId,
4669
- paidMintPricePerToken,
4670
- account,
4671
- mintArguments,
4672
- minter,
4673
- zoraCreator1155Contract,
4674
- zoraCreator1155TokenId
4675
- }) {
4676
- const call = encodeCollectOnManager({
4677
- tokenIds,
4678
- quantities,
4679
- zoraCreator1155Contract,
4680
- zoraCreator1155TokenId,
4681
- minter,
4682
- mintArguments
4683
- });
4684
- return makeContractParameters({
4685
- abi: zoraMints1155Config.abi,
4686
- address: zoraMints1155Config.address[chainId],
4687
- functionName: "transferBatchToManagerAndCall",
4688
- args: [tokenIds, quantities, call],
4689
- // if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
4690
- // for the paid mint cost.
4691
- value: getPaidMintValue(quantities, paidMintPricePerToken),
4692
- account
4521
+ function or(left, right) {
4522
+ return new ComposedDecoder({
4523
+ ...left.decoders ?? { [left.prefix]: left },
4524
+ ...right.decoders ?? { [right.prefix]: right }
4693
4525
  });
4694
4526
  }
4695
- function getMintsEthPrice({
4696
- publicClient
4697
- }) {
4698
- const chainId = publicClient.chain?.id;
4699
- if (!chainId || !zoraMintsManagerImplAddress[chainId]) {
4700
- throw new Error(`Chain id ${chainId} not supported`);
4527
+ var Codec = class {
4528
+ constructor(name, prefix, baseEncode, baseDecode) {
4529
+ __publicField(this, "name");
4530
+ __publicField(this, "prefix");
4531
+ __publicField(this, "baseEncode");
4532
+ __publicField(this, "baseDecode");
4533
+ __publicField(this, "encoder");
4534
+ __publicField(this, "decoder");
4535
+ this.name = name;
4536
+ this.prefix = prefix;
4537
+ this.baseEncode = baseEncode;
4538
+ this.baseDecode = baseDecode;
4539
+ this.encoder = new Encoder(name, prefix, baseEncode);
4540
+ this.decoder = new Decoder(name, prefix, baseDecode);
4701
4541
  }
4702
- return publicClient.readContract({
4703
- abi: zoraMintsManagerImplABI,
4704
- address: zoraMintsManagerImplAddress[chainId],
4705
- functionName: "getEthPrice"
4706
- });
4707
- }
4708
- function makePermitTransferBatchAndTypeData({
4709
- tokenIds,
4710
- quantities,
4711
- chainId,
4712
- mintsOwner,
4713
- to,
4714
- nonce,
4715
- deadline,
4716
- safeTransferData
4717
- }) {
4718
- const permit = {
4719
- owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
4720
- to,
4721
- tokenIds,
4722
- quantities,
4723
- deadline,
4724
- nonce,
4725
- safeTransferData
4726
- };
4727
- const typedData = {
4728
- ...mintsSafeTransferBatchTypedDataDefinition({
4729
- chainId,
4730
- message: permit
4731
- }),
4732
- account: mintsOwner
4733
- };
4734
- return {
4735
- permit,
4736
- typedData
4737
- };
4738
- }
4739
- function makePermitTransferTypeData({
4740
- tokenId,
4741
- quantity,
4742
- chainId,
4743
- mintsOwner,
4744
- to,
4745
- nonce,
4746
- deadline,
4747
- safeTransferData
4748
- }) {
4749
- const permit = {
4750
- owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
4751
- to,
4752
- tokenId,
4753
- quantity,
4754
- deadline,
4755
- nonce,
4756
- safeTransferData
4757
- };
4758
- const typedData = {
4759
- ...mintsSafeTransferTypedDataDefinition({
4760
- chainId,
4761
- message: permit
4762
- }),
4763
- account: mintsOwner
4764
- };
4765
- return {
4766
- permit,
4767
- typedData
4768
- };
4769
- }
4770
- var encodePremintOnManager = ({
4771
- contractCreationConfig,
4772
- premintConfig,
4773
- premintSignature,
4774
- mintArguments,
4775
- signerContract = zeroAddress6
4776
- }) => encodeFunctionData2({
4777
- abi: zoraMintsManagerImplConfig.abi,
4778
- functionName: "collectPremintV2",
4779
- args: [
4780
- contractCreationConfig,
4781
- premintConfig,
4782
- premintSignature,
4783
- mintArguments,
4784
- signerContract
4785
- ]
4786
- });
4787
- var makePermitToCollectPremintOrNonPremint = ({
4788
- mintsOwner,
4789
- chainId,
4790
- deadline,
4791
- tokenIds,
4792
- // this quantity of MINTs will be used to collect premint
4793
- // and will be burned. This same quantity is the quantity of
4794
- // premint to collect.
4795
- quantities,
4796
- nonce,
4797
- premint,
4798
- collect
4799
- }) => {
4800
- let safeTransferData;
4801
- if (premint) {
4802
- safeTransferData = encodePremintOnManager(premint);
4803
- } else if (collect) {
4804
- safeTransferData = encodeCollectOnManager(collect);
4805
- } else {
4806
- throw new Error("Invalid operation");
4542
+ encode(input) {
4543
+ return this.encoder.encode(input);
4544
+ }
4545
+ decode(input) {
4546
+ return this.decoder.decode(input);
4807
4547
  }
4808
- return makePermitTransferBatchAndTypeData({
4809
- tokenIds,
4810
- quantities,
4811
- chainId,
4812
- mintsOwner,
4813
- nonce,
4814
- deadline,
4815
- safeTransferData,
4816
- to: zoraMintsManagerImplConfig.address[chainId]
4817
- });
4818
4548
  };
4819
- function collectPremintV2WithMintsParams({
4820
- tokenIds,
4821
- quantities,
4822
- paidMintPricePerToken,
4823
- account,
4824
- chainId,
4825
- ...rest
4826
- }) {
4827
- const call = encodePremintOnManager({
4828
- ...rest
4829
- });
4830
- return makeContractParameters({
4831
- abi: zoraMints1155Config.abi,
4832
- address: zoraMints1155Config.address[chainId],
4833
- functionName: "transferBatchToManagerAndCall",
4834
- args: [tokenIds, quantities, call],
4835
- value: getPaidMintValue(quantities, paidMintPricePerToken),
4836
- account
4837
- });
4549
+ function from({ name, prefix, encode: encode3, decode: decode5 }) {
4550
+ return new Codec(name, prefix, encode3, decode5);
4838
4551
  }
4839
- function decodeCallFailedError(error) {
4840
- if (error.data?.errorName !== "CallFailed")
4841
- throw new Error("Not a CallFailed error");
4842
- const internalErrorData = error.data?.args?.[0];
4843
- return decodeErrorResult({
4844
- abi: zoraMintsManagerImplABI,
4845
- data: internalErrorData
4552
+ function baseX({ name, prefix, alphabet }) {
4553
+ const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
4554
+ return from({
4555
+ prefix,
4556
+ name,
4557
+ encode: encode3,
4558
+ decode: (text) => coerce2(decode5(text))
4846
4559
  });
4847
4560
  }
4848
-
4849
- // src/sdk.ts
4850
- function createCreatorClient(clientConfig) {
4851
- const premintClient = new PremintClient({
4852
- chainId: clientConfig.chainId,
4853
- publicClient: clientConfig.publicClient,
4854
- premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
4855
- });
4856
- const create1155CreatorClient = new Create1155Client({
4857
- chainId: clientConfig.chainId,
4858
- publicClient: clientConfig.publicClient
4859
- });
4860
- return {
4861
- createPremint: (p) => premintClient.createPremint(p),
4862
- updatePremint: (p) => premintClient.updatePremint(p),
4863
- deletePremint: (p) => premintClient.deletePremint(p),
4864
- create1155: (p) => create1155CreatorClient.createNew1155Token(p)
4865
- };
4866
- }
4867
- function createCollectorClient(params) {
4868
- const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
4869
- const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
4870
- const mintClient = new MintClient({
4871
- publicClient: params.publicClient,
4872
- premintGetter: premintGetterToUse,
4873
- mintGetter: mintGetterToUse
4874
- });
4875
- return {
4876
- getPremint: (p) => premintGetterToUse.get({
4877
- collectionAddress: p.address,
4878
- uid: p.uid
4879
- }),
4880
- getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
4881
- getToken: (p) => mintClient.get(p),
4882
- getTokensOfContract: (p) => mintClient.getOfContract(p),
4883
- mint: (p) => mintClient.mint(p),
4884
- getMintCosts: (p) => mintClient.getMintCosts(p)
4885
- };
4886
- }
4887
-
4888
- // src/ipfs/arweave.ts
4889
- function isArweaveURL(url) {
4890
- return url && typeof url === "string" ? url.startsWith("ar://") : false;
4891
- }
4892
-
4893
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
4894
- var empty = new Uint8Array(0);
4895
- function equals(aa, bb) {
4896
- if (aa === bb)
4897
- return true;
4898
- if (aa.byteLength !== bb.byteLength) {
4899
- return false;
4561
+ function decode(string, alphabet, bitsPerChar, name) {
4562
+ const codes = {};
4563
+ for (let i = 0; i < alphabet.length; ++i) {
4564
+ codes[alphabet[i]] = i;
4900
4565
  }
4901
- for (let ii = 0; ii < aa.byteLength; ii++) {
4902
- if (aa[ii] !== bb[ii]) {
4903
- return false;
4566
+ let end = string.length;
4567
+ while (string[end - 1] === "=") {
4568
+ --end;
4569
+ }
4570
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
4571
+ let bits = 0;
4572
+ let buffer = 0;
4573
+ let written = 0;
4574
+ for (let i = 0; i < end; ++i) {
4575
+ const value = codes[string[i]];
4576
+ if (value === void 0) {
4577
+ throw new SyntaxError(`Non-${name} character`);
4578
+ }
4579
+ buffer = buffer << bitsPerChar | value;
4580
+ bits += bitsPerChar;
4581
+ if (bits >= 8) {
4582
+ bits -= 8;
4583
+ out[written++] = 255 & buffer >> bits;
4904
4584
  }
4905
4585
  }
4906
- return true;
4907
- }
4908
- function coerce4(o) {
4909
- if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
4910
- return o;
4911
- if (o instanceof ArrayBuffer)
4912
- return new Uint8Array(o);
4913
- if (ArrayBuffer.isView(o)) {
4914
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
4586
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
4587
+ throw new SyntaxError("Unexpected end of data");
4915
4588
  }
4916
- throw new Error("Unknown type, must be binary type");
4589
+ return out;
4917
4590
  }
4918
-
4919
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
4920
- function base2(ALPHABET, name) {
4921
- if (ALPHABET.length >= 255) {
4922
- throw new TypeError("Alphabet too long");
4923
- }
4924
- var BASE_MAP = new Uint8Array(256);
4925
- for (var j = 0; j < BASE_MAP.length; j++) {
4926
- BASE_MAP[j] = 255;
4927
- }
4928
- for (var i = 0; i < ALPHABET.length; i++) {
4929
- var x = ALPHABET.charAt(i);
4930
- var xc = x.charCodeAt(0);
4931
- if (BASE_MAP[xc] !== 255) {
4932
- throw new TypeError(x + " is ambiguous");
4591
+ function encode(data, alphabet, bitsPerChar) {
4592
+ const pad = alphabet[alphabet.length - 1] === "=";
4593
+ const mask = (1 << bitsPerChar) - 1;
4594
+ let out = "";
4595
+ let bits = 0;
4596
+ let buffer = 0;
4597
+ for (let i = 0; i < data.length; ++i) {
4598
+ buffer = buffer << 8 | data[i];
4599
+ bits += 8;
4600
+ while (bits > bitsPerChar) {
4601
+ bits -= bitsPerChar;
4602
+ out += alphabet[mask & buffer >> bits];
4933
4603
  }
4934
- BASE_MAP[xc] = i;
4935
4604
  }
4936
- var BASE = ALPHABET.length;
4937
- var LEADER = ALPHABET.charAt(0);
4938
- var FACTOR = Math.log(BASE) / Math.log(256);
4939
- var iFACTOR = Math.log(256) / Math.log(BASE);
4940
- function encode3(source) {
4941
- if (source instanceof Uint8Array)
4942
- ;
4943
- else if (ArrayBuffer.isView(source)) {
4944
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
4945
- } else if (Array.isArray(source)) {
4946
- source = Uint8Array.from(source);
4947
- }
4948
- if (!(source instanceof Uint8Array)) {
4949
- throw new TypeError("Expected Uint8Array");
4950
- }
4951
- if (source.length === 0) {
4952
- return "";
4953
- }
4954
- var zeroes = 0;
4955
- var length2 = 0;
4956
- var pbegin = 0;
4957
- var pend = source.length;
4958
- while (pbegin !== pend && source[pbegin] === 0) {
4959
- pbegin++;
4960
- zeroes++;
4961
- }
4962
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
4963
- var b58 = new Uint8Array(size);
4964
- while (pbegin !== pend) {
4965
- var carry = source[pbegin];
4966
- var i2 = 0;
4967
- for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
4968
- carry += 256 * b58[it1] >>> 0;
4969
- b58[it1] = carry % BASE >>> 0;
4970
- carry = carry / BASE >>> 0;
4971
- }
4972
- if (carry !== 0) {
4973
- throw new Error("Non-zero carry");
4974
- }
4975
- length2 = i2;
4976
- pbegin++;
4977
- }
4978
- var it2 = size - length2;
4979
- while (it2 !== size && b58[it2] === 0) {
4980
- it2++;
4981
- }
4982
- var str = LEADER.repeat(zeroes);
4983
- for (; it2 < size; ++it2) {
4984
- str += ALPHABET.charAt(b58[it2]);
4985
- }
4986
- return str;
4605
+ if (bits !== 0) {
4606
+ out += alphabet[mask & buffer << bitsPerChar - bits];
4987
4607
  }
4988
- function decodeUnsafe(source) {
4989
- if (typeof source !== "string") {
4990
- throw new TypeError("Expected String");
4991
- }
4992
- if (source.length === 0) {
4993
- return new Uint8Array();
4994
- }
4995
- var psz = 0;
4996
- if (source[psz] === " ") {
4997
- return;
4998
- }
4999
- var zeroes = 0;
5000
- var length2 = 0;
5001
- while (source[psz] === LEADER) {
5002
- zeroes++;
5003
- psz++;
5004
- }
5005
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
5006
- var b256 = new Uint8Array(size);
5007
- while (source[psz]) {
5008
- var carry = BASE_MAP[source.charCodeAt(psz)];
5009
- if (carry === 255) {
5010
- return;
5011
- }
5012
- var i2 = 0;
5013
- for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
5014
- carry += BASE * b256[it3] >>> 0;
5015
- b256[it3] = carry % 256 >>> 0;
5016
- carry = carry / 256 >>> 0;
5017
- }
5018
- if (carry !== 0) {
5019
- throw new Error("Non-zero carry");
5020
- }
5021
- length2 = i2;
5022
- psz++;
5023
- }
5024
- if (source[psz] === " ") {
5025
- return;
5026
- }
5027
- var it4 = size - length2;
5028
- while (it4 !== size && b256[it4] === 0) {
5029
- it4++;
5030
- }
5031
- var vch = new Uint8Array(zeroes + (size - it4));
5032
- var j2 = zeroes;
5033
- while (it4 !== size) {
5034
- vch[j2++] = b256[it4++];
4608
+ if (pad) {
4609
+ while ((out.length * bitsPerChar & 7) !== 0) {
4610
+ out += "=";
5035
4611
  }
5036
- return vch;
5037
4612
  }
5038
- function decode5(string) {
5039
- var buffer = decodeUnsafe(string);
5040
- if (buffer) {
5041
- return buffer;
4613
+ return out;
4614
+ }
4615
+ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
4616
+ return from({
4617
+ prefix,
4618
+ name,
4619
+ encode(input) {
4620
+ return encode(input, alphabet, bitsPerChar);
4621
+ },
4622
+ decode(input) {
4623
+ return decode(input, alphabet, bitsPerChar, name);
5042
4624
  }
5043
- throw new Error(`Non-${name} character`);
5044
- }
5045
- return {
5046
- encode: encode3,
5047
- decodeUnsafe,
5048
- decode: decode5
5049
- };
5050
- }
5051
- var src = base2;
5052
- var _brrp__multiformats_scope_baseX = src;
5053
- var base_x_default = _brrp__multiformats_scope_baseX;
5054
-
5055
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
5056
- var Encoder = class {
5057
- constructor(name, prefix, baseEncode) {
5058
- __publicField(this, "name");
5059
- __publicField(this, "prefix");
5060
- __publicField(this, "baseEncode");
5061
- this.name = name;
5062
- this.prefix = prefix;
5063
- this.baseEncode = baseEncode;
5064
- }
5065
- encode(bytes) {
5066
- if (bytes instanceof Uint8Array) {
5067
- return `${this.prefix}${this.baseEncode(bytes)}`;
5068
- } else {
5069
- throw Error("Unknown type, must be binary type");
5070
- }
5071
- }
5072
- };
5073
- var Decoder = class {
5074
- constructor(name, prefix, baseDecode) {
5075
- __publicField(this, "name");
5076
- __publicField(this, "prefix");
5077
- __publicField(this, "baseDecode");
5078
- __publicField(this, "prefixCodePoint");
5079
- this.name = name;
5080
- this.prefix = prefix;
5081
- if (prefix.codePointAt(0) === void 0) {
5082
- throw new Error("Invalid prefix character");
5083
- }
5084
- this.prefixCodePoint = prefix.codePointAt(0);
5085
- this.baseDecode = baseDecode;
5086
- }
5087
- decode(text) {
5088
- if (typeof text === "string") {
5089
- if (text.codePointAt(0) !== this.prefixCodePoint) {
5090
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
5091
- }
5092
- return this.baseDecode(text.slice(this.prefix.length));
5093
- } else {
5094
- throw Error("Can only multibase decode strings");
5095
- }
5096
- }
5097
- or(decoder) {
5098
- return or(this, decoder);
5099
- }
5100
- };
5101
- var ComposedDecoder = class {
5102
- constructor(decoders) {
5103
- __publicField(this, "decoders");
5104
- this.decoders = decoders;
5105
- }
5106
- or(decoder) {
5107
- return or(this, decoder);
5108
- }
5109
- decode(input) {
5110
- const prefix = input[0];
5111
- const decoder = this.decoders[prefix];
5112
- if (decoder != null) {
5113
- return decoder.decode(input);
5114
- } else {
5115
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
5116
- }
5117
- }
5118
- };
5119
- function or(left, right) {
5120
- return new ComposedDecoder({
5121
- ...left.decoders ?? { [left.prefix]: left },
5122
- ...right.decoders ?? { [right.prefix]: right }
5123
- });
5124
- }
5125
- var Codec = class {
5126
- constructor(name, prefix, baseEncode, baseDecode) {
5127
- __publicField(this, "name");
5128
- __publicField(this, "prefix");
5129
- __publicField(this, "baseEncode");
5130
- __publicField(this, "baseDecode");
5131
- __publicField(this, "encoder");
5132
- __publicField(this, "decoder");
5133
- this.name = name;
5134
- this.prefix = prefix;
5135
- this.baseEncode = baseEncode;
5136
- this.baseDecode = baseDecode;
5137
- this.encoder = new Encoder(name, prefix, baseEncode);
5138
- this.decoder = new Decoder(name, prefix, baseDecode);
5139
- }
5140
- encode(input) {
5141
- return this.encoder.encode(input);
5142
- }
5143
- decode(input) {
5144
- return this.decoder.decode(input);
5145
- }
5146
- };
5147
- function from({ name, prefix, encode: encode3, decode: decode5 }) {
5148
- return new Codec(name, prefix, encode3, decode5);
5149
- }
5150
- function baseX({ name, prefix, alphabet }) {
5151
- const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
5152
- return from({
5153
- prefix,
5154
- name,
5155
- encode: encode3,
5156
- decode: (text) => coerce4(decode5(text))
5157
- });
5158
- }
5159
- function decode(string, alphabet, bitsPerChar, name) {
5160
- const codes = {};
5161
- for (let i = 0; i < alphabet.length; ++i) {
5162
- codes[alphabet[i]] = i;
5163
- }
5164
- let end = string.length;
5165
- while (string[end - 1] === "=") {
5166
- --end;
5167
- }
5168
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
5169
- let bits = 0;
5170
- let buffer = 0;
5171
- let written = 0;
5172
- for (let i = 0; i < end; ++i) {
5173
- const value = codes[string[i]];
5174
- if (value === void 0) {
5175
- throw new SyntaxError(`Non-${name} character`);
5176
- }
5177
- buffer = buffer << bitsPerChar | value;
5178
- bits += bitsPerChar;
5179
- if (bits >= 8) {
5180
- bits -= 8;
5181
- out[written++] = 255 & buffer >> bits;
5182
- }
5183
- }
5184
- if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
5185
- throw new SyntaxError("Unexpected end of data");
5186
- }
5187
- return out;
5188
- }
5189
- function encode(data, alphabet, bitsPerChar) {
5190
- const pad = alphabet[alphabet.length - 1] === "=";
5191
- const mask = (1 << bitsPerChar) - 1;
5192
- let out = "";
5193
- let bits = 0;
5194
- let buffer = 0;
5195
- for (let i = 0; i < data.length; ++i) {
5196
- buffer = buffer << 8 | data[i];
5197
- bits += 8;
5198
- while (bits > bitsPerChar) {
5199
- bits -= bitsPerChar;
5200
- out += alphabet[mask & buffer >> bits];
5201
- }
5202
- }
5203
- if (bits !== 0) {
5204
- out += alphabet[mask & buffer << bitsPerChar - bits];
5205
- }
5206
- if (pad) {
5207
- while ((out.length * bitsPerChar & 7) !== 0) {
5208
- out += "=";
5209
- }
5210
- }
5211
- return out;
5212
- }
5213
- function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
5214
- return from({
5215
- prefix,
5216
- name,
5217
- encode(input) {
5218
- return encode(input, alphabet, bitsPerChar);
5219
- },
5220
- decode(input) {
5221
- return decode(input, alphabet, bitsPerChar, name);
5222
- }
5223
- });
4625
+ });
5224
4626
  }
5225
4627
 
5226
4628
  // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
@@ -5375,7 +4777,7 @@ function create(code, digest) {
5375
4777
  return new Digest(code, size, digest, bytes);
5376
4778
  }
5377
4779
  function decode4(multihash) {
5378
- const bytes = coerce4(multihash);
4780
+ const bytes = coerce2(multihash);
5379
4781
  const [code, sizeOffset] = decode3(bytes);
5380
4782
  const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
5381
4783
  const digest = bytes.subarray(sizeOffset + digestOffset);
@@ -5618,7 +5020,7 @@ var CID = class _CID {
5618
5020
  static decodeFirst(bytes) {
5619
5021
  const specs = _CID.inspectBytes(bytes);
5620
5022
  const prefixSize = specs.size - specs.multihashSize;
5621
- const multihashBytes = coerce4(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
5023
+ const multihashBytes = coerce2(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
5622
5024
  if (multihashBytes.byteLength !== specs.multihashSize) {
5623
5025
  throw new Error("Incorrect length");
5624
5026
  }
@@ -5921,67 +5323,1060 @@ function mimeTypeToMedia(mimeType) {
5921
5323
  return "UNKNOWN" /* UNKNOWN */;
5922
5324
  return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
5923
5325
  }
5924
- async function getMimeType(uri) {
5925
- if (!uri)
5926
- return uri;
5927
- const res = await fetch(uri, { method: "HEAD" });
5928
- let mimeType = res.headers.get("content-type");
5929
- return mimeType;
5326
+ async function getMimeType(uri) {
5327
+ if (!uri)
5328
+ return uri;
5329
+ const res = await fetch(uri, { method: "HEAD" });
5330
+ let mimeType = res.headers.get("content-type");
5331
+ return mimeType;
5332
+ }
5333
+
5334
+ // src/ipfs/token-metadata.ts
5335
+ var makeTextTokenMetadata = (parameters) => {
5336
+ const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
5337
+ const content = textFileUrl ? {
5338
+ mime: TEXT_PLAIN,
5339
+ uri: textFileUrl
5340
+ } : null;
5341
+ const image = thumbnailUrl;
5342
+ const animation_url = textFileUrl;
5343
+ return {
5344
+ name,
5345
+ image,
5346
+ animation_url,
5347
+ content,
5348
+ attributes
5349
+ };
5350
+ };
5351
+ var makeMediaTokenMetadata = async ({
5352
+ name,
5353
+ description,
5354
+ attributes = [],
5355
+ mediaUrl,
5356
+ thumbnailUrl
5357
+ }) => {
5358
+ const contentUrl = mediaUrl;
5359
+ const fetchableContentUrl = getFetchableUrl(contentUrl);
5360
+ if (!fetchableContentUrl)
5361
+ throw new Error(`Content url (${contentUrl}) is not fetchable`);
5362
+ const mimeType = await getMimeType(fetchableContentUrl);
5363
+ const mediaType = mimeTypeToMedia(mimeType);
5364
+ let image = void 0;
5365
+ let animation_url = null;
5366
+ if (isImage(mimeType)) {
5367
+ image = contentUrl;
5368
+ } else {
5369
+ image = thumbnailUrl;
5370
+ animation_url = mediaUrl;
5371
+ }
5372
+ if (!image)
5373
+ image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
5374
+ const content = contentUrl ? {
5375
+ mime: mimeType || "application/octet-stream",
5376
+ uri: contentUrl
5377
+ } : null;
5378
+ return {
5379
+ name,
5380
+ description,
5381
+ image,
5382
+ animation_url,
5383
+ content,
5384
+ attributes
5385
+ };
5386
+ };
5387
+ async function fetchTokenMetadata(tokenMetadataURI) {
5388
+ const fetchableUrl = getFetchableUrl(tokenMetadataURI);
5389
+ if (!fetchableUrl) {
5390
+ throw new Error(`Invalid token metadata URI: ${tokenMetadataURI}`);
5391
+ }
5392
+ const json = await (await fetch(fetchableUrl)).json();
5393
+ if (!json) {
5394
+ throw new Error(`Failed to fetch metadata from ${fetchableUrl}`);
5395
+ }
5396
+ return json;
5397
+ }
5398
+
5399
+ // src/create/minter-defaults.ts
5400
+ var SALE_END_FOREVER = 18446744073709551615n;
5401
+ var DEFAULT_SALE_START_AND_END = {
5402
+ // Sale start time – defaults to beginning of unix time
5403
+ saleStart: 0n,
5404
+ // This is the end of uint64, plenty of time
5405
+ saleEnd: SALE_END_FOREVER
5406
+ };
5407
+ var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
5408
+ maxTokensPerAddress: 0n
5409
+ };
5410
+ var erc20SaleSettingsWithDefaults = (params) => ({
5411
+ ...DEFAULT_SALE_START_AND_END,
5412
+ ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
5413
+ ...params
5414
+ });
5415
+ var allowListWithDefaults = (allowlist) => {
5416
+ return {
5417
+ ...DEFAULT_SALE_START_AND_END,
5418
+ ...allowlist
5419
+ };
5420
+ };
5421
+ var fixedPriceSettingsWithDefaults = (params) => ({
5422
+ ...DEFAULT_SALE_START_AND_END,
5423
+ ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
5424
+ type: "fixedPrice",
5425
+ ...params
5426
+ });
5427
+ var parseNameIntoSymbol = (name) => {
5428
+ if (name === "") {
5429
+ throw new Error("Name must be provided to generate a symbol");
5430
+ }
5431
+ const result = "$" + name.replace(/[^a-zA-Z0-9]/g, "").replace(/^\$+/, "").toUpperCase().replace(/[AEIOU\s]/g, "").slice(0, 4);
5432
+ if (result === "$") {
5433
+ throw new Error("Not enough valid characters to generate a symbol");
5434
+ }
5435
+ return result;
5436
+ };
5437
+ async function fetchTokenNameFromMetadata(tokenMetadataURI) {
5438
+ const tokenMetadata = await fetchTokenMetadata(tokenMetadataURI);
5439
+ if (!tokenMetadata.name) {
5440
+ throw new Error("No name found in token metadata");
5441
+ }
5442
+ return tokenMetadata.name;
5443
+ }
5444
+ var timedSaleSettingsWithDefaults = async (params, tokenMetadataURI) => {
5445
+ const erc20Name = params.erc20Name || await fetchTokenNameFromMetadata(tokenMetadataURI);
5446
+ const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
5447
+ return {
5448
+ type: "timed",
5449
+ ...DEFAULT_SALE_START_AND_END,
5450
+ erc20Name,
5451
+ erc20Symbol: symbol
5452
+ };
5453
+ };
5454
+ var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
5455
+ var isErc20 = (salesConfig) => salesConfig.type === "erc20Mint";
5456
+ var isFixedPrice = (salesConfig) => {
5457
+ return salesConfig.pricePerToken > 0n;
5458
+ };
5459
+ var getSalesConfigWithDefaults = async (salesConfig, tokenMetadataURI) => {
5460
+ if (!salesConfig)
5461
+ return timedSaleSettingsWithDefaults({}, tokenMetadataURI);
5462
+ if (isAllowList(salesConfig)) {
5463
+ return allowListWithDefaults(salesConfig);
5464
+ }
5465
+ if (isErc20(salesConfig)) {
5466
+ return erc20SaleSettingsWithDefaults(salesConfig);
5467
+ }
5468
+ if (isFixedPrice(salesConfig)) {
5469
+ return fixedPriceSettingsWithDefaults(salesConfig);
5470
+ }
5471
+ return timedSaleSettingsWithDefaults(salesConfig, tokenMetadataURI);
5472
+ };
5473
+
5474
+ // src/create/minter-setup.ts
5475
+ import {
5476
+ erc20MinterABI as erc20MinterABI2,
5477
+ erc20MinterAddress as erc20MinterAddresses,
5478
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI4,
5479
+ zoraCreatorFixedPriceSaleStrategyABI,
5480
+ zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2,
5481
+ zoraCreatorMerkleMinterStrategyABI,
5482
+ zoraCreatorMerkleMinterStrategyAddress,
5483
+ zoraTimedSaleStrategyABI as zoraTimedSaleStrategyABI2,
5484
+ zoraTimedSaleStrategyAddress
5485
+ } from "@zoralabs/protocol-deployments";
5486
+ import { encodeFunctionData } from "viem";
5487
+ var PERMISSION_BITS = {
5488
+ MINTER: 2n ** 2n
5489
+ };
5490
+ function setupErc20Minter({
5491
+ pricePerToken,
5492
+ chainId,
5493
+ tokenId: nextTokenId,
5494
+ currency,
5495
+ saleStart,
5496
+ saleEnd,
5497
+ maxTokensPerAddress: mintLimit,
5498
+ fundsRecipient
5499
+ }) {
5500
+ const erc20MinterAddress = erc20MinterAddresses[chainId];
5501
+ if (!erc20MinterAddress)
5502
+ throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
5503
+ const erc20MinterApproval = encodeFunctionData({
5504
+ abi: zoraCreator1155ImplABI4,
5505
+ functionName: "addPermission",
5506
+ args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
5507
+ });
5508
+ const saleData = encodeFunctionData({
5509
+ abi: erc20MinterABI2,
5510
+ functionName: "setSale",
5511
+ args: [
5512
+ BigInt(nextTokenId),
5513
+ {
5514
+ saleStart: saleStart || BigInt(0),
5515
+ saleEnd: saleEnd || BigInt(0),
5516
+ maxTokensPerAddress: BigInt(mintLimit || 0),
5517
+ pricePerToken,
5518
+ fundsRecipient,
5519
+ currency
5520
+ }
5521
+ ]
5522
+ });
5523
+ const callSale = encodeFunctionData({
5524
+ abi: zoraCreator1155ImplABI4,
5525
+ functionName: "callSale",
5526
+ args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
5527
+ });
5528
+ return {
5529
+ minter: erc20MinterAddress,
5530
+ setupActions: [erc20MinterApproval, callSale]
5531
+ };
5532
+ }
5533
+ function setupFixedPriceMinter({
5534
+ pricePerToken: price,
5535
+ tokenId: nextTokenId,
5536
+ chainId,
5537
+ saleStart,
5538
+ saleEnd,
5539
+ maxTokensPerAddress: mintLimit,
5540
+ fundsRecipient
5541
+ }) {
5542
+ const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress2[chainId];
5543
+ const fixedPriceApproval = encodeFunctionData({
5544
+ abi: zoraCreator1155ImplABI4,
5545
+ functionName: "addPermission",
5546
+ args: [
5547
+ BigInt(nextTokenId),
5548
+ fixedPriceStrategyAddress,
5549
+ PERMISSION_BITS.MINTER
5550
+ ]
5551
+ });
5552
+ const saleData = encodeFunctionData({
5553
+ abi: zoraCreatorFixedPriceSaleStrategyABI,
5554
+ functionName: "setSale",
5555
+ args: [
5556
+ BigInt(nextTokenId),
5557
+ {
5558
+ pricePerToken: price,
5559
+ saleStart: saleStart || BigInt(0),
5560
+ saleEnd: saleEnd || BigInt(0),
5561
+ maxTokensPerAddress: BigInt(mintLimit || 0),
5562
+ fundsRecipient
5563
+ }
5564
+ ]
5565
+ });
5566
+ const callSale = encodeFunctionData({
5567
+ abi: zoraCreator1155ImplABI4,
5568
+ functionName: "callSale",
5569
+ args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
5570
+ });
5571
+ return {
5572
+ minter: fixedPriceStrategyAddress,
5573
+ setupActions: [fixedPriceApproval, callSale]
5574
+ };
5575
+ }
5576
+ function setupTimedSaleMinter({
5577
+ chainId,
5578
+ tokenId,
5579
+ erc20Name: erc20zName,
5580
+ erc20Symbol: erc20zSymbol,
5581
+ saleStart,
5582
+ saleEnd
5583
+ }) {
5584
+ const minterAddress = zoraTimedSaleStrategyAddress[chainId];
5585
+ const fixedPriceApproval = encodeFunctionData({
5586
+ abi: zoraCreator1155ImplABI4,
5587
+ functionName: "addPermission",
5588
+ args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER]
5589
+ });
5590
+ const saleData = encodeFunctionData({
5591
+ abi: zoraTimedSaleStrategyABI2,
5592
+ functionName: "setSale",
5593
+ args: [
5594
+ BigInt(tokenId),
5595
+ {
5596
+ saleStart,
5597
+ saleEnd,
5598
+ name: erc20zName,
5599
+ symbol: erc20zSymbol
5600
+ }
5601
+ ]
5602
+ });
5603
+ const callSale = encodeFunctionData({
5604
+ abi: zoraCreator1155ImplABI4,
5605
+ functionName: "callSale",
5606
+ args: [BigInt(tokenId), minterAddress, saleData]
5607
+ });
5608
+ return {
5609
+ minter: minterAddress,
5610
+ setupActions: [fixedPriceApproval, callSale]
5611
+ };
5612
+ }
5613
+ function setupAllowListMinter({
5614
+ chainId,
5615
+ tokenId: nextTokenId,
5616
+ allowlist,
5617
+ fundsRecipient
5618
+ }) {
5619
+ const merkleSaleStrategyAddress = zoraCreatorMerkleMinterStrategyAddress[chainId];
5620
+ const merkleApproval = encodeFunctionData({
5621
+ abi: zoraCreator1155ImplABI4,
5622
+ functionName: "addPermission",
5623
+ args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER]
5624
+ });
5625
+ const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x") ? allowlist.presaleMerkleRoot : `0x${allowlist.presaleMerkleRoot}`;
5626
+ const saleData = encodeFunctionData({
5627
+ abi: zoraCreatorMerkleMinterStrategyABI,
5628
+ functionName: "setSale",
5629
+ args: [
5630
+ BigInt(nextTokenId),
5631
+ {
5632
+ presaleStart: allowlist.saleStart,
5633
+ presaleEnd: allowlist.saleEnd,
5634
+ merkleRoot,
5635
+ fundsRecipient
5636
+ }
5637
+ ]
5638
+ });
5639
+ const callSaleMerkle = encodeFunctionData({
5640
+ abi: zoraCreator1155ImplABI4,
5641
+ functionName: "callSale",
5642
+ args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData]
5643
+ });
5644
+ return {
5645
+ minter: merkleSaleStrategyAddress,
5646
+ setupActions: [merkleApproval, callSaleMerkle]
5647
+ };
5648
+ }
5649
+ var isAllowList2 = (salesConfig) => salesConfig.type === "allowlistMint";
5650
+ var isErc202 = (salesConfig) => salesConfig.type === "erc20Mint";
5651
+ var isFixedPrice2 = (salesConfig) => salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > BigInt(0);
5652
+ function setupMinters({ salesConfig, ...rest }) {
5653
+ if (isErc202(salesConfig)) {
5654
+ return setupErc20Minter({
5655
+ ...salesConfig,
5656
+ ...rest
5657
+ });
5658
+ }
5659
+ if (isAllowList2(salesConfig)) {
5660
+ return setupAllowListMinter({
5661
+ allowlist: salesConfig,
5662
+ ...rest
5663
+ });
5664
+ }
5665
+ if (isFixedPrice2(salesConfig))
5666
+ return setupFixedPriceMinter({
5667
+ ...salesConfig,
5668
+ ...rest
5669
+ });
5670
+ return setupTimedSaleMinter({
5671
+ ...salesConfig,
5672
+ ...rest
5673
+ });
5674
+ }
5675
+
5676
+ // src/create/token-setup.ts
5677
+ async function applyNew1155Defaults(props, ownerAddress) {
5678
+ const { payoutRecipient: fundsRecipient } = props;
5679
+ const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== zeroAddress5 ? fundsRecipient : ownerAddress;
5680
+ return {
5681
+ payoutRecipient: fundsRecipientOrOwner,
5682
+ createReferral: props.createReferral || zeroAddress5,
5683
+ maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
5684
+ royaltyBPS: props.royaltyBPS || 1e3,
5685
+ tokenMetadataURI: props.tokenMetadataURI,
5686
+ salesConfig: await getSalesConfigWithDefaults(
5687
+ props.salesConfig,
5688
+ props.tokenMetadataURI
5689
+ )
5690
+ };
5691
+ }
5692
+ function buildSetupNewToken({
5693
+ tokenURI,
5694
+ maxSupply = OPEN_EDITION_MINT_SIZE,
5695
+ createReferral = zeroAddress5,
5696
+ contractVersion
5697
+ }) {
5698
+ if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
5699
+ return encodeFunctionData2({
5700
+ abi: zoraCreator1155ImplABI5,
5701
+ functionName: "setupNewTokenWithCreateReferral",
5702
+ args: [tokenURI, BigInt(maxSupply), createReferral]
5703
+ });
5704
+ }
5705
+ if (createReferral !== zeroAddress5) {
5706
+ throw new Error(
5707
+ "Contract does not support create referral, but one was provided"
5708
+ );
5709
+ }
5710
+ return encodeFunctionData2({
5711
+ abi: zoraCreator1155ImplABI5,
5712
+ functionName: "setupNewToken",
5713
+ args: [tokenURI, BigInt(maxSupply)]
5714
+ });
5715
+ }
5716
+ function setupRoyaltyConfig({
5717
+ royaltyBPS,
5718
+ royaltyRecipient,
5719
+ nextTokenId
5720
+ }) {
5721
+ if (royaltyBPS > 0 && royaltyRecipient != zeroAddress5) {
5722
+ return encodeFunctionData2({
5723
+ abi: zoraCreator1155ImplABI5,
5724
+ functionName: "updateRoyaltiesForToken",
5725
+ args: [
5726
+ nextTokenId,
5727
+ {
5728
+ royaltyBPS,
5729
+ royaltyRecipient,
5730
+ royaltyMintSchedule: 0
5731
+ }
5732
+ ]
5733
+ });
5734
+ }
5735
+ return null;
5736
+ }
5737
+ function makeAdminMintCall({
5738
+ ownerAddress,
5739
+ mintQuantity,
5740
+ nextTokenId
5741
+ }) {
5742
+ if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
5743
+ return null;
5744
+ }
5745
+ return encodeFunctionData2({
5746
+ abi: zoraCreator1155ImplABI5,
5747
+ functionName: "adminMint",
5748
+ args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
5749
+ });
5750
+ }
5751
+ async function constructCreate1155TokenCalls(props) {
5752
+ const {
5753
+ chainId,
5754
+ nextTokenId,
5755
+ mintToCreatorCount,
5756
+ ownerAddress,
5757
+ contractVersion
5758
+ } = props;
5759
+ const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
5760
+ props,
5761
+ ownerAddress
5762
+ );
5763
+ const verifyTokenIdExpected = encodeFunctionData2({
5764
+ abi: zoraCreator1155ImplABI5,
5765
+ functionName: "assumeLastTokenIdMatches",
5766
+ args: [nextTokenId - 1n]
5767
+ });
5768
+ const setupNewToken = buildSetupNewToken({
5769
+ tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
5770
+ maxSupply: new1155TokenPropsWithDefaults.maxSupply,
5771
+ createReferral: new1155TokenPropsWithDefaults.createReferral,
5772
+ contractVersion
5773
+ });
5774
+ const royaltyConfig = setupRoyaltyConfig({
5775
+ royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
5776
+ royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
5777
+ nextTokenId
5778
+ });
5779
+ const { minter, setupActions: mintersSetup } = setupMinters({
5780
+ tokenId: nextTokenId,
5781
+ chainId,
5782
+ fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
5783
+ salesConfig: new1155TokenPropsWithDefaults.salesConfig
5784
+ });
5785
+ const adminMintCall = makeAdminMintCall({
5786
+ ownerAddress,
5787
+ mintQuantity: mintToCreatorCount,
5788
+ nextTokenId
5789
+ });
5790
+ const setupActions = [
5791
+ verifyTokenIdExpected,
5792
+ setupNewToken,
5793
+ ...mintersSetup,
5794
+ royaltyConfig,
5795
+ adminMintCall
5796
+ ].filter((item) => item !== null);
5797
+ return {
5798
+ setupActions,
5799
+ minter,
5800
+ newToken: new1155TokenPropsWithDefaults
5801
+ };
5802
+ }
5803
+ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
5804
+ if (!contractStandard || !contractVersion) {
5805
+ return false;
5806
+ }
5807
+ const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
5808
+ if (!semVerContractVersion)
5809
+ return false;
5810
+ if (contractStandard === "ERC1155") {
5811
+ return semver2.gte(semVerContractVersion, "1.3.5");
5812
+ } else {
5813
+ return semver2.gte(semVerContractVersion, "14.0.0");
5814
+ }
5815
+ };
5816
+
5817
+ // src/create/1155-create-helper.ts
5818
+ var ROYALTY_BPS_DEFAULT = 1e3;
5819
+ var getTokenIdFromCreateReceipt = (receipt) => {
5820
+ for (const data of receipt.logs) {
5821
+ try {
5822
+ const decodedLog = decodeEventLog2({
5823
+ abi: zoraCreator1155ImplABI6,
5824
+ eventName: "SetupNewToken",
5825
+ ...data
5826
+ });
5827
+ if (decodedLog && decodedLog.eventName === "SetupNewToken") {
5828
+ return decodedLog.args.tokenId;
5829
+ }
5830
+ } catch (err) {
5831
+ }
5832
+ }
5833
+ throw new Error(
5834
+ "No event found in receipt that could be used to get tokenId"
5835
+ );
5836
+ };
5837
+ var getContractAddressFromReceipt = (receipt) => {
5838
+ for (const data of receipt.logs) {
5839
+ try {
5840
+ const decodedLog = decodeEventLog2({
5841
+ abi: zoraCreator1155FactoryImplABI2,
5842
+ eventName: "SetupNewContract",
5843
+ ...data
5844
+ });
5845
+ if (decodedLog && decodedLog.eventName === "SetupNewContract") {
5846
+ return decodedLog.args.newContract;
5847
+ }
5848
+ } catch (err) {
5849
+ }
5850
+ }
5851
+ throw new Error(
5852
+ "No event found in receipt that could be used to get contract address"
5853
+ );
5854
+ };
5855
+ function makeCreateContractAndTokenCall({
5856
+ account,
5857
+ contract,
5858
+ royaltyBPS,
5859
+ fundsRecipient,
5860
+ tokenSetupActions,
5861
+ chainId
5862
+ }) {
5863
+ const accountAddress = typeof account === "string" ? account : account.address;
5864
+ return makeContractParameters({
5865
+ abi: zoraCreator1155FactoryImplABI2,
5866
+ functionName: "createContractDeterministic",
5867
+ account,
5868
+ address: zoraCreator1155FactoryImplAddress2[chainId],
5869
+ args: [
5870
+ contract.uri,
5871
+ contract.name,
5872
+ {
5873
+ // deprecated
5874
+ royaltyMintSchedule: 0,
5875
+ royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
5876
+ royaltyRecipient: fundsRecipient || accountAddress
5877
+ },
5878
+ contract.defaultAdmin || accountAddress,
5879
+ tokenSetupActions
5880
+ ]
5881
+ });
5882
+ }
5883
+ function makeCreateTokenCall({
5884
+ contractAddress,
5885
+ account,
5886
+ tokenSetupActions
5887
+ }) {
5888
+ return makeContractParameters({
5889
+ abi: zoraCreator1155ImplABI6,
5890
+ functionName: "multicall",
5891
+ account,
5892
+ address: contractAddress,
5893
+ args: [tokenSetupActions]
5894
+ });
5895
+ }
5896
+ var Create1155Client = class {
5897
+ constructor({
5898
+ chainId,
5899
+ publicClient
5900
+ }) {
5901
+ this.chainId = chainId;
5902
+ this.publicClient = publicClient;
5903
+ }
5904
+ async createNew1155(props) {
5905
+ return createNew1155ContractAndToken({
5906
+ ...props,
5907
+ publicClient: this.publicClient,
5908
+ chainId: this.chainId
5909
+ });
5910
+ }
5911
+ async createNew1155OnExistingContract({
5912
+ contractAddress: contract,
5913
+ account,
5914
+ token,
5915
+ getAdditionalSetupActions
5916
+ }) {
5917
+ return createNew1155Token({
5918
+ contractAddress: contract,
5919
+ account,
5920
+ token,
5921
+ getAdditionalSetupActions,
5922
+ publicClient: this.publicClient,
5923
+ chainId: this.chainId
5924
+ });
5925
+ }
5926
+ };
5927
+ async function createNew1155ContractAndToken({
5928
+ contract,
5929
+ account,
5930
+ chainId,
5931
+ token,
5932
+ publicClient,
5933
+ getAdditionalSetupActions
5934
+ }) {
5935
+ const nextTokenId = 1n;
5936
+ const contractVersion = new1155ContractVersion(chainId);
5937
+ const {
5938
+ minter,
5939
+ newToken,
5940
+ setupActions: tokenSetupActions
5941
+ } = await prepareSetupActions({
5942
+ chainId,
5943
+ account,
5944
+ contractVersion,
5945
+ nextTokenId,
5946
+ token,
5947
+ getAdditionalSetupActions
5948
+ });
5949
+ const request = makeCreateContractAndTokenCall({
5950
+ contract,
5951
+ account,
5952
+ chainId,
5953
+ tokenSetupActions,
5954
+ fundsRecipient: token.payoutRecipient,
5955
+ royaltyBPS: token.royaltyBPS
5956
+ });
5957
+ const contractAddress = await getDeterministicContractAddress({
5958
+ account,
5959
+ publicClient,
5960
+ setupActions: tokenSetupActions,
5961
+ chainId,
5962
+ contract
5963
+ });
5964
+ return {
5965
+ parameters: request,
5966
+ tokenSetupActions,
5967
+ newTokenId: nextTokenId,
5968
+ newToken,
5969
+ contractAddress,
5970
+ contractVersion,
5971
+ minter
5972
+ };
5973
+ }
5974
+ async function createNew1155Token({
5975
+ contractAddress,
5976
+ account,
5977
+ getAdditionalSetupActions,
5978
+ token,
5979
+ publicClient,
5980
+ chainId
5981
+ }) {
5982
+ const { nextTokenId, contractVersion } = await getContractInfoExistingContract({
5983
+ publicClient,
5984
+ contractAddress
5985
+ });
5986
+ const {
5987
+ minter,
5988
+ newToken,
5989
+ setupActions: tokenSetupActions
5990
+ } = await prepareSetupActions({
5991
+ chainId,
5992
+ account,
5993
+ contractVersion,
5994
+ nextTokenId,
5995
+ token,
5996
+ getAdditionalSetupActions
5997
+ });
5998
+ const request = makeCreateTokenCall({
5999
+ contractAddress,
6000
+ account,
6001
+ tokenSetupActions
6002
+ });
6003
+ return {
6004
+ parameters: request,
6005
+ tokenSetupActions,
6006
+ newTokenId: nextTokenId,
6007
+ newToken,
6008
+ contractVersion,
6009
+ minter
6010
+ };
6011
+ }
6012
+ async function prepareSetupActions({
6013
+ chainId,
6014
+ account,
6015
+ contractVersion,
6016
+ nextTokenId,
6017
+ token,
6018
+ getAdditionalSetupActions
6019
+ }) {
6020
+ const {
6021
+ minter,
6022
+ newToken,
6023
+ setupActions: tokenSetupActions
6024
+ } = await constructCreate1155TokenCalls({
6025
+ chainId,
6026
+ ownerAddress: account,
6027
+ contractVersion,
6028
+ nextTokenId,
6029
+ ...token
6030
+ });
6031
+ const setupActions = getAdditionalSetupActions ? [
6032
+ ...getAdditionalSetupActions({
6033
+ tokenId: nextTokenId
6034
+ }),
6035
+ ...tokenSetupActions
6036
+ ] : tokenSetupActions;
6037
+ return { minter, newToken, setupActions };
6038
+ }
6039
+
6040
+ // src/sparks/mints-queries.ts
6041
+ var getMintsAccountBalanceWithPriceQuery = (account) => {
6042
+ const query = `
6043
+ query GetMintAccountBalances($account: String!) {
6044
+ mintAccountBalances(where: { account: $account }) {
6045
+ balance
6046
+ mintToken {
6047
+ id
6048
+ pricePerToken
6049
+ }
6050
+ }
6051
+ }
6052
+ `;
6053
+ return {
6054
+ query,
6055
+ variables: { account }
6056
+ };
6057
+ };
6058
+ var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
6059
+ const parsed = mintAccountBalances.map((r) => {
6060
+ return {
6061
+ tokenId: BigInt(r.mintToken.id),
6062
+ quantity: BigInt(r.balance),
6063
+ pricePerToken: BigInt(r.mintToken.pricePerToken)
6064
+ };
6065
+ });
6066
+ const sorted = parsed.sort((a, b) => {
6067
+ if (a.pricePerToken < b.pricePerToken) {
6068
+ return -1;
6069
+ }
6070
+ return 1;
6071
+ });
6072
+ let remainingQuantity = quantityToCollect;
6073
+ const tokenIds = [];
6074
+ const quantities = [];
6075
+ while (remainingQuantity > 0) {
6076
+ const next = sorted.shift();
6077
+ if (!next) {
6078
+ throw new Error("Not enough MINTs to collect with");
6079
+ }
6080
+ const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
6081
+ tokenIds.push(next.tokenId);
6082
+ quantities.push(quantityToUse);
6083
+ remainingQuantity -= quantityToUse;
6084
+ }
6085
+ return {
6086
+ tokenIds,
6087
+ quantities
6088
+ };
6089
+ };
6090
+ var sumBalances = (mintAccountBalances) => {
6091
+ return mintAccountBalances.reduce((acc, curr) => {
6092
+ return acc + BigInt(curr.balance);
6093
+ }, BigInt(0));
6094
+ };
6095
+
6096
+ // src/sparks/sparks-contracts.ts
6097
+ import {
6098
+ mintsSafeTransferBatchTypedDataDefinition,
6099
+ mintsSafeTransferTypedDataDefinition,
6100
+ zoraMints1155Config,
6101
+ zoraMintsManagerImplABI,
6102
+ zoraMintsManagerImplAddress,
6103
+ zoraMintsManagerImplConfig,
6104
+ zoraSparksManagerImplABI,
6105
+ zoraSparksManagerImplAddress
6106
+ } from "@zoralabs/protocol-deployments";
6107
+ import {
6108
+ decodeErrorResult,
6109
+ encodeFunctionData as encodeFunctionData3,
6110
+ zeroAddress as zeroAddress6
6111
+ } from "viem";
6112
+ var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
6113
+ var mintWithEthParams = ({
6114
+ tokenId,
6115
+ quantity,
6116
+ recipient,
6117
+ chainId,
6118
+ pricePerMint,
6119
+ account
6120
+ }) => makeContractParameters({
6121
+ abi: zoraSparksManagerImplABI,
6122
+ address: zoraSparksManagerImplAddress[chainId],
6123
+ functionName: "mintWithEth",
6124
+ args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
6125
+ value: pricePerMint * quantity,
6126
+ account
6127
+ });
6128
+ var getPaidMintValue = (quantities, pricePerMint) => {
6129
+ if (!pricePerMint || pricePerMint === 0n)
6130
+ return;
6131
+ return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
6132
+ };
6133
+ var mintsBalanceOfAccountParams = ({
6134
+ account,
6135
+ chainId
6136
+ }) => ({
6137
+ abi: zoraMints1155Config.abi,
6138
+ address: zoraMints1155Config.address[chainId],
6139
+ functionName: "balanceOfAccount",
6140
+ args: [account]
6141
+ });
6142
+ var encodeCollectOnManager = ({
6143
+ zoraCreator1155Contract,
6144
+ minter,
6145
+ zoraCreator1155TokenId,
6146
+ mintArguments
6147
+ }) => encodeFunctionData3({
6148
+ abi: zoraMintsManagerImplConfig.abi,
6149
+ functionName: "collect",
6150
+ args: [
6151
+ zoraCreator1155Contract,
6152
+ minter,
6153
+ zoraCreator1155TokenId,
6154
+ mintArguments
6155
+ ]
6156
+ });
6157
+ function collectWithMintsParams({
6158
+ tokenIds,
6159
+ quantities,
6160
+ chainId,
6161
+ paidMintPricePerToken,
6162
+ account,
6163
+ mintArguments,
6164
+ minter,
6165
+ zoraCreator1155Contract,
6166
+ zoraCreator1155TokenId
6167
+ }) {
6168
+ const call = encodeCollectOnManager({
6169
+ tokenIds,
6170
+ quantities,
6171
+ zoraCreator1155Contract,
6172
+ zoraCreator1155TokenId,
6173
+ minter,
6174
+ mintArguments
6175
+ });
6176
+ return makeContractParameters({
6177
+ abi: zoraMints1155Config.abi,
6178
+ address: zoraMints1155Config.address[chainId],
6179
+ functionName: "transferBatchToManagerAndCall",
6180
+ args: [tokenIds, quantities, call],
6181
+ // if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
6182
+ // for the paid mint cost.
6183
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
6184
+ account
6185
+ });
6186
+ }
6187
+ function getMintsEthPrice({
6188
+ publicClient
6189
+ }) {
6190
+ const chainId = publicClient.chain?.id;
6191
+ if (!chainId || !zoraMintsManagerImplAddress[chainId]) {
6192
+ throw new Error(`Chain id ${chainId} not supported`);
6193
+ }
6194
+ return publicClient.readContract({
6195
+ abi: zoraMintsManagerImplABI,
6196
+ address: zoraMintsManagerImplAddress[chainId],
6197
+ functionName: "getEthPrice"
6198
+ });
5930
6199
  }
5931
-
5932
- // src/ipfs/token-metadata.ts
5933
- var makeTextTokenMetadata = (parameters) => {
5934
- const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
5935
- const content = textFileUrl ? {
5936
- mime: TEXT_PLAIN,
5937
- uri: textFileUrl
5938
- } : null;
5939
- const image = thumbnailUrl;
5940
- const animation_url = textFileUrl;
6200
+ function makePermitTransferBatchAndTypeData({
6201
+ tokenIds,
6202
+ quantities,
6203
+ chainId,
6204
+ mintsOwner,
6205
+ to,
6206
+ nonce,
6207
+ deadline,
6208
+ safeTransferData
6209
+ }) {
6210
+ const permit = {
6211
+ owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
6212
+ to,
6213
+ tokenIds,
6214
+ quantities,
6215
+ deadline,
6216
+ nonce,
6217
+ safeTransferData
6218
+ };
6219
+ const typedData = {
6220
+ ...mintsSafeTransferBatchTypedDataDefinition({
6221
+ chainId,
6222
+ message: permit
6223
+ }),
6224
+ account: mintsOwner
6225
+ };
5941
6226
  return {
5942
- name,
5943
- image,
5944
- animation_url,
5945
- content,
5946
- attributes
6227
+ permit,
6228
+ typedData
5947
6229
  };
5948
- };
5949
- var makeMediaTokenMetadata = async ({
5950
- name,
5951
- description,
5952
- attributes = [],
5953
- mediaUrl,
5954
- thumbnailUrl
6230
+ }
6231
+ function makePermitTransferTypeData({
6232
+ tokenId,
6233
+ quantity,
6234
+ chainId,
6235
+ mintsOwner,
6236
+ to,
6237
+ nonce,
6238
+ deadline,
6239
+ safeTransferData
6240
+ }) {
6241
+ const permit = {
6242
+ owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
6243
+ to,
6244
+ tokenId,
6245
+ quantity,
6246
+ deadline,
6247
+ nonce,
6248
+ safeTransferData
6249
+ };
6250
+ const typedData = {
6251
+ ...mintsSafeTransferTypedDataDefinition({
6252
+ chainId,
6253
+ message: permit
6254
+ }),
6255
+ account: mintsOwner
6256
+ };
6257
+ return {
6258
+ permit,
6259
+ typedData
6260
+ };
6261
+ }
6262
+ var encodePremintOnManager = ({
6263
+ contractCreationConfig,
6264
+ premintConfig,
6265
+ premintSignature,
6266
+ mintArguments,
6267
+ signerContract = zeroAddress6
6268
+ }) => encodeFunctionData3({
6269
+ abi: zoraMintsManagerImplConfig.abi,
6270
+ functionName: "collectPremintV2",
6271
+ args: [
6272
+ contractCreationConfig,
6273
+ premintConfig,
6274
+ premintSignature,
6275
+ mintArguments,
6276
+ signerContract
6277
+ ]
6278
+ });
6279
+ var makePermitToCollectPremintOrNonPremint = ({
6280
+ mintsOwner,
6281
+ chainId,
6282
+ deadline,
6283
+ tokenIds,
6284
+ // this quantity of MINTs will be used to collect premint
6285
+ // and will be burned. This same quantity is the quantity of
6286
+ // premint to collect.
6287
+ quantities,
6288
+ nonce,
6289
+ premint,
6290
+ collect
5955
6291
  }) => {
5956
- const contentUrl = mediaUrl;
5957
- const fetchableContentUrl = getFetchableUrl(contentUrl);
5958
- if (!fetchableContentUrl)
5959
- throw new Error(`Content url (${contentUrl}) is not fetchable`);
5960
- const mimeType = await getMimeType(fetchableContentUrl);
5961
- const mediaType = mimeTypeToMedia(mimeType);
5962
- let image = void 0;
5963
- let animation_url = null;
5964
- if (isImage(mimeType)) {
5965
- image = contentUrl;
6292
+ let safeTransferData;
6293
+ if (premint) {
6294
+ safeTransferData = encodePremintOnManager(premint);
6295
+ } else if (collect) {
6296
+ safeTransferData = encodeCollectOnManager(collect);
5966
6297
  } else {
5967
- image = thumbnailUrl;
5968
- animation_url = mediaUrl;
6298
+ throw new Error("Invalid operation");
5969
6299
  }
5970
- if (!image)
5971
- image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
5972
- const content = contentUrl ? {
5973
- mime: mimeType || "application/octet-stream",
5974
- uri: contentUrl
5975
- } : null;
6300
+ return makePermitTransferBatchAndTypeData({
6301
+ tokenIds,
6302
+ quantities,
6303
+ chainId,
6304
+ mintsOwner,
6305
+ nonce,
6306
+ deadline,
6307
+ safeTransferData,
6308
+ to: zoraMintsManagerImplConfig.address[chainId]
6309
+ });
6310
+ };
6311
+ function collectPremintV2WithMintsParams({
6312
+ tokenIds,
6313
+ quantities,
6314
+ paidMintPricePerToken,
6315
+ account,
6316
+ chainId,
6317
+ ...rest
6318
+ }) {
6319
+ const call = encodePremintOnManager({
6320
+ ...rest
6321
+ });
6322
+ return makeContractParameters({
6323
+ abi: zoraMints1155Config.abi,
6324
+ address: zoraMints1155Config.address[chainId],
6325
+ functionName: "transferBatchToManagerAndCall",
6326
+ args: [tokenIds, quantities, call],
6327
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
6328
+ account
6329
+ });
6330
+ }
6331
+ function decodeCallFailedError(error) {
6332
+ if (error.data?.errorName !== "CallFailed")
6333
+ throw new Error("Not a CallFailed error");
6334
+ const internalErrorData = error.data?.args?.[0];
6335
+ return decodeErrorResult({
6336
+ abi: zoraMintsManagerImplABI,
6337
+ data: internalErrorData
6338
+ });
6339
+ }
6340
+
6341
+ // src/sdk.ts
6342
+ function createCreatorClient(clientConfig) {
6343
+ const premintClient = new PremintClient({
6344
+ chainId: clientConfig.chainId,
6345
+ publicClient: clientConfig.publicClient,
6346
+ premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
6347
+ });
6348
+ const create1155CreatorClient = new Create1155Client({
6349
+ chainId: clientConfig.chainId,
6350
+ publicClient: clientConfig.publicClient
6351
+ });
5976
6352
  return {
5977
- name,
5978
- description,
5979
- image,
5980
- animation_url,
5981
- content,
5982
- attributes
6353
+ createPremint: (p) => premintClient.createPremint(p),
6354
+ updatePremint: (p) => premintClient.updatePremint(p),
6355
+ deletePremint: (p) => premintClient.deletePremint(p),
6356
+ create1155: (p) => create1155CreatorClient.createNew1155(p),
6357
+ create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
5983
6358
  };
5984
- };
6359
+ }
6360
+ function createCollectorClient(params) {
6361
+ const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
6362
+ const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
6363
+ const mintClient = new MintClient({
6364
+ publicClient: params.publicClient,
6365
+ premintGetter: premintGetterToUse,
6366
+ mintGetter: mintGetterToUse
6367
+ });
6368
+ return {
6369
+ getPremint: (p) => premintGetterToUse.get({
6370
+ collectionAddress: p.address,
6371
+ uid: p.uid
6372
+ }),
6373
+ getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
6374
+ getToken: (p) => mintClient.get(p),
6375
+ getTokensOfContract: (p) => mintClient.getOfContract(p),
6376
+ mint: (p) => mintClient.mint(p),
6377
+ getMintCosts: (p) => mintClient.getMintCosts(p)
6378
+ };
6379
+ }
5985
6380
 
5986
6381
  // src/ipfs/text-metadata.ts
5987
6382
  var CHAR_LIMIT = 1111;
@@ -6076,6 +6471,26 @@ async function generateTextNftMetadataFiles(text) {
6076
6471
  thumbnailFile
6077
6472
  };
6078
6473
  }
6474
+
6475
+ // src/allow-list/allow-list-client.ts
6476
+ var ALLOW_LIST_API_BASE = "http://allowlist.zora.co/";
6477
+ var createAllowList = async ({
6478
+ allowList,
6479
+ httpClient: httpClient2 = httpClient,
6480
+ baseUrl = ALLOW_LIST_API_BASE
6481
+ }) => {
6482
+ const { post: post2, retries: retries2 } = httpClient2;
6483
+ const data = {
6484
+ entries: allowList.entries.map((entry) => ({
6485
+ user: entry.user,
6486
+ maxCanMint: entry.maxCanMint,
6487
+ price: entry.price.toString()
6488
+ }))
6489
+ };
6490
+ return (await retries2(
6491
+ () => post2(`${baseUrl}allowlist`, data)
6492
+ )).root;
6493
+ };
6079
6494
  export {
6080
6495
  Create1155Client,
6081
6496
  Errors,
@@ -6087,7 +6502,6 @@ export {
6087
6502
  ZORA_API_BASE,
6088
6503
  applyUpdateToPremint,
6089
6504
  buildPremintMintCall,
6090
- collectOnchain,
6091
6505
  collectPremint,
6092
6506
  collectPremintV2WithMintsParams,
6093
6507
  collectWithMintsParams,
@@ -6095,6 +6509,7 @@ export {
6095
6509
  convertGetPremintApiResponse,
6096
6510
  convertGetPremintOfCollectionApiResponse,
6097
6511
  convertPremintFromApi,
6512
+ createAllowList,
6098
6513
  createCollectorClient,
6099
6514
  createCreatorClient,
6100
6515
  decodeCallFailedError,
@@ -6107,6 +6522,7 @@ export {
6107
6522
  encodePremintForAPI,
6108
6523
  generateTextNftMetadataFiles,
6109
6524
  getApiNetworkConfigForChain,
6525
+ getContractAddressFromReceipt,
6110
6526
  getDataFromPremintReceipt,
6111
6527
  getDefaultFixedPriceMinterAddress,
6112
6528
  getMintsAccountBalanceWithPriceQuery,
@@ -6124,6 +6540,7 @@ export {
6124
6540
  isPremintConfigV1,
6125
6541
  isPremintConfigV2,
6126
6542
  isValidSignature,
6543
+ makeCreateContractAndTokenCall,
6127
6544
  makeMediaTokenMetadata,
6128
6545
  makeMintRewardsRecipient,
6129
6546
  makeNewPremint,