@zoralabs/protocol-sdk 0.8.0 → 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 (75) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +11 -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/contract-setup.d.ts +1 -0
  13. package/dist/create/contract-setup.d.ts.map +1 -1
  14. package/dist/create/minter-defaults.d.ts +5 -0
  15. package/dist/create/minter-defaults.d.ts.map +1 -0
  16. package/dist/create/minter-setup.d.ts +14 -0
  17. package/dist/create/minter-setup.d.ts.map +1 -0
  18. package/dist/create/token-setup.d.ts +4 -19
  19. package/dist/create/token-setup.d.ts.map +1 -1
  20. package/dist/create/types.d.ts +32 -7
  21. package/dist/create/types.d.ts.map +1 -1
  22. package/dist/create/update.d.ts +15 -0
  23. package/dist/create/update.d.ts.map +1 -0
  24. package/dist/index.cjs +2249 -1936
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +2284 -1966
  29. package/dist/index.js.map +1 -1
  30. package/dist/ipfs/token-metadata.d.ts +1 -0
  31. package/dist/ipfs/token-metadata.d.ts.map +1 -1
  32. package/dist/mint/mint-client.d.ts +2 -6
  33. package/dist/mint/mint-client.d.ts.map +1 -1
  34. package/dist/mint/mint-queries.d.ts +3 -1
  35. package/dist/mint/mint-queries.d.ts.map +1 -1
  36. package/dist/mint/mint-transactions.d.ts +9 -7
  37. package/dist/mint/mint-transactions.d.ts.map +1 -1
  38. package/dist/mint/subgraph-mint-getter.d.ts +5 -4
  39. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  40. package/dist/mint/subgraph-queries.d.ts +42 -15
  41. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  42. package/dist/mint/types.d.ts +32 -13
  43. package/dist/mint/types.d.ts.map +1 -1
  44. package/dist/sparks/sparks-contracts.d.ts +96 -96
  45. package/dist/types.d.ts +1 -1
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/utils.d.ts +1 -8
  48. package/dist/utils.d.ts.map +1 -1
  49. package/package.json +2 -2
  50. package/src/allow-list/allow-list-client.ts +105 -0
  51. package/src/allow-list/types.ts +15 -0
  52. package/src/apis/generated/allow-list-api-types.ts +288 -0
  53. package/src/apis/http-api-base.ts +12 -0
  54. package/src/apis/subgraph-querier.ts +38 -0
  55. package/src/create/1155-create-helper.test.ts +216 -66
  56. package/src/create/1155-create-helper.ts +4 -4
  57. package/src/create/contract-setup.ts +8 -0
  58. package/src/create/minter-defaults.test.ts +21 -0
  59. package/src/create/minter-defaults.ts +134 -0
  60. package/src/create/minter-setup.ts +293 -0
  61. package/src/create/token-setup.ts +14 -190
  62. package/src/create/types.ts +56 -9
  63. package/src/create/update.ts +93 -0
  64. package/src/index.ts +4 -0
  65. package/src/ipfs/token-metadata.ts +18 -0
  66. package/src/mint/mint-client.test.ts +219 -15
  67. package/src/mint/mint-client.ts +2 -34
  68. package/src/mint/mint-queries.ts +34 -13
  69. package/src/mint/mint-transactions.ts +104 -17
  70. package/src/mint/subgraph-mint-getter.ts +107 -50
  71. package/src/mint/subgraph-queries.ts +67 -37
  72. package/src/mint/types.ts +55 -16
  73. package/src/premint/premint-client.test.ts +6 -5
  74. package/src/types.ts +1 -1
  75. 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
 
@@ -4121,8 +4249,14 @@ async function getContractInfoExistingContract({
4121
4249
  abi: zoraCreator1155ImplABI3,
4122
4250
  functionName: "nextTokenId"
4123
4251
  });
4252
+ const contractName = await publicClient.readContract({
4253
+ address: contractAddress,
4254
+ abi: zoraCreator1155ImplABI3,
4255
+ functionName: "name"
4256
+ });
4124
4257
  return {
4125
4258
  contractVersion,
4259
+ contractName,
4126
4260
  nextTokenId
4127
4261
  };
4128
4262
  }
@@ -4149,1936 +4283,2100 @@ async function getDeterministicContractAddress({
4149
4283
  }
4150
4284
 
4151
4285
  // src/create/token-setup.ts
4152
- var semver3 = __toESM(require_semver2(), 1);
4153
- import {
4154
- erc20MinterABI as erc20MinterABI2,
4155
- erc20MinterAddress as erc20MinterAddresses,
4156
- zoraCreator1155ImplABI as zoraCreator1155ImplABI4,
4157
- zoraCreatorFixedPriceSaleStrategyABI,
4158
- zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
4159
- } from "@zoralabs/protocol-deployments";
4160
- import { encodeFunctionData, zeroAddress as zeroAddress5 } from "viem";
4161
- var PERMISSION_BITS = {
4162
- MINTER: 2n ** 2n
4163
- };
4164
- var saleSettingsOrDefault = (saleSettings) => {
4165
- const SALE_END_FOREVER = 18446744073709551615n;
4166
- const DEFAULT_SALE_SETTINGS = {
4167
- currency: zeroAddress5,
4168
- // Free Mint
4169
- pricePerToken: 0n,
4170
- // Sale start time – defaults to beginning of unix time
4171
- saleStart: 0n,
4172
- // This is the end of uint64, plenty of time
4173
- saleEnd: SALE_END_FOREVER,
4174
- // 0 Here means no limit
4175
- maxTokensPerAddress: 0n
4176
- };
4177
- return {
4178
- ...DEFAULT_SALE_SETTINGS,
4179
- ...saleSettings
4180
- };
4181
- };
4182
- function applyNew1155Defaults(props, ownerAddress) {
4183
- const { payoutRecipient: fundsRecipient } = props;
4184
- const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== zeroAddress5 ? fundsRecipient : ownerAddress;
4185
- return {
4186
- payoutRecipient: fundsRecipientOrOwner,
4187
- createReferral: props.createReferral || zeroAddress5,
4188
- maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
4189
- royaltyBPS: props.royaltyBPS || 1e3,
4190
- salesConfig: saleSettingsOrDefault(props.salesConfig),
4191
- tokenMetadataURI: props.tokenMetadataURI
4192
- };
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;
4193
4293
  }
4194
- function setupErc20Minter({
4195
- pricePerToken,
4196
- chainId,
4197
- tokenId: nextTokenId,
4198
- currency,
4199
- saleStart,
4200
- saleEnd,
4201
- maxTokensPerAddress: mintLimit,
4202
- fundsRecipient
4203
- }) {
4204
- const erc20MinterAddress = erc20MinterAddresses[chainId];
4205
- if (!erc20MinterAddress)
4206
- throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
4207
- const erc20MinterApproval = encodeFunctionData({
4208
- abi: zoraCreator1155ImplABI4,
4209
- functionName: "addPermission",
4210
- args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
4211
- });
4212
- const saleData = encodeFunctionData({
4213
- abi: erc20MinterABI2,
4214
- functionName: "setSale",
4215
- args: [
4216
- BigInt(nextTokenId),
4217
- {
4218
- saleStart: saleStart || BigInt(0),
4219
- saleEnd: saleEnd || BigInt(0),
4220
- maxTokensPerAddress: BigInt(mintLimit || 0),
4221
- pricePerToken,
4222
- fundsRecipient,
4223
- currency
4224
- }
4225
- ]
4226
- });
4227
- const callSale = encodeFunctionData({
4228
- abi: zoraCreator1155ImplABI4,
4229
- functionName: "callSale",
4230
- args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
4231
- });
4232
- return {
4233
- minter: erc20MinterAddress,
4234
- setupActions: [erc20MinterApproval, callSale]
4235
- };
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;
4302
+ }
4303
+ for (let ii = 0; ii < aa.byteLength; ii++) {
4304
+ if (aa[ii] !== bb[ii]) {
4305
+ return false;
4306
+ }
4307
+ }
4308
+ return true;
4236
4309
  }
4237
- function setupFixedPriceMinter({
4238
- pricePerToken: price,
4239
- tokenId: nextTokenId,
4240
- chainId,
4241
- saleStart,
4242
- saleEnd,
4243
- maxTokensPerAddress: mintLimit,
4244
- fundsRecipient
4245
- }) {
4246
- const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress2[chainId];
4247
- const fixedPriceApproval = encodeFunctionData({
4248
- abi: zoraCreator1155ImplABI4,
4249
- functionName: "addPermission",
4250
- args: [
4251
- BigInt(nextTokenId),
4252
- fixedPriceStrategyAddress,
4253
- PERMISSION_BITS.MINTER
4254
- ]
4255
- });
4256
- const saleData = encodeFunctionData({
4257
- abi: zoraCreatorFixedPriceSaleStrategyABI,
4258
- functionName: "setSale",
4259
- args: [
4260
- BigInt(nextTokenId),
4261
- {
4262
- pricePerToken: price,
4263
- saleStart: saleStart || BigInt(0),
4264
- saleEnd: saleEnd || BigInt(0),
4265
- maxTokensPerAddress: BigInt(mintLimit || 0),
4266
- fundsRecipient
4267
- }
4268
- ]
4269
- });
4270
- const callSale = encodeFunctionData({
4271
- abi: zoraCreator1155ImplABI4,
4272
- functionName: "callSale",
4273
- args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
4274
- });
4275
- return {
4276
- minter: fixedPriceStrategyAddress,
4277
- setupActions: [fixedPriceApproval, callSale]
4278
- };
4279
- }
4280
- function setupMinters({ salesConfig, ...rest }) {
4281
- if (!salesConfig)
4282
- throw new Error("No sales config for token");
4283
- const { currency: currencyAddress } = salesConfig;
4284
- if (currencyAddress === zeroAddress5) {
4285
- return setupFixedPriceMinter({
4286
- ...salesConfig,
4287
- ...rest
4288
- });
4289
- } else {
4290
- return setupErc20Minter({
4291
- ...salesConfig,
4292
- ...rest
4293
- });
4294
- }
4295
- }
4296
- function buildSetupNewToken({
4297
- tokenURI,
4298
- maxSupply = OPEN_EDITION_MINT_SIZE,
4299
- createReferral = zeroAddress5,
4300
- contractVersion
4301
- }) {
4302
- if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
4303
- return encodeFunctionData({
4304
- abi: zoraCreator1155ImplABI4,
4305
- functionName: "setupNewTokenWithCreateReferral",
4306
- args: [tokenURI, BigInt(maxSupply), createReferral]
4307
- });
4308
- }
4309
- if (createReferral !== zeroAddress5) {
4310
- throw new Error(
4311
- "Contract does not support create referral, but one was provided"
4312
- );
4313
- }
4314
- return encodeFunctionData({
4315
- abi: zoraCreator1155ImplABI4,
4316
- functionName: "setupNewToken",
4317
- args: [tokenURI, BigInt(maxSupply)]
4318
- });
4319
- }
4320
- function setupRoyaltyConfig({
4321
- royaltyBPS,
4322
- royaltyRecipient,
4323
- nextTokenId
4324
- }) {
4325
- if (royaltyBPS > 0 && royaltyRecipient != zeroAddress5) {
4326
- return encodeFunctionData({
4327
- abi: zoraCreator1155ImplABI4,
4328
- functionName: "updateRoyaltiesForToken",
4329
- args: [
4330
- nextTokenId,
4331
- {
4332
- royaltyBPS,
4333
- royaltyRecipient,
4334
- royaltyMintSchedule: 0
4335
- }
4336
- ]
4337
- });
4338
- }
4339
- return null;
4340
- }
4341
- function makeAdminMintCall({
4342
- ownerAddress,
4343
- mintQuantity,
4344
- nextTokenId
4345
- }) {
4346
- if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
4347
- return null;
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);
4348
4317
  }
4349
- return encodeFunctionData({
4350
- abi: zoraCreator1155ImplABI4,
4351
- functionName: "adminMint",
4352
- args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
4353
- });
4354
- }
4355
- function constructCreate1155TokenCalls(props) {
4356
- const {
4357
- chainId,
4358
- nextTokenId,
4359
- mintToCreatorCount,
4360
- ownerAddress,
4361
- contractVersion
4362
- } = props;
4363
- const new1155TokenPropsWithDefaults = applyNew1155Defaults(
4364
- props,
4365
- ownerAddress
4366
- );
4367
- const verifyTokenIdExpected = encodeFunctionData({
4368
- abi: zoraCreator1155ImplABI4,
4369
- functionName: "assumeLastTokenIdMatches",
4370
- args: [nextTokenId - 1n]
4371
- });
4372
- const setupNewToken = buildSetupNewToken({
4373
- tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
4374
- maxSupply: new1155TokenPropsWithDefaults.maxSupply,
4375
- createReferral: new1155TokenPropsWithDefaults.createReferral,
4376
- contractVersion
4377
- });
4378
- const royaltyConfig = setupRoyaltyConfig({
4379
- royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
4380
- royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
4381
- nextTokenId
4382
- });
4383
- const { minter, setupActions: mintersSetup } = setupMinters({
4384
- tokenId: nextTokenId,
4385
- chainId,
4386
- fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
4387
- salesConfig: new1155TokenPropsWithDefaults.salesConfig
4388
- });
4389
- const adminMintCall = makeAdminMintCall({
4390
- ownerAddress,
4391
- mintQuantity: mintToCreatorCount,
4392
- nextTokenId
4393
- });
4394
- const setupActions = [
4395
- verifyTokenIdExpected,
4396
- setupNewToken,
4397
- ...mintersSetup,
4398
- royaltyConfig,
4399
- adminMintCall
4400
- ].filter((item) => item !== null);
4401
- return {
4402
- setupActions,
4403
- minter,
4404
- newToken: new1155TokenPropsWithDefaults
4405
- };
4318
+ throw new Error("Unknown type, must be binary type");
4406
4319
  }
4407
- var contractSupportsMintRewards = (contractVersion, contractStandard) => {
4408
- if (!contractStandard || !contractVersion) {
4409
- return false;
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");
4410
4325
  }
4411
- const semVerContractVersion = semver3.coerce(contractVersion)?.raw;
4412
- if (!semVerContractVersion)
4413
- return false;
4414
- if (contractStandard === "ERC1155") {
4415
- return semver3.gte(semVerContractVersion, "1.3.5");
4416
- } else {
4417
- return semver3.gte(semVerContractVersion, "14.0.0");
4326
+ var BASE_MAP = new Uint8Array(256);
4327
+ for (var j = 0; j < BASE_MAP.length; j++) {
4328
+ BASE_MAP[j] = 255;
4418
4329
  }
4419
- };
4420
-
4421
- // src/create/1155-create-helper.ts
4422
- var ROYALTY_BPS_DEFAULT = 1e3;
4423
- var getTokenIdFromCreateReceipt = (receipt) => {
4424
- for (const data of receipt.logs) {
4425
- try {
4426
- const decodedLog = decodeEventLog2({
4427
- abi: zoraCreator1155ImplABI5,
4428
- eventName: "SetupNewToken",
4429
- ...data
4430
- });
4431
- if (decodedLog && decodedLog.eventName === "SetupNewToken") {
4432
- return decodedLog.args.tokenId;
4433
- }
4434
- } catch (err) {
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");
4435
4335
  }
4336
+ BASE_MAP[xc] = i;
4436
4337
  }
4437
- throw new Error(
4438
- "No event found in receipt that could be used to get tokenId"
4439
- );
4440
- };
4441
- var getContractAddressFromReceipt = (receipt) => {
4442
- for (const data of receipt.logs) {
4443
- try {
4444
- const decodedLog = decodeEventLog2({
4445
- abi: zoraCreator1155FactoryImplABI2,
4446
- eventName: "SetupNewContract",
4447
- ...data
4448
- });
4449
- if (decodedLog && decodedLog.eventName === "SetupNewContract") {
4450
- return decodedLog.args.newContract;
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;
4451
4373
  }
4452
- } 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]);
4453
4387
  }
4388
+ return str;
4454
4389
  }
4455
- throw new Error(
4456
- "No event found in receipt that could be used to get contract address"
4457
- );
4458
- };
4459
- function makeCreateContractAndTokenCall({
4460
- account,
4461
- contract,
4462
- royaltyBPS,
4463
- fundsRecipient,
4464
- tokenSetupActions,
4465
- chainId
4466
- }) {
4467
- const accountAddress = typeof account === "string" ? account : account.address;
4468
- return makeContractParameters({
4469
- abi: zoraCreator1155FactoryImplABI2,
4470
- functionName: "createContractDeterministic",
4471
- account,
4472
- address: zoraCreator1155FactoryImplAddress2[chainId],
4473
- args: [
4474
- contract.uri,
4475
- contract.name,
4476
- {
4477
- // deprecated
4478
- royaltyMintSchedule: 0,
4479
- royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
4480
- royaltyRecipient: fundsRecipient || accountAddress
4481
- },
4482
- contract.defaultAdmin || accountAddress,
4483
- tokenSetupActions
4484
- ]
4485
- });
4390
+ function decodeUnsafe(source) {
4391
+ if (typeof source !== "string") {
4392
+ throw new TypeError("Expected String");
4393
+ }
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;
4439
+ }
4440
+ function decode5(string) {
4441
+ var buffer = decodeUnsafe(string);
4442
+ if (buffer) {
4443
+ return buffer;
4444
+ }
4445
+ throw new Error(`Non-${name} character`);
4446
+ }
4447
+ return {
4448
+ encode: encode3,
4449
+ decodeUnsafe,
4450
+ decode: decode5
4451
+ };
4486
4452
  }
4487
- function makeCreateTokenCall({
4488
- contractAddress,
4489
- account,
4490
- tokenSetupActions
4491
- }) {
4492
- return makeContractParameters({
4493
- abi: zoraCreator1155ImplABI5,
4494
- functionName: "multicall",
4495
- account,
4496
- address: contractAddress,
4497
- args: [tokenSetupActions]
4453
+ var src = base2;
4454
+ var _brrp__multiformats_scope_baseX = src;
4455
+ var base_x_default = _brrp__multiformats_scope_baseX;
4456
+
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");
4472
+ }
4473
+ }
4474
+ };
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");
4485
+ }
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");
4497
+ }
4498
+ }
4499
+ or(decoder) {
4500
+ return or(this, decoder);
4501
+ }
4502
+ };
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
+ }
4520
+ };
4521
+ function or(left, right) {
4522
+ return new ComposedDecoder({
4523
+ ...left.decoders ?? { [left.prefix]: left },
4524
+ ...right.decoders ?? { [right.prefix]: right }
4498
4525
  });
4499
4526
  }
4500
- var Create1155Client = class {
4501
- constructor({
4502
- chainId,
4503
- publicClient
4504
- }) {
4505
- this.chainId = chainId;
4506
- this.publicClient = publicClient;
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);
4507
4541
  }
4508
- async createNew1155(props) {
4509
- return createNew1155ContractAndToken({
4510
- ...props,
4511
- publicClient: this.publicClient,
4512
- chainId: this.chainId
4513
- });
4542
+ encode(input) {
4543
+ return this.encoder.encode(input);
4514
4544
  }
4515
- async createNew1155OnExistingContract({
4516
- contractAddress: contract,
4517
- account,
4518
- token,
4519
- getAdditionalSetupActions
4520
- }) {
4521
- return createNew1155Token({
4522
- contractAddress: contract,
4523
- account,
4524
- token,
4525
- getAdditionalSetupActions,
4526
- publicClient: this.publicClient,
4527
- chainId: this.chainId
4528
- });
4545
+ decode(input) {
4546
+ return this.decoder.decode(input);
4529
4547
  }
4530
4548
  };
4531
- async function createNew1155ContractAndToken({
4532
- contract,
4533
- account,
4534
- chainId,
4535
- token,
4536
- publicClient,
4537
- getAdditionalSetupActions
4538
- }) {
4539
- const nextTokenId = 1n;
4540
- const contractVersion = new1155ContractVersion(chainId);
4541
- const {
4542
- minter,
4543
- newToken,
4544
- setupActions: tokenSetupActions
4545
- } = prepareSetupActions({
4546
- chainId,
4547
- account,
4548
- contractVersion,
4549
- nextTokenId,
4550
- token,
4551
- getAdditionalSetupActions
4549
+ function from({ name, prefix, encode: encode3, decode: decode5 }) {
4550
+ return new Codec(name, prefix, encode3, decode5);
4551
+ }
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))
4552
4559
  });
4553
- const request = makeCreateContractAndTokenCall({
4554
- contract,
4555
- account,
4556
- chainId,
4557
- tokenSetupActions,
4558
- fundsRecipient: token.payoutRecipient,
4559
- royaltyBPS: token.royaltyBPS
4560
- });
4561
- const contractAddress = await getDeterministicContractAddress({
4562
- account,
4563
- publicClient,
4564
- setupActions: tokenSetupActions,
4565
- chainId,
4566
- contract
4567
- });
4568
- return {
4569
- parameters: request,
4570
- tokenSetupActions,
4571
- newTokenId: nextTokenId,
4572
- newToken,
4573
- contractAddress,
4574
- contractVersion,
4575
- minter
4576
- };
4577
- }
4578
- async function createNew1155Token({
4579
- contractAddress,
4580
- account,
4581
- getAdditionalSetupActions,
4582
- token,
4583
- publicClient,
4584
- chainId
4585
- }) {
4586
- const { nextTokenId, contractVersion } = await getContractInfoExistingContract({
4587
- publicClient,
4588
- contractAddress
4589
- });
4590
- const {
4591
- minter,
4592
- newToken,
4593
- setupActions: tokenSetupActions
4594
- } = prepareSetupActions({
4595
- chainId,
4596
- account,
4597
- contractVersion,
4598
- nextTokenId,
4599
- token,
4600
- getAdditionalSetupActions
4601
- });
4602
- const request = makeCreateTokenCall({
4603
- contractAddress,
4604
- account,
4605
- tokenSetupActions
4606
- });
4607
- return {
4608
- parameters: request,
4609
- tokenSetupActions,
4610
- newTokenId: nextTokenId,
4611
- newToken,
4612
- contractVersion,
4613
- minter
4614
- };
4615
- }
4616
- function prepareSetupActions({
4617
- chainId,
4618
- account,
4619
- contractVersion,
4620
- nextTokenId,
4621
- token,
4622
- getAdditionalSetupActions
4623
- }) {
4624
- const {
4625
- minter,
4626
- newToken,
4627
- setupActions: tokenSetupActions
4628
- } = constructCreate1155TokenCalls({
4629
- chainId,
4630
- ownerAddress: account,
4631
- contractVersion,
4632
- nextTokenId,
4633
- ...token
4634
- });
4635
- const setupActions = getAdditionalSetupActions ? [
4636
- ...getAdditionalSetupActions({
4637
- tokenId: nextTokenId
4638
- }),
4639
- ...tokenSetupActions
4640
- ] : tokenSetupActions;
4641
- return { minter, newToken, setupActions };
4642
4560
  }
4643
-
4644
- // src/sparks/mints-queries.ts
4645
- var getMintsAccountBalanceWithPriceQuery = (account) => {
4646
- const query = `
4647
- query GetMintAccountBalances($account: String!) {
4648
- mintAccountBalances(where: { account: $account }) {
4649
- balance
4650
- mintToken {
4651
- id
4652
- pricePerToken
4653
- }
4654
- }
4561
+ function decode(string, alphabet, bitsPerChar, name) {
4562
+ const codes = {};
4563
+ for (let i = 0; i < alphabet.length; ++i) {
4564
+ codes[alphabet[i]] = i;
4565
+ }
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`);
4655
4578
  }
4656
- `;
4657
- return {
4658
- query,
4659
- variables: { account }
4660
- };
4661
- };
4662
- var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
4663
- const parsed = mintAccountBalances.map((r) => {
4664
- return {
4665
- tokenId: BigInt(r.mintToken.id),
4666
- quantity: BigInt(r.balance),
4667
- pricePerToken: BigInt(r.mintToken.pricePerToken)
4668
- };
4669
- });
4670
- const sorted = parsed.sort((a, b) => {
4671
- if (a.pricePerToken < b.pricePerToken) {
4672
- return -1;
4579
+ buffer = buffer << bitsPerChar | value;
4580
+ bits += bitsPerChar;
4581
+ if (bits >= 8) {
4582
+ bits -= 8;
4583
+ out[written++] = 255 & buffer >> bits;
4673
4584
  }
4674
- return 1;
4675
- });
4676
- let remainingQuantity = quantityToCollect;
4677
- const tokenIds = [];
4678
- const quantities = [];
4679
- while (remainingQuantity > 0) {
4680
- const next = sorted.shift();
4681
- if (!next) {
4682
- throw new Error("Not enough MINTs to collect with");
4585
+ }
4586
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
4587
+ throw new SyntaxError("Unexpected end of data");
4588
+ }
4589
+ return out;
4590
+ }
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];
4683
4603
  }
4684
- const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
4685
- tokenIds.push(next.tokenId);
4686
- quantities.push(quantityToUse);
4687
- remainingQuantity -= quantityToUse;
4688
4604
  }
4689
- return {
4690
- tokenIds,
4691
- quantities
4692
- };
4693
- };
4694
- var sumBalances = (mintAccountBalances) => {
4695
- return mintAccountBalances.reduce((acc, curr) => {
4696
- return acc + BigInt(curr.balance);
4697
- }, BigInt(0));
4698
- };
4605
+ if (bits !== 0) {
4606
+ out += alphabet[mask & buffer << bitsPerChar - bits];
4607
+ }
4608
+ if (pad) {
4609
+ while ((out.length * bitsPerChar & 7) !== 0) {
4610
+ out += "=";
4611
+ }
4612
+ }
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);
4624
+ }
4625
+ });
4626
+ }
4699
4627
 
4700
- // src/sparks/sparks-contracts.ts
4701
- import {
4702
- mintsSafeTransferBatchTypedDataDefinition,
4703
- mintsSafeTransferTypedDataDefinition,
4704
- zoraMints1155Config,
4705
- zoraMintsManagerImplABI,
4706
- zoraMintsManagerImplAddress,
4707
- zoraMintsManagerImplConfig,
4708
- zoraSparksManagerImplABI,
4709
- zoraSparksManagerImplAddress
4710
- } from "@zoralabs/protocol-deployments";
4711
- import {
4712
- decodeErrorResult,
4713
- encodeFunctionData as encodeFunctionData2,
4714
- zeroAddress as zeroAddress6
4715
- } from "viem";
4716
- var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
4717
- var mintWithEthParams = ({
4718
- tokenId,
4719
- quantity,
4720
- recipient,
4721
- chainId,
4722
- pricePerMint,
4723
- account
4724
- }) => makeContractParameters({
4725
- abi: zoraSparksManagerImplABI,
4726
- address: zoraSparksManagerImplAddress[chainId],
4727
- functionName: "mintWithEth",
4728
- args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
4729
- value: pricePerMint * quantity,
4730
- account
4628
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
4629
+ var base32 = rfc4648({
4630
+ prefix: "b",
4631
+ name: "base32",
4632
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
4633
+ bitsPerChar: 5
4731
4634
  });
4732
- var getPaidMintValue = (quantities, pricePerMint) => {
4733
- if (!pricePerMint || pricePerMint === 0n)
4734
- return;
4735
- return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
4736
- };
4737
- var mintsBalanceOfAccountParams = ({
4738
- account,
4739
- chainId
4740
- }) => ({
4741
- abi: zoraMints1155Config.abi,
4742
- address: zoraMints1155Config.address[chainId],
4743
- functionName: "balanceOfAccount",
4744
- args: [account]
4635
+ var base32upper = rfc4648({
4636
+ prefix: "B",
4637
+ name: "base32upper",
4638
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
4639
+ bitsPerChar: 5
4745
4640
  });
4746
- var encodeCollectOnManager = ({
4747
- zoraCreator1155Contract,
4748
- minter,
4749
- zoraCreator1155TokenId,
4750
- mintArguments
4751
- }) => encodeFunctionData2({
4752
- abi: zoraMintsManagerImplConfig.abi,
4753
- functionName: "collect",
4754
- args: [
4755
- zoraCreator1155Contract,
4756
- minter,
4757
- zoraCreator1155TokenId,
4758
- mintArguments
4759
- ]
4641
+ var base32pad = rfc4648({
4642
+ prefix: "c",
4643
+ name: "base32pad",
4644
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
4645
+ bitsPerChar: 5
4760
4646
  });
4761
- function collectWithMintsParams({
4762
- tokenIds,
4763
- quantities,
4764
- chainId,
4765
- paidMintPricePerToken,
4766
- account,
4767
- mintArguments,
4768
- minter,
4769
- zoraCreator1155Contract,
4770
- zoraCreator1155TokenId
4771
- }) {
4772
- const call = encodeCollectOnManager({
4773
- tokenIds,
4774
- quantities,
4775
- zoraCreator1155Contract,
4776
- zoraCreator1155TokenId,
4777
- minter,
4778
- mintArguments
4779
- });
4780
- return makeContractParameters({
4781
- abi: zoraMints1155Config.abi,
4782
- address: zoraMints1155Config.address[chainId],
4783
- functionName: "transferBatchToManagerAndCall",
4784
- args: [tokenIds, quantities, call],
4785
- // if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
4786
- // for the paid mint cost.
4787
- value: getPaidMintValue(quantities, paidMintPricePerToken),
4788
- account
4789
- });
4790
- }
4791
- function getMintsEthPrice({
4792
- publicClient
4793
- }) {
4794
- const chainId = publicClient.chain?.id;
4795
- if (!chainId || !zoraMintsManagerImplAddress[chainId]) {
4796
- throw new Error(`Chain id ${chainId} not supported`);
4797
- }
4798
- return publicClient.readContract({
4799
- abi: zoraMintsManagerImplABI,
4800
- address: zoraMintsManagerImplAddress[chainId],
4801
- functionName: "getEthPrice"
4802
- });
4803
- }
4804
- function makePermitTransferBatchAndTypeData({
4805
- tokenIds,
4806
- quantities,
4807
- chainId,
4808
- mintsOwner,
4809
- to,
4810
- nonce,
4811
- deadline,
4812
- safeTransferData
4813
- }) {
4814
- const permit = {
4815
- owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
4816
- to,
4817
- tokenIds,
4818
- quantities,
4819
- deadline,
4820
- nonce,
4821
- safeTransferData
4822
- };
4823
- const typedData = {
4824
- ...mintsSafeTransferBatchTypedDataDefinition({
4825
- chainId,
4826
- message: permit
4827
- }),
4828
- account: mintsOwner
4829
- };
4830
- return {
4831
- permit,
4832
- typedData
4833
- };
4834
- }
4835
- function makePermitTransferTypeData({
4836
- tokenId,
4837
- quantity,
4838
- chainId,
4839
- mintsOwner,
4840
- to,
4841
- nonce,
4842
- deadline,
4843
- safeTransferData
4844
- }) {
4845
- const permit = {
4846
- owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
4847
- to,
4848
- tokenId,
4849
- quantity,
4850
- deadline,
4851
- nonce,
4852
- safeTransferData
4853
- };
4854
- const typedData = {
4855
- ...mintsSafeTransferTypedDataDefinition({
4856
- chainId,
4857
- message: permit
4858
- }),
4859
- account: mintsOwner
4860
- };
4861
- return {
4862
- permit,
4863
- typedData
4864
- };
4865
- }
4866
- var encodePremintOnManager = ({
4867
- contractCreationConfig,
4868
- premintConfig,
4869
- premintSignature,
4870
- mintArguments,
4871
- signerContract = zeroAddress6
4872
- }) => encodeFunctionData2({
4873
- abi: zoraMintsManagerImplConfig.abi,
4874
- functionName: "collectPremintV2",
4875
- args: [
4876
- contractCreationConfig,
4877
- premintConfig,
4878
- premintSignature,
4879
- mintArguments,
4880
- signerContract
4881
- ]
4647
+ var base32padupper = rfc4648({
4648
+ prefix: "C",
4649
+ name: "base32padupper",
4650
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
4651
+ bitsPerChar: 5
4652
+ });
4653
+ var base32hex = rfc4648({
4654
+ prefix: "v",
4655
+ name: "base32hex",
4656
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
4657
+ bitsPerChar: 5
4658
+ });
4659
+ var base32hexupper = rfc4648({
4660
+ prefix: "V",
4661
+ name: "base32hexupper",
4662
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
4663
+ bitsPerChar: 5
4664
+ });
4665
+ var base32hexpad = rfc4648({
4666
+ prefix: "t",
4667
+ name: "base32hexpad",
4668
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
4669
+ bitsPerChar: 5
4670
+ });
4671
+ var base32hexpadupper = rfc4648({
4672
+ prefix: "T",
4673
+ name: "base32hexpadupper",
4674
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
4675
+ bitsPerChar: 5
4676
+ });
4677
+ var base32z = rfc4648({
4678
+ prefix: "h",
4679
+ name: "base32z",
4680
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
4681
+ bitsPerChar: 5
4882
4682
  });
4883
- var makePermitToCollectPremintOrNonPremint = ({
4884
- mintsOwner,
4885
- chainId,
4886
- deadline,
4887
- tokenIds,
4888
- // this quantity of MINTs will be used to collect premint
4889
- // and will be burned. This same quantity is the quantity of
4890
- // premint to collect.
4891
- quantities,
4892
- nonce,
4893
- premint,
4894
- collect
4895
- }) => {
4896
- let safeTransferData;
4897
- if (premint) {
4898
- safeTransferData = encodePremintOnManager(premint);
4899
- } else if (collect) {
4900
- safeTransferData = encodeCollectOnManager(collect);
4901
- } else {
4902
- throw new Error("Invalid operation");
4903
- }
4904
- return makePermitTransferBatchAndTypeData({
4905
- tokenIds,
4906
- quantities,
4907
- chainId,
4908
- mintsOwner,
4909
- nonce,
4910
- deadline,
4911
- safeTransferData,
4912
- to: zoraMintsManagerImplConfig.address[chainId]
4913
- });
4914
- };
4915
- function collectPremintV2WithMintsParams({
4916
- tokenIds,
4917
- quantities,
4918
- paidMintPricePerToken,
4919
- account,
4920
- chainId,
4921
- ...rest
4922
- }) {
4923
- const call = encodePremintOnManager({
4924
- ...rest
4925
- });
4926
- return makeContractParameters({
4927
- abi: zoraMints1155Config.abi,
4928
- address: zoraMints1155Config.address[chainId],
4929
- functionName: "transferBatchToManagerAndCall",
4930
- args: [tokenIds, quantities, call],
4931
- value: getPaidMintValue(quantities, paidMintPricePerToken),
4932
- account
4933
- });
4934
- }
4935
- function decodeCallFailedError(error) {
4936
- if (error.data?.errorName !== "CallFailed")
4937
- throw new Error("Not a CallFailed error");
4938
- const internalErrorData = error.data?.args?.[0];
4939
- return decodeErrorResult({
4940
- abi: zoraMintsManagerImplABI,
4941
- data: internalErrorData
4942
- });
4943
- }
4944
-
4945
- // src/sdk.ts
4946
- function createCreatorClient(clientConfig) {
4947
- const premintClient = new PremintClient({
4948
- chainId: clientConfig.chainId,
4949
- publicClient: clientConfig.publicClient,
4950
- premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
4951
- });
4952
- const create1155CreatorClient = new Create1155Client({
4953
- chainId: clientConfig.chainId,
4954
- publicClient: clientConfig.publicClient
4955
- });
4956
- return {
4957
- createPremint: (p) => premintClient.createPremint(p),
4958
- updatePremint: (p) => premintClient.updatePremint(p),
4959
- deletePremint: (p) => premintClient.deletePremint(p),
4960
- create1155: (p) => create1155CreatorClient.createNew1155(p),
4961
- create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
4962
- };
4963
- }
4964
- function createCollectorClient(params) {
4965
- const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
4966
- const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
4967
- const mintClient = new MintClient({
4968
- publicClient: params.publicClient,
4969
- premintGetter: premintGetterToUse,
4970
- mintGetter: mintGetterToUse
4971
- });
4972
- return {
4973
- getPremint: (p) => premintGetterToUse.get({
4974
- collectionAddress: p.address,
4975
- uid: p.uid
4976
- }),
4977
- getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
4978
- getToken: (p) => mintClient.get(p),
4979
- getTokensOfContract: (p) => mintClient.getOfContract(p),
4980
- mint: (p) => mintClient.mint(p),
4981
- getMintCosts: (p) => mintClient.getMintCosts(p)
4982
- };
4983
- }
4984
-
4985
- // src/ipfs/arweave.ts
4986
- function isArweaveURL(url) {
4987
- return url && typeof url === "string" ? url.startsWith("ar://") : false;
4988
- }
4989
4683
 
4990
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
4991
- var empty = new Uint8Array(0);
4992
- function equals(aa, bb) {
4993
- if (aa === bb)
4994
- return true;
4995
- if (aa.byteLength !== bb.byteLength) {
4996
- return false;
4997
- }
4998
- for (let ii = 0; ii < aa.byteLength; ii++) {
4999
- if (aa[ii] !== bb[ii]) {
5000
- return false;
5001
- }
5002
- }
5003
- return true;
5004
- }
5005
- function coerce4(o) {
5006
- if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
5007
- return o;
5008
- if (o instanceof ArrayBuffer)
5009
- return new Uint8Array(o);
5010
- if (ArrayBuffer.isView(o)) {
5011
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
5012
- }
5013
- throw new Error("Unknown type, must be binary type");
5014
- }
4684
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
4685
+ var base58btc = baseX({
4686
+ name: "base58btc",
4687
+ prefix: "z",
4688
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
4689
+ });
4690
+ var base58flickr = baseX({
4691
+ name: "base58flickr",
4692
+ prefix: "Z",
4693
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
4694
+ });
5015
4695
 
5016
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
5017
- function base2(ALPHABET, name) {
5018
- if (ALPHABET.length >= 255) {
5019
- throw new TypeError("Alphabet too long");
5020
- }
5021
- var BASE_MAP = new Uint8Array(256);
5022
- for (var j = 0; j < BASE_MAP.length; j++) {
5023
- BASE_MAP[j] = 255;
5024
- }
5025
- for (var i = 0; i < ALPHABET.length; i++) {
5026
- var x = ALPHABET.charAt(i);
5027
- var xc = x.charCodeAt(0);
5028
- if (BASE_MAP[xc] !== 255) {
5029
- throw new TypeError(x + " is ambiguous");
5030
- }
5031
- BASE_MAP[xc] = i;
5032
- }
5033
- var BASE = ALPHABET.length;
5034
- var LEADER = ALPHABET.charAt(0);
5035
- var FACTOR = Math.log(BASE) / Math.log(256);
5036
- var iFACTOR = Math.log(256) / Math.log(BASE);
5037
- function encode3(source) {
5038
- if (source instanceof Uint8Array)
5039
- ;
5040
- else if (ArrayBuffer.isView(source)) {
5041
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
5042
- } else if (Array.isArray(source)) {
5043
- source = Uint8Array.from(source);
5044
- }
5045
- if (!(source instanceof Uint8Array)) {
5046
- throw new TypeError("Expected Uint8Array");
5047
- }
5048
- if (source.length === 0) {
5049
- return "";
5050
- }
5051
- var zeroes = 0;
5052
- var length2 = 0;
5053
- var pbegin = 0;
5054
- var pend = source.length;
5055
- while (pbegin !== pend && source[pbegin] === 0) {
5056
- pbegin++;
5057
- zeroes++;
5058
- }
5059
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
5060
- var b58 = new Uint8Array(size);
5061
- while (pbegin !== pend) {
5062
- var carry = source[pbegin];
5063
- var i2 = 0;
5064
- for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
5065
- carry += 256 * b58[it1] >>> 0;
5066
- b58[it1] = carry % BASE >>> 0;
5067
- carry = carry / BASE >>> 0;
5068
- }
5069
- if (carry !== 0) {
5070
- throw new Error("Non-zero carry");
5071
- }
5072
- length2 = i2;
5073
- pbegin++;
5074
- }
5075
- var it2 = size - length2;
5076
- while (it2 !== size && b58[it2] === 0) {
5077
- it2++;
5078
- }
5079
- var str = LEADER.repeat(zeroes);
5080
- for (; it2 < size; ++it2) {
5081
- str += ALPHABET.charAt(b58[it2]);
5082
- }
5083
- return str;
4696
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
4697
+ var encode_1 = encode2;
4698
+ var MSB = 128;
4699
+ var REST = 127;
4700
+ var MSBALL = ~REST;
4701
+ var INT = Math.pow(2, 31);
4702
+ function encode2(num, out, offset) {
4703
+ out = out || [];
4704
+ offset = offset || 0;
4705
+ var oldOffset = offset;
4706
+ while (num >= INT) {
4707
+ out[offset++] = num & 255 | MSB;
4708
+ num /= 128;
5084
4709
  }
5085
- function decodeUnsafe(source) {
5086
- if (typeof source !== "string") {
5087
- throw new TypeError("Expected String");
5088
- }
5089
- if (source.length === 0) {
5090
- return new Uint8Array();
5091
- }
5092
- var psz = 0;
5093
- if (source[psz] === " ") {
5094
- return;
5095
- }
5096
- var zeroes = 0;
5097
- var length2 = 0;
5098
- while (source[psz] === LEADER) {
5099
- zeroes++;
5100
- psz++;
5101
- }
5102
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
5103
- var b256 = new Uint8Array(size);
5104
- while (source[psz]) {
5105
- var carry = BASE_MAP[source.charCodeAt(psz)];
5106
- if (carry === 255) {
5107
- return;
5108
- }
5109
- var i2 = 0;
5110
- for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
5111
- carry += BASE * b256[it3] >>> 0;
5112
- b256[it3] = carry % 256 >>> 0;
5113
- carry = carry / 256 >>> 0;
5114
- }
5115
- if (carry !== 0) {
5116
- throw new Error("Non-zero carry");
5117
- }
5118
- length2 = i2;
5119
- psz++;
5120
- }
5121
- if (source[psz] === " ") {
5122
- return;
5123
- }
5124
- var it4 = size - length2;
5125
- while (it4 !== size && b256[it4] === 0) {
5126
- it4++;
5127
- }
5128
- var vch = new Uint8Array(zeroes + (size - it4));
5129
- var j2 = zeroes;
5130
- while (it4 !== size) {
5131
- vch[j2++] = b256[it4++];
5132
- }
5133
- return vch;
4710
+ while (num & MSBALL) {
4711
+ out[offset++] = num & 255 | MSB;
4712
+ num >>>= 7;
5134
4713
  }
5135
- function decode5(string) {
5136
- var buffer = decodeUnsafe(string);
5137
- if (buffer) {
5138
- return buffer;
4714
+ out[offset] = num | 0;
4715
+ encode2.bytes = offset - oldOffset + 1;
4716
+ return out;
4717
+ }
4718
+ var decode2 = read;
4719
+ var MSB$1 = 128;
4720
+ var REST$1 = 127;
4721
+ function read(buf, offset) {
4722
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
4723
+ do {
4724
+ if (counter >= l) {
4725
+ read.bytes = 0;
4726
+ throw new RangeError("Could not decode varint");
5139
4727
  }
5140
- throw new Error(`Non-${name} character`);
5141
- }
5142
- return {
5143
- encode: encode3,
5144
- decodeUnsafe,
5145
- decode: decode5
5146
- };
4728
+ b = buf[counter++];
4729
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
4730
+ shift += 7;
4731
+ } while (b >= MSB$1);
4732
+ read.bytes = counter - offset;
4733
+ return res;
5147
4734
  }
5148
- var src = base2;
5149
- var _brrp__multiformats_scope_baseX = src;
5150
- var base_x_default = _brrp__multiformats_scope_baseX;
4735
+ var N1 = Math.pow(2, 7);
4736
+ var N2 = Math.pow(2, 14);
4737
+ var N3 = Math.pow(2, 21);
4738
+ var N4 = Math.pow(2, 28);
4739
+ var N5 = Math.pow(2, 35);
4740
+ var N6 = Math.pow(2, 42);
4741
+ var N7 = Math.pow(2, 49);
4742
+ var N8 = Math.pow(2, 56);
4743
+ var N9 = Math.pow(2, 63);
4744
+ var length = function(value) {
4745
+ return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
4746
+ };
4747
+ var varint = {
4748
+ encode: encode_1,
4749
+ decode: decode2,
4750
+ encodingLength: length
4751
+ };
4752
+ var _brrp_varint = varint;
4753
+ var varint_default = _brrp_varint;
5151
4754
 
5152
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
5153
- var Encoder = class {
5154
- constructor(name, prefix, baseEncode) {
5155
- __publicField(this, "name");
5156
- __publicField(this, "prefix");
5157
- __publicField(this, "baseEncode");
5158
- this.name = name;
5159
- this.prefix = prefix;
5160
- this.baseEncode = baseEncode;
4755
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
4756
+ function decode3(data, offset = 0) {
4757
+ const code = varint_default.decode(data, offset);
4758
+ return [code, varint_default.decode.bytes];
4759
+ }
4760
+ function encodeTo(int, target, offset = 0) {
4761
+ varint_default.encode(int, target, offset);
4762
+ return target;
4763
+ }
4764
+ function encodingLength(int) {
4765
+ return varint_default.encodingLength(int);
4766
+ }
4767
+
4768
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
4769
+ function create(code, digest) {
4770
+ const size = digest.byteLength;
4771
+ const sizeOffset = encodingLength(code);
4772
+ const digestOffset = sizeOffset + encodingLength(size);
4773
+ const bytes = new Uint8Array(digestOffset + size);
4774
+ encodeTo(code, bytes, 0);
4775
+ encodeTo(size, bytes, sizeOffset);
4776
+ bytes.set(digest, digestOffset);
4777
+ return new Digest(code, size, digest, bytes);
4778
+ }
4779
+ function decode4(multihash) {
4780
+ const bytes = coerce2(multihash);
4781
+ const [code, sizeOffset] = decode3(bytes);
4782
+ const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
4783
+ const digest = bytes.subarray(sizeOffset + digestOffset);
4784
+ if (digest.byteLength !== size) {
4785
+ throw new Error("Incorrect length");
5161
4786
  }
5162
- encode(bytes) {
5163
- if (bytes instanceof Uint8Array) {
5164
- return `${this.prefix}${this.baseEncode(bytes)}`;
5165
- } else {
5166
- throw Error("Unknown type, must be binary type");
5167
- }
4787
+ return new Digest(code, size, digest, bytes);
4788
+ }
4789
+ function equals2(a, b) {
4790
+ if (a === b) {
4791
+ return true;
4792
+ } else {
4793
+ const data = b;
4794
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
4795
+ }
4796
+ }
4797
+ var Digest = class {
4798
+ /**
4799
+ * Creates a multihash digest.
4800
+ */
4801
+ constructor(code, size, digest, bytes) {
4802
+ __publicField(this, "code");
4803
+ __publicField(this, "size");
4804
+ __publicField(this, "digest");
4805
+ __publicField(this, "bytes");
4806
+ this.code = code;
4807
+ this.size = size;
4808
+ this.digest = digest;
4809
+ this.bytes = bytes;
5168
4810
  }
5169
4811
  };
5170
- var Decoder = class {
5171
- constructor(name, prefix, baseDecode) {
5172
- __publicField(this, "name");
5173
- __publicField(this, "prefix");
5174
- __publicField(this, "baseDecode");
5175
- __publicField(this, "prefixCodePoint");
5176
- this.name = name;
5177
- this.prefix = prefix;
5178
- if (prefix.codePointAt(0) === void 0) {
5179
- throw new Error("Invalid prefix character");
5180
- }
5181
- this.prefixCodePoint = prefix.codePointAt(0);
5182
- this.baseDecode = baseDecode;
4812
+
4813
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
4814
+ function format(link, base3) {
4815
+ const { bytes, version } = link;
4816
+ switch (version) {
4817
+ case 0:
4818
+ return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
4819
+ default:
4820
+ return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
5183
4821
  }
5184
- decode(text) {
5185
- if (typeof text === "string") {
5186
- if (text.codePointAt(0) !== this.prefixCodePoint) {
5187
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
5188
- }
5189
- return this.baseDecode(text.slice(this.prefix.length));
5190
- } else {
5191
- throw Error("Can only multibase decode strings");
5192
- }
4822
+ }
4823
+ var cache = /* @__PURE__ */ new WeakMap();
4824
+ function baseCache(cid) {
4825
+ const baseCache2 = cache.get(cid);
4826
+ if (baseCache2 == null) {
4827
+ const baseCache3 = /* @__PURE__ */ new Map();
4828
+ cache.set(cid, baseCache3);
4829
+ return baseCache3;
5193
4830
  }
5194
- or(decoder) {
5195
- return or(this, decoder);
4831
+ return baseCache2;
4832
+ }
4833
+ var _a;
4834
+ var CID = class _CID {
4835
+ /**
4836
+ * @param version - Version of the CID
4837
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
4838
+ * @param multihash - (Multi)hash of the of the content.
4839
+ */
4840
+ constructor(version, code, multihash, bytes) {
4841
+ __publicField(this, "code");
4842
+ __publicField(this, "version");
4843
+ __publicField(this, "multihash");
4844
+ __publicField(this, "bytes");
4845
+ __publicField(this, "/");
4846
+ __publicField(this, _a, "CID");
4847
+ this.code = code;
4848
+ this.version = version;
4849
+ this.multihash = multihash;
4850
+ this.bytes = bytes;
4851
+ this["/"] = bytes;
5196
4852
  }
5197
- };
5198
- var ComposedDecoder = class {
5199
- constructor(decoders) {
5200
- __publicField(this, "decoders");
5201
- this.decoders = decoders;
4853
+ /**
4854
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
4855
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
4856
+ *
4857
+ * @deprecated
4858
+ */
4859
+ get asCID() {
4860
+ return this;
5202
4861
  }
5203
- or(decoder) {
5204
- return or(this, decoder);
4862
+ // ArrayBufferView
4863
+ get byteOffset() {
4864
+ return this.bytes.byteOffset;
5205
4865
  }
5206
- decode(input) {
5207
- const prefix = input[0];
5208
- const decoder = this.decoders[prefix];
5209
- if (decoder != null) {
5210
- return decoder.decode(input);
5211
- } else {
5212
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
4866
+ // ArrayBufferView
4867
+ get byteLength() {
4868
+ return this.bytes.byteLength;
4869
+ }
4870
+ toV0() {
4871
+ switch (this.version) {
4872
+ case 0: {
4873
+ return this;
4874
+ }
4875
+ case 1: {
4876
+ const { code, multihash } = this;
4877
+ if (code !== DAG_PB_CODE) {
4878
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
4879
+ }
4880
+ if (multihash.code !== SHA_256_CODE) {
4881
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
4882
+ }
4883
+ return _CID.createV0(multihash);
4884
+ }
4885
+ default: {
4886
+ throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
4887
+ }
5213
4888
  }
5214
4889
  }
5215
- };
5216
- function or(left, right) {
5217
- return new ComposedDecoder({
5218
- ...left.decoders ?? { [left.prefix]: left },
5219
- ...right.decoders ?? { [right.prefix]: right }
5220
- });
5221
- }
5222
- var Codec = class {
5223
- constructor(name, prefix, baseEncode, baseDecode) {
5224
- __publicField(this, "name");
5225
- __publicField(this, "prefix");
5226
- __publicField(this, "baseEncode");
5227
- __publicField(this, "baseDecode");
5228
- __publicField(this, "encoder");
5229
- __publicField(this, "decoder");
5230
- this.name = name;
5231
- this.prefix = prefix;
5232
- this.baseEncode = baseEncode;
5233
- this.baseDecode = baseDecode;
5234
- this.encoder = new Encoder(name, prefix, baseEncode);
5235
- this.decoder = new Decoder(name, prefix, baseDecode);
4890
+ toV1() {
4891
+ switch (this.version) {
4892
+ case 0: {
4893
+ const { code, digest } = this.multihash;
4894
+ const multihash = create(code, digest);
4895
+ return _CID.createV1(this.code, multihash);
4896
+ }
4897
+ case 1: {
4898
+ return this;
4899
+ }
4900
+ default: {
4901
+ throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
4902
+ }
4903
+ }
5236
4904
  }
5237
- encode(input) {
5238
- return this.encoder.encode(input);
4905
+ equals(other) {
4906
+ return _CID.equals(this, other);
5239
4907
  }
5240
- decode(input) {
5241
- return this.decoder.decode(input);
4908
+ static equals(self, other) {
4909
+ const unknown = other;
4910
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
5242
4911
  }
5243
- };
5244
- function from({ name, prefix, encode: encode3, decode: decode5 }) {
5245
- return new Codec(name, prefix, encode3, decode5);
5246
- }
5247
- function baseX({ name, prefix, alphabet }) {
5248
- const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
5249
- return from({
5250
- prefix,
5251
- name,
5252
- encode: encode3,
5253
- decode: (text) => coerce4(decode5(text))
5254
- });
5255
- }
5256
- function decode(string, alphabet, bitsPerChar, name) {
5257
- const codes = {};
5258
- for (let i = 0; i < alphabet.length; ++i) {
5259
- codes[alphabet[i]] = i;
4912
+ toString(base3) {
4913
+ return format(this, base3);
5260
4914
  }
5261
- let end = string.length;
5262
- while (string[end - 1] === "=") {
5263
- --end;
4915
+ toJSON() {
4916
+ return { "/": format(this) };
5264
4917
  }
5265
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
5266
- let bits = 0;
5267
- let buffer = 0;
5268
- let written = 0;
5269
- for (let i = 0; i < end; ++i) {
5270
- const value = codes[string[i]];
5271
- if (value === void 0) {
5272
- throw new SyntaxError(`Non-${name} character`);
4918
+ link() {
4919
+ return this;
4920
+ }
4921
+ // Legacy
4922
+ [(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
4923
+ return `CID(${this.toString()})`;
4924
+ }
4925
+ /**
4926
+ * Takes any input `value` and returns a `CID` instance if it was
4927
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
4928
+ * it will return value back. If `value` is not instance of this CID
4929
+ * class, but is compatible CID it will return new instance of this
4930
+ * `CID` class. Otherwise returns null.
4931
+ *
4932
+ * This allows two different incompatible versions of CID library to
4933
+ * co-exist and interop as long as binary interface is compatible.
4934
+ */
4935
+ static asCID(input) {
4936
+ if (input == null) {
4937
+ return null;
5273
4938
  }
5274
- buffer = buffer << bitsPerChar | value;
5275
- bits += bitsPerChar;
5276
- if (bits >= 8) {
5277
- bits -= 8;
5278
- out[written++] = 255 & buffer >> bits;
4939
+ const value = input;
4940
+ if (value instanceof _CID) {
4941
+ return value;
4942
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
4943
+ const { version, code, multihash, bytes } = value;
4944
+ return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
4945
+ } else if (value[cidSymbol] === true) {
4946
+ const { version, multihash, code } = value;
4947
+ const digest = decode4(multihash);
4948
+ return _CID.create(version, code, digest);
4949
+ } else {
4950
+ return null;
5279
4951
  }
5280
4952
  }
5281
- if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
5282
- throw new SyntaxError("Unexpected end of data");
5283
- }
5284
- return out;
5285
- }
5286
- function encode(data, alphabet, bitsPerChar) {
5287
- const pad = alphabet[alphabet.length - 1] === "=";
5288
- const mask = (1 << bitsPerChar) - 1;
5289
- let out = "";
5290
- let bits = 0;
5291
- let buffer = 0;
5292
- for (let i = 0; i < data.length; ++i) {
5293
- buffer = buffer << 8 | data[i];
5294
- bits += 8;
5295
- while (bits > bitsPerChar) {
5296
- bits -= bitsPerChar;
5297
- out += alphabet[mask & buffer >> bits];
4953
+ /**
4954
+ * @param version - Version of the CID
4955
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
4956
+ * @param digest - (Multi)hash of the of the content.
4957
+ */
4958
+ static create(version, code, digest) {
4959
+ if (typeof code !== "number") {
4960
+ throw new Error("String codecs are no longer supported");
4961
+ }
4962
+ if (!(digest.bytes instanceof Uint8Array)) {
4963
+ throw new Error("Invalid digest");
4964
+ }
4965
+ switch (version) {
4966
+ case 0: {
4967
+ if (code !== DAG_PB_CODE) {
4968
+ throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
4969
+ } else {
4970
+ return new _CID(version, code, digest, digest.bytes);
4971
+ }
4972
+ }
4973
+ case 1: {
4974
+ const bytes = encodeCID(version, code, digest.bytes);
4975
+ return new _CID(version, code, digest, bytes);
4976
+ }
4977
+ default: {
4978
+ throw new Error("Invalid version");
4979
+ }
5298
4980
  }
5299
4981
  }
5300
- if (bits !== 0) {
5301
- out += alphabet[mask & buffer << bitsPerChar - bits];
4982
+ /**
4983
+ * Simplified version of `create` for CIDv0.
4984
+ */
4985
+ static createV0(digest) {
4986
+ return _CID.create(0, DAG_PB_CODE, digest);
5302
4987
  }
5303
- if (pad) {
5304
- while ((out.length * bitsPerChar & 7) !== 0) {
5305
- out += "=";
5306
- }
4988
+ /**
4989
+ * Simplified version of `create` for CIDv1.
4990
+ *
4991
+ * @param code - Content encoding format code.
4992
+ * @param digest - Multihash of the content.
4993
+ */
4994
+ static createV1(code, digest) {
4995
+ return _CID.create(1, code, digest);
5307
4996
  }
5308
- return out;
5309
- }
5310
- function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
5311
- return from({
5312
- prefix,
5313
- name,
5314
- encode(input) {
5315
- return encode(input, alphabet, bitsPerChar);
5316
- },
5317
- decode(input) {
5318
- return decode(input, alphabet, bitsPerChar, name);
5319
- }
5320
- });
5321
- }
5322
-
5323
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
5324
- var base32 = rfc4648({
5325
- prefix: "b",
5326
- name: "base32",
5327
- alphabet: "abcdefghijklmnopqrstuvwxyz234567",
5328
- bitsPerChar: 5
5329
- });
5330
- var base32upper = rfc4648({
5331
- prefix: "B",
5332
- name: "base32upper",
5333
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
5334
- bitsPerChar: 5
5335
- });
5336
- var base32pad = rfc4648({
5337
- prefix: "c",
5338
- name: "base32pad",
5339
- alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
5340
- bitsPerChar: 5
5341
- });
5342
- var base32padupper = rfc4648({
5343
- prefix: "C",
5344
- name: "base32padupper",
5345
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
5346
- bitsPerChar: 5
5347
- });
5348
- var base32hex = rfc4648({
5349
- prefix: "v",
5350
- name: "base32hex",
5351
- alphabet: "0123456789abcdefghijklmnopqrstuv",
5352
- bitsPerChar: 5
5353
- });
5354
- var base32hexupper = rfc4648({
5355
- prefix: "V",
5356
- name: "base32hexupper",
5357
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
5358
- bitsPerChar: 5
5359
- });
5360
- var base32hexpad = rfc4648({
5361
- prefix: "t",
5362
- name: "base32hexpad",
5363
- alphabet: "0123456789abcdefghijklmnopqrstuv=",
5364
- bitsPerChar: 5
5365
- });
5366
- var base32hexpadupper = rfc4648({
5367
- prefix: "T",
5368
- name: "base32hexpadupper",
5369
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
5370
- bitsPerChar: 5
5371
- });
5372
- var base32z = rfc4648({
5373
- prefix: "h",
5374
- name: "base32z",
5375
- alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
5376
- bitsPerChar: 5
5377
- });
5378
-
5379
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
5380
- var base58btc = baseX({
5381
- name: "base58btc",
5382
- prefix: "z",
5383
- alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
5384
- });
5385
- var base58flickr = baseX({
5386
- name: "base58flickr",
5387
- prefix: "Z",
5388
- alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
5389
- });
5390
-
5391
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
5392
- var encode_1 = encode2;
5393
- var MSB = 128;
5394
- var REST = 127;
5395
- var MSBALL = ~REST;
5396
- var INT = Math.pow(2, 31);
5397
- function encode2(num, out, offset) {
5398
- out = out || [];
5399
- offset = offset || 0;
5400
- var oldOffset = offset;
5401
- while (num >= INT) {
5402
- out[offset++] = num & 255 | MSB;
5403
- num /= 128;
4997
+ /**
4998
+ * Decoded a CID from its binary representation. The byte array must contain
4999
+ * only the CID with no additional bytes.
5000
+ *
5001
+ * An error will be thrown if the bytes provided do not contain a valid
5002
+ * binary representation of a CID.
5003
+ */
5004
+ static decode(bytes) {
5005
+ const [cid, remainder] = _CID.decodeFirst(bytes);
5006
+ if (remainder.length !== 0) {
5007
+ throw new Error("Incorrect length");
5008
+ }
5009
+ return cid;
5404
5010
  }
5405
- while (num & MSBALL) {
5406
- out[offset++] = num & 255 | MSB;
5407
- num >>>= 7;
5011
+ /**
5012
+ * Decoded a CID from its binary representation at the beginning of a byte
5013
+ * array.
5014
+ *
5015
+ * Returns an array with the first element containing the CID and the second
5016
+ * element containing the remainder of the original byte array. The remainder
5017
+ * will be a zero-length byte array if the provided bytes only contained a
5018
+ * binary CID representation.
5019
+ */
5020
+ static decodeFirst(bytes) {
5021
+ const specs = _CID.inspectBytes(bytes);
5022
+ const prefixSize = specs.size - specs.multihashSize;
5023
+ const multihashBytes = coerce2(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
5024
+ if (multihashBytes.byteLength !== specs.multihashSize) {
5025
+ throw new Error("Incorrect length");
5026
+ }
5027
+ const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
5028
+ const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
5029
+ const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
5030
+ return [cid, bytes.subarray(specs.size)];
5408
5031
  }
5409
- out[offset] = num | 0;
5410
- encode2.bytes = offset - oldOffset + 1;
5411
- return out;
5412
- }
5413
- var decode2 = read;
5414
- var MSB$1 = 128;
5415
- var REST$1 = 127;
5416
- function read(buf, offset) {
5417
- var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
5418
- do {
5419
- if (counter >= l) {
5420
- read.bytes = 0;
5421
- throw new RangeError("Could not decode varint");
5032
+ /**
5033
+ * Inspect the initial bytes of a CID to determine its properties.
5034
+ *
5035
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
5036
+ * bytes but for larger multicodec code values and larger multihash digest
5037
+ * lengths these varints can be quite large. It is recommended that at least
5038
+ * 10 bytes be made available in the `initialBytes` argument for a complete
5039
+ * inspection.
5040
+ */
5041
+ static inspectBytes(initialBytes) {
5042
+ let offset = 0;
5043
+ const next = () => {
5044
+ const [i, length2] = decode3(initialBytes.subarray(offset));
5045
+ offset += length2;
5046
+ return i;
5047
+ };
5048
+ let version = next();
5049
+ let codec = DAG_PB_CODE;
5050
+ if (version === 18) {
5051
+ version = 0;
5052
+ offset = 0;
5053
+ } else {
5054
+ codec = next();
5422
5055
  }
5423
- b = buf[counter++];
5424
- res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
5425
- shift += 7;
5426
- } while (b >= MSB$1);
5427
- read.bytes = counter - offset;
5428
- return res;
5429
- }
5430
- var N1 = Math.pow(2, 7);
5431
- var N2 = Math.pow(2, 14);
5432
- var N3 = Math.pow(2, 21);
5433
- var N4 = Math.pow(2, 28);
5434
- var N5 = Math.pow(2, 35);
5435
- var N6 = Math.pow(2, 42);
5436
- var N7 = Math.pow(2, 49);
5437
- var N8 = Math.pow(2, 56);
5438
- var N9 = Math.pow(2, 63);
5439
- var length = function(value) {
5440
- return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
5441
- };
5442
- var varint = {
5443
- encode: encode_1,
5444
- decode: decode2,
5445
- encodingLength: length
5056
+ if (version !== 0 && version !== 1) {
5057
+ throw new RangeError(`Invalid CID version ${version}`);
5058
+ }
5059
+ const prefixSize = offset;
5060
+ const multihashCode = next();
5061
+ const digestSize = next();
5062
+ const size = offset + digestSize;
5063
+ const multihashSize = size - prefixSize;
5064
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
5065
+ }
5066
+ /**
5067
+ * Takes cid in a string representation and creates an instance. If `base`
5068
+ * decoder is not provided will use a default from the configuration. It will
5069
+ * throw an error if encoding of the CID is not compatible with supplied (or
5070
+ * a default decoder).
5071
+ */
5072
+ static parse(source, base3) {
5073
+ const [prefix, bytes] = parseCIDtoBytes(source, base3);
5074
+ const cid = _CID.decode(bytes);
5075
+ if (cid.version === 0 && source[0] !== "Q") {
5076
+ throw Error("Version 0 CID string must not include multibase prefix");
5077
+ }
5078
+ baseCache(cid).set(prefix, source);
5079
+ return cid;
5080
+ }
5446
5081
  };
5447
- var _brrp_varint = varint;
5448
- var varint_default = _brrp_varint;
5449
-
5450
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
5451
- function decode3(data, offset = 0) {
5452
- const code = varint_default.decode(data, offset);
5453
- return [code, varint_default.decode.bytes];
5454
- }
5455
- function encodeTo(int, target, offset = 0) {
5456
- varint_default.encode(int, target, offset);
5457
- return target;
5458
- }
5459
- function encodingLength(int) {
5460
- return varint_default.encodingLength(int);
5461
- }
5462
-
5463
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
5464
- function create(code, digest) {
5465
- const size = digest.byteLength;
5466
- const sizeOffset = encodingLength(code);
5467
- const digestOffset = sizeOffset + encodingLength(size);
5468
- const bytes = new Uint8Array(digestOffset + size);
5469
- encodeTo(code, bytes, 0);
5470
- encodeTo(size, bytes, sizeOffset);
5471
- bytes.set(digest, digestOffset);
5472
- return new Digest(code, size, digest, bytes);
5473
- }
5474
- function decode4(multihash) {
5475
- const bytes = coerce4(multihash);
5476
- const [code, sizeOffset] = decode3(bytes);
5477
- const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
5478
- const digest = bytes.subarray(sizeOffset + digestOffset);
5479
- if (digest.byteLength !== size) {
5480
- throw new Error("Incorrect length");
5082
+ function parseCIDtoBytes(source, base3) {
5083
+ switch (source[0]) {
5084
+ case "Q": {
5085
+ const decoder = base3 ?? base58btc;
5086
+ return [
5087
+ base58btc.prefix,
5088
+ decoder.decode(`${base58btc.prefix}${source}`)
5089
+ ];
5090
+ }
5091
+ case base58btc.prefix: {
5092
+ const decoder = base3 ?? base58btc;
5093
+ return [base58btc.prefix, decoder.decode(source)];
5094
+ }
5095
+ case base32.prefix: {
5096
+ const decoder = base3 ?? base32;
5097
+ return [base32.prefix, decoder.decode(source)];
5098
+ }
5099
+ default: {
5100
+ if (base3 == null) {
5101
+ throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
5102
+ }
5103
+ return [source[0], base3.decode(source)];
5104
+ }
5481
5105
  }
5482
- return new Digest(code, size, digest, bytes);
5483
5106
  }
5484
- function equals2(a, b) {
5485
- if (a === b) {
5486
- return true;
5107
+ function toStringV0(bytes, cache2, base3) {
5108
+ const { prefix } = base3;
5109
+ if (prefix !== base58btc.prefix) {
5110
+ throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
5111
+ }
5112
+ const cid = cache2.get(prefix);
5113
+ if (cid == null) {
5114
+ const cid2 = base3.encode(bytes).slice(1);
5115
+ cache2.set(prefix, cid2);
5116
+ return cid2;
5487
5117
  } else {
5488
- const data = b;
5489
- return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
5118
+ return cid;
5490
5119
  }
5491
5120
  }
5492
- var Digest = class {
5493
- /**
5494
- * Creates a multihash digest.
5495
- */
5496
- constructor(code, size, digest, bytes) {
5497
- __publicField(this, "code");
5498
- __publicField(this, "size");
5499
- __publicField(this, "digest");
5500
- __publicField(this, "bytes");
5501
- this.code = code;
5502
- this.size = size;
5503
- this.digest = digest;
5504
- this.bytes = bytes;
5121
+ function toStringV1(bytes, cache2, base3) {
5122
+ const { prefix } = base3;
5123
+ const cid = cache2.get(prefix);
5124
+ if (cid == null) {
5125
+ const cid2 = base3.encode(bytes);
5126
+ cache2.set(prefix, cid2);
5127
+ return cid2;
5128
+ } else {
5129
+ return cid;
5505
5130
  }
5506
- };
5131
+ }
5132
+ var DAG_PB_CODE = 112;
5133
+ var SHA_256_CODE = 18;
5134
+ function encodeCID(version, code, multihash) {
5135
+ const codeOffset = encodingLength(version);
5136
+ const hashOffset = codeOffset + encodingLength(code);
5137
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
5138
+ encodeTo(version, bytes, 0);
5139
+ encodeTo(code, bytes, codeOffset);
5140
+ bytes.set(multihash, hashOffset);
5141
+ return bytes;
5142
+ }
5143
+ var cidSymbol = Symbol.for("@ipld/js-cid/CID");
5507
5144
 
5508
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
5509
- function format(link, base3) {
5510
- const { bytes, version } = link;
5511
- switch (version) {
5512
- case 0:
5513
- return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
5514
- default:
5515
- return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
5145
+ // src/ipfs/ipfs.ts
5146
+ function isCID(str) {
5147
+ if (!str)
5148
+ return false;
5149
+ try {
5150
+ CID.parse(str);
5151
+ return true;
5152
+ } catch (e) {
5153
+ if (/^(bafy|Qm)/.test(str))
5154
+ return true;
5155
+ return false;
5516
5156
  }
5517
5157
  }
5518
- var cache = /* @__PURE__ */ new WeakMap();
5519
- function baseCache(cid) {
5520
- const baseCache2 = cache.get(cid);
5521
- if (baseCache2 == null) {
5522
- const baseCache3 = /* @__PURE__ */ new Map();
5523
- cache.set(cid, baseCache3);
5524
- return baseCache3;
5158
+ function normalizeIPFSUrl(url) {
5159
+ if (!url || typeof url !== "string")
5160
+ return null;
5161
+ url = url.replace(/"/g, "");
5162
+ if (isNormalizedIPFSURL(url))
5163
+ return url;
5164
+ if (isCID(url))
5165
+ return `ipfs://${url}`;
5166
+ if (!isIPFSUrl(url))
5167
+ return null;
5168
+ if (isGatewayIPFSUrl(url)) {
5169
+ const parsed = new URL(url.replace(/^\/\//, "http://"));
5170
+ parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
5171
+ const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
5172
+ return `ipfs://${cid}`;
5525
5173
  }
5526
- return baseCache2;
5174
+ return null;
5527
5175
  }
5528
- var _a;
5529
- var CID = class _CID {
5530
- /**
5531
- * @param version - Version of the CID
5532
- * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
5533
- * @param multihash - (Multi)hash of the of the content.
5534
- */
5535
- constructor(version, code, multihash, bytes) {
5536
- __publicField(this, "code");
5537
- __publicField(this, "version");
5538
- __publicField(this, "multihash");
5539
- __publicField(this, "bytes");
5540
- __publicField(this, "/");
5541
- __publicField(this, _a, "CID");
5542
- this.code = code;
5543
- this.version = version;
5544
- this.multihash = multihash;
5545
- this.bytes = bytes;
5546
- this["/"] = bytes;
5176
+ function isNormalizedIPFSURL(url) {
5177
+ return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
5178
+ }
5179
+ function isGatewayIPFSUrl(url) {
5180
+ if (url && typeof url === "string") {
5181
+ try {
5182
+ const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
5183
+ return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
5184
+ } catch {
5185
+ return false;
5186
+ }
5547
5187
  }
5548
- /**
5549
- * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
5550
- * please either use `CID.asCID(cid)` or switch to new signalling mechanism
5551
- *
5552
- * @deprecated
5553
- */
5554
- get asCID() {
5555
- return this;
5188
+ return false;
5189
+ }
5190
+ function isIPFSUrl(url) {
5191
+ return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
5192
+ }
5193
+ function isNormalizeableIPFSUrl(url) {
5194
+ return url ? isIPFSUrl(url) || isCID(url) : false;
5195
+ }
5196
+
5197
+ // src/ipfs/gateway.ts
5198
+ var IPFS_GATEWAY = "https://magic.decentralized-content.com";
5199
+ var ARWEAVE_GATEWAY = "https://arweave.net";
5200
+ function arweaveGatewayUrl(normalizedArweaveUrl) {
5201
+ if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
5202
+ return null;
5203
+ return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
5204
+ }
5205
+ function ipfsGatewayUrl(url) {
5206
+ if (!url || typeof url !== "string")
5207
+ return null;
5208
+ const normalizedIPFSUrl = normalizeIPFSUrl(url);
5209
+ if (normalizedIPFSUrl) {
5210
+ return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
5556
5211
  }
5557
- // ArrayBufferView
5558
- get byteOffset() {
5559
- return this.bytes.byteOffset;
5212
+ return null;
5213
+ }
5214
+ function getFetchableUrl(uri) {
5215
+ if (!uri || typeof uri !== "string")
5216
+ return null;
5217
+ if (uri.startsWith("http://"))
5218
+ return null;
5219
+ if (isNormalizeableIPFSUrl(uri)) {
5220
+ return ipfsGatewayUrl(uri);
5560
5221
  }
5561
- // ArrayBufferView
5562
- get byteLength() {
5563
- return this.bytes.byteLength;
5222
+ if (isArweaveURL(uri)) {
5223
+ return arweaveGatewayUrl(uri);
5564
5224
  }
5565
- toV0() {
5566
- switch (this.version) {
5567
- case 0: {
5568
- return this;
5569
- }
5570
- case 1: {
5571
- const { code, multihash } = this;
5572
- if (code !== DAG_PB_CODE) {
5573
- throw new Error("Cannot convert a non dag-pb CID to CIDv0");
5574
- }
5575
- if (multihash.code !== SHA_256_CODE) {
5576
- throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
5577
- }
5578
- return _CID.createV0(multihash);
5579
- }
5580
- default: {
5581
- throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
5582
- }
5583
- }
5225
+ if (/^(https|data|blob):/.test(uri)) {
5226
+ return uri;
5584
5227
  }
5585
- toV1() {
5586
- switch (this.version) {
5587
- case 0: {
5588
- const { code, digest } = this.multihash;
5589
- const multihash = create(code, digest);
5590
- return _CID.createV1(this.code, multihash);
5591
- }
5592
- case 1: {
5593
- return this;
5594
- }
5595
- default: {
5596
- throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
5597
- }
5598
- }
5228
+ return null;
5229
+ }
5230
+
5231
+ // src/ipfs/mimeTypes.ts
5232
+ var HTML = "text/html";
5233
+ var MARKDOWN = "text/markdown";
5234
+ var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
5235
+ var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
5236
+ var TEXT_PLAIN = "text/plain";
5237
+ var CSV = "text/csv";
5238
+ var NUMBERS = ".numbers";
5239
+ var EXCEL = ".xlsx";
5240
+ var PDF = "application/pdf";
5241
+ var JPG = "image/jpg";
5242
+ var JPEG = "image/jpeg";
5243
+ var PNG = "image/png";
5244
+ var WEBP = "image/webp";
5245
+ var SVG = "image/svg+xml";
5246
+ var TIFF = "image/tiff";
5247
+ var GIF = "image/gif";
5248
+ var isImage = (mimeType) => {
5249
+ if (!mimeType)
5250
+ return false;
5251
+ return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
5252
+ };
5253
+ var DEFAULT_THUMBNAIL_CID_HASHES = {
5254
+ ["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
5255
+ ["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
5256
+ ["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
5257
+ ["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
5258
+ // assuming all zip files are html directories
5259
+ ["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
5260
+ default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
5261
+ };
5262
+ var MP4 = "video/mp4";
5263
+ var QUICKTIME = "video/quicktime";
5264
+ var M4V = "video/x-m4v";
5265
+ var WEBM = "video/webm";
5266
+ var M4A = "audio/x-m4a";
5267
+ var MPEG = "audio/mpeg";
5268
+ var MP3 = "audio/mp3";
5269
+ var WAV = "audio/wav";
5270
+ var VND_WAV = "audio/vnd.wav";
5271
+ var VND_WAVE = "audio/vnd.wave";
5272
+ var WAVE = "audio/wave";
5273
+ var X_WAV = "audio/x-wav";
5274
+ var AIFF = "audio/aiff";
5275
+ var GLTF = "model/gltf+json";
5276
+ var GLB = "model/gltf-binary";
5277
+ var GLTF_EXT = ".gltf";
5278
+ var GLB_EXT = ".glb";
5279
+ var JSON_MIME_TYPE = "application/json";
5280
+ var ZIP = "application/zip";
5281
+ var mimeToMediaType = {
5282
+ [HTML]: "HTML" /* HTML */,
5283
+ [JPG]: "IMAGE" /* IMAGE */,
5284
+ [JPEG]: "IMAGE" /* IMAGE */,
5285
+ [PNG]: "IMAGE" /* IMAGE */,
5286
+ [WEBP]: "IMAGE" /* IMAGE */,
5287
+ [SVG]: "IMAGE" /* IMAGE */,
5288
+ [TIFF]: "TIFF" /* TIFF */,
5289
+ [GIF]: "IMAGE" /* IMAGE */,
5290
+ [MP4]: "VIDEO" /* VIDEO */,
5291
+ [WEBM]: "VIDEO" /* VIDEO */,
5292
+ [QUICKTIME]: "VIDEO" /* VIDEO */,
5293
+ [M4V]: "VIDEO" /* VIDEO */,
5294
+ [MPEG]: "AUDIO" /* AUDIO */,
5295
+ [MP3]: "AUDIO" /* AUDIO */,
5296
+ [M4A]: "AUDIO" /* AUDIO */,
5297
+ [VND_WAV]: "AUDIO" /* AUDIO */,
5298
+ [VND_WAVE]: "AUDIO" /* AUDIO */,
5299
+ [WAV]: "AUDIO" /* AUDIO */,
5300
+ [WAVE]: "AUDIO" /* AUDIO */,
5301
+ [X_WAV]: "AUDIO" /* AUDIO */,
5302
+ [AIFF]: "AUDIO" /* AUDIO */,
5303
+ [TEXT_PLAIN]: "TEXT" /* TEXT */,
5304
+ [TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
5305
+ [MARKDOWN]: "TEXT" /* TEXT */,
5306
+ [MARKDOWN_UTF8]: "TEXT" /* TEXT */,
5307
+ [CSV]: "CSV" /* CSV */,
5308
+ [NUMBERS]: "NUMBERS" /* NUMBERS */,
5309
+ [EXCEL]: "EXCEL" /* EXCEL */,
5310
+ [PDF]: "PDF" /* PDF */,
5311
+ [ZIP]: "ZIP" /* ZIP */,
5312
+ [GLTF]: "MODEL" /* MODEL */,
5313
+ [GLTF_EXT]: "MODEL" /* MODEL */,
5314
+ [GLB]: "MODEL" /* MODEL */,
5315
+ // GLTF returns 'application/json' as the mimetype,
5316
+ // and as the only JSON-encoded media we currently support,
5317
+ // we assume that if the mimetype is JSON, it's a GLTF
5318
+ [JSON_MIME_TYPE]: "MODEL" /* MODEL */,
5319
+ [GLB_EXT]: "MODEL" /* MODEL */
5320
+ };
5321
+ function mimeTypeToMedia(mimeType) {
5322
+ if (!mimeType)
5323
+ return "UNKNOWN" /* UNKNOWN */;
5324
+ return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
5325
+ }
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;
5599
5371
  }
5600
- equals(other) {
5601
- return _CID.equals(this, other);
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}`);
5602
5391
  }
5603
- static equals(self, other) {
5604
- const unknown = other;
5605
- return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
5392
+ const json = await (await fetch(fetchableUrl)).json();
5393
+ if (!json) {
5394
+ throw new Error(`Failed to fetch metadata from ${fetchableUrl}`);
5606
5395
  }
5607
- toString(base3) {
5608
- return format(this, base3);
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");
5609
5430
  }
5610
- toJSON() {
5611
- return { "/": format(this) };
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");
5612
5434
  }
5613
- link() {
5614
- return this;
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");
5615
5441
  }
5616
- // Legacy
5617
- [(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
5618
- return `CID(${this.toString()})`;
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);
5619
5464
  }
5620
- /**
5621
- * Takes any input `value` and returns a `CID` instance if it was
5622
- * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
5623
- * it will return value back. If `value` is not instance of this CID
5624
- * class, but is compatible CID it will return new instance of this
5625
- * `CID` class. Otherwise returns null.
5626
- *
5627
- * This allows two different incompatible versions of CID library to
5628
- * co-exist and interop as long as binary interface is compatible.
5629
- */
5630
- static asCID(input) {
5631
- if (input == null) {
5632
- return null;
5633
- }
5634
- const value = input;
5635
- if (value instanceof _CID) {
5636
- return value;
5637
- } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
5638
- const { version, code, multihash, bytes } = value;
5639
- return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
5640
- } else if (value[cidSymbol] === true) {
5641
- const { version, multihash, code } = value;
5642
- const digest = decode4(multihash);
5643
- return _CID.create(version, code, digest);
5644
- } else {
5645
- return null;
5646
- }
5465
+ if (isErc20(salesConfig)) {
5466
+ return erc20SaleSettingsWithDefaults(salesConfig);
5647
5467
  }
5648
- /**
5649
- * @param version - Version of the CID
5650
- * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
5651
- * @param digest - (Multi)hash of the of the content.
5652
- */
5653
- static create(version, code, digest) {
5654
- if (typeof code !== "number") {
5655
- throw new Error("String codecs are no longer supported");
5656
- }
5657
- if (!(digest.bytes instanceof Uint8Array)) {
5658
- throw new Error("Invalid digest");
5659
- }
5660
- switch (version) {
5661
- case 0: {
5662
- if (code !== DAG_PB_CODE) {
5663
- throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
5664
- } else {
5665
- return new _CID(version, code, digest, digest.bytes);
5666
- }
5667
- }
5668
- case 1: {
5669
- const bytes = encodeCID(version, code, digest.bytes);
5670
- return new _CID(version, code, digest, bytes);
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
5671
5520
  }
5672
- default: {
5673
- throw new Error("Invalid version");
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
5674
5563
  }
5675
- }
5676
- }
5677
- /**
5678
- * Simplified version of `create` for CIDv0.
5679
- */
5680
- static createV0(digest) {
5681
- return _CID.create(0, DAG_PB_CODE, digest);
5682
- }
5683
- /**
5684
- * Simplified version of `create` for CIDv1.
5685
- *
5686
- * @param code - Content encoding format code.
5687
- * @param digest - Multihash of the content.
5688
- */
5689
- static createV1(code, digest) {
5690
- return _CID.create(1, code, digest);
5691
- }
5692
- /**
5693
- * Decoded a CID from its binary representation. The byte array must contain
5694
- * only the CID with no additional bytes.
5695
- *
5696
- * An error will be thrown if the bytes provided do not contain a valid
5697
- * binary representation of a CID.
5698
- */
5699
- static decode(bytes) {
5700
- const [cid, remainder] = _CID.decodeFirst(bytes);
5701
- if (remainder.length !== 0) {
5702
- throw new Error("Incorrect length");
5703
- }
5704
- return cid;
5705
- }
5706
- /**
5707
- * Decoded a CID from its binary representation at the beginning of a byte
5708
- * array.
5709
- *
5710
- * Returns an array with the first element containing the CID and the second
5711
- * element containing the remainder of the original byte array. The remainder
5712
- * will be a zero-length byte array if the provided bytes only contained a
5713
- * binary CID representation.
5714
- */
5715
- static decodeFirst(bytes) {
5716
- const specs = _CID.inspectBytes(bytes);
5717
- const prefixSize = specs.size - specs.multihashSize;
5718
- const multihashBytes = coerce4(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
5719
- if (multihashBytes.byteLength !== specs.multihashSize) {
5720
- throw new Error("Incorrect length");
5721
- }
5722
- const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
5723
- const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
5724
- const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
5725
- return [cid, bytes.subarray(specs.size)];
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
+ });
5726
5658
  }
5727
- /**
5728
- * Inspect the initial bytes of a CID to determine its properties.
5729
- *
5730
- * Involves decoding up to 4 varints. Typically this will require only 4 to 6
5731
- * bytes but for larger multicodec code values and larger multihash digest
5732
- * lengths these varints can be quite large. It is recommended that at least
5733
- * 10 bytes be made available in the `initialBytes` argument for a complete
5734
- * inspection.
5735
- */
5736
- static inspectBytes(initialBytes) {
5737
- let offset = 0;
5738
- const next = () => {
5739
- const [i, length2] = decode3(initialBytes.subarray(offset));
5740
- offset += length2;
5741
- return i;
5742
- };
5743
- let version = next();
5744
- let codec = DAG_PB_CODE;
5745
- if (version === 18) {
5746
- version = 0;
5747
- offset = 0;
5748
- } else {
5749
- codec = next();
5750
- }
5751
- if (version !== 0 && version !== 1) {
5752
- throw new RangeError(`Invalid CID version ${version}`);
5753
- }
5754
- const prefixSize = offset;
5755
- const multihashCode = next();
5756
- const digestSize = next();
5757
- const size = offset + digestSize;
5758
- const multihashSize = size - prefixSize;
5759
- return { version, codec, multihashCode, digestSize, multihashSize, size };
5659
+ if (isAllowList2(salesConfig)) {
5660
+ return setupAllowListMinter({
5661
+ allowlist: salesConfig,
5662
+ ...rest
5663
+ });
5760
5664
  }
5761
- /**
5762
- * Takes cid in a string representation and creates an instance. If `base`
5763
- * decoder is not provided will use a default from the configuration. It will
5764
- * throw an error if encoding of the CID is not compatible with supplied (or
5765
- * a default decoder).
5766
- */
5767
- static parse(source, base3) {
5768
- const [prefix, bytes] = parseCIDtoBytes(source, base3);
5769
- const cid = _CID.decode(bytes);
5770
- if (cid.version === 0 && source[0] !== "Q") {
5771
- throw Error("Version 0 CID string must not include multibase prefix");
5772
- }
5773
- baseCache(cid).set(prefix, source);
5774
- return cid;
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
+ });
5775
5704
  }
5776
- };
5777
- function parseCIDtoBytes(source, base3) {
5778
- switch (source[0]) {
5779
- case "Q": {
5780
- const decoder = base3 ?? base58btc;
5781
- return [
5782
- base58btc.prefix,
5783
- decoder.decode(`${base58btc.prefix}${source}`)
5784
- ];
5785
- }
5786
- case base58btc.prefix: {
5787
- const decoder = base3 ?? base58btc;
5788
- return [base58btc.prefix, decoder.decode(source)];
5789
- }
5790
- case base32.prefix: {
5791
- const decoder = base3 ?? base32;
5792
- return [base32.prefix, decoder.decode(source)];
5793
- }
5794
- default: {
5795
- if (base3 == null) {
5796
- throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
5797
- }
5798
- return [source[0], base3.decode(source)];
5799
- }
5705
+ if (createReferral !== zeroAddress5) {
5706
+ throw new Error(
5707
+ "Contract does not support create referral, but one was provided"
5708
+ );
5800
5709
  }
5710
+ return encodeFunctionData2({
5711
+ abi: zoraCreator1155ImplABI5,
5712
+ functionName: "setupNewToken",
5713
+ args: [tokenURI, BigInt(maxSupply)]
5714
+ });
5801
5715
  }
5802
- function toStringV0(bytes, cache2, base3) {
5803
- const { prefix } = base3;
5804
- if (prefix !== base58btc.prefix) {
5805
- throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
5806
- }
5807
- const cid = cache2.get(prefix);
5808
- if (cid == null) {
5809
- const cid2 = base3.encode(bytes).slice(1);
5810
- cache2.set(prefix, cid2);
5811
- return cid2;
5812
- } else {
5813
- return cid;
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
+ });
5814
5734
  }
5735
+ return null;
5815
5736
  }
5816
- function toStringV1(bytes, cache2, base3) {
5817
- const { prefix } = base3;
5818
- const cid = cache2.get(prefix);
5819
- if (cid == null) {
5820
- const cid2 = base3.encode(bytes);
5821
- cache2.set(prefix, cid2);
5822
- return cid2;
5823
- } else {
5824
- return cid;
5737
+ function makeAdminMintCall({
5738
+ ownerAddress,
5739
+ mintQuantity,
5740
+ nextTokenId
5741
+ }) {
5742
+ if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
5743
+ return null;
5825
5744
  }
5745
+ return encodeFunctionData2({
5746
+ abi: zoraCreator1155ImplABI5,
5747
+ functionName: "adminMint",
5748
+ args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
5749
+ });
5826
5750
  }
5827
- var DAG_PB_CODE = 112;
5828
- var SHA_256_CODE = 18;
5829
- function encodeCID(version, code, multihash) {
5830
- const codeOffset = encodingLength(version);
5831
- const hashOffset = codeOffset + encodingLength(code);
5832
- const bytes = new Uint8Array(hashOffset + multihash.byteLength);
5833
- encodeTo(version, bytes, 0);
5834
- encodeTo(code, bytes, codeOffset);
5835
- bytes.set(multihash, hashOffset);
5836
- return bytes;
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
+ };
5837
5802
  }
5838
- var cidSymbol = Symbol.for("@ipld/js-cid/CID");
5839
-
5840
- // src/ipfs/ipfs.ts
5841
- function isCID(str) {
5842
- if (!str)
5803
+ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
5804
+ if (!contractStandard || !contractVersion) {
5843
5805
  return false;
5844
- try {
5845
- CID.parse(str);
5846
- return true;
5847
- } catch (e) {
5848
- if (/^(bafy|Qm)/.test(str))
5849
- return true;
5806
+ }
5807
+ const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
5808
+ if (!semVerContractVersion)
5850
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");
5851
5814
  }
5852
- }
5853
- function normalizeIPFSUrl(url) {
5854
- if (!url || typeof url !== "string")
5855
- return null;
5856
- url = url.replace(/"/g, "");
5857
- if (isNormalizedIPFSURL(url))
5858
- return url;
5859
- if (isCID(url))
5860
- return `ipfs://${url}`;
5861
- if (!isIPFSUrl(url))
5862
- return null;
5863
- if (isGatewayIPFSUrl(url)) {
5864
- const parsed = new URL(url.replace(/^\/\//, "http://"));
5865
- parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
5866
- const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
5867
- return `ipfs://${cid}`;
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
+ }
5868
5832
  }
5869
- return null;
5870
- }
5871
- function isNormalizedIPFSURL(url) {
5872
- return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
5873
- }
5874
- function isGatewayIPFSUrl(url) {
5875
- if (url && typeof url === "string") {
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) {
5876
5839
  try {
5877
- const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
5878
- return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
5879
- } catch {
5880
- return false;
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) {
5881
5849
  }
5882
5850
  }
5883
- return false;
5884
- }
5885
- function isIPFSUrl(url) {
5886
- return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
5887
- }
5888
- function isNormalizeableIPFSUrl(url) {
5889
- return url ? isIPFSUrl(url) || isCID(url) : false;
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
+ });
5890
5882
  }
5891
-
5892
- // src/ipfs/gateway.ts
5893
- var IPFS_GATEWAY = "https://magic.decentralized-content.com";
5894
- var ARWEAVE_GATEWAY = "https://arweave.net";
5895
- function arweaveGatewayUrl(normalizedArweaveUrl) {
5896
- if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
5897
- return null;
5898
- return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
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
+ });
5899
5895
  }
5900
- function ipfsGatewayUrl(url) {
5901
- if (!url || typeof url !== "string")
5902
- return null;
5903
- const normalizedIPFSUrl = normalizeIPFSUrl(url);
5904
- if (normalizedIPFSUrl) {
5905
- return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
5896
+ var Create1155Client = class {
5897
+ constructor({
5898
+ chainId,
5899
+ publicClient
5900
+ }) {
5901
+ this.chainId = chainId;
5902
+ this.publicClient = publicClient;
5906
5903
  }
5907
- return null;
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
+ };
5908
6011
  }
5909
- function getFetchableUrl(uri) {
5910
- if (!uri || typeof uri !== "string")
5911
- return null;
5912
- if (uri.startsWith("http://"))
5913
- return null;
5914
- if (isNormalizeableIPFSUrl(uri)) {
5915
- return ipfsGatewayUrl(uri);
5916
- }
5917
- if (isArweaveURL(uri)) {
5918
- return arweaveGatewayUrl(uri);
5919
- }
5920
- if (/^(https|data|blob):/.test(uri)) {
5921
- return uri;
5922
- }
5923
- return null;
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 };
5924
6038
  }
5925
6039
 
5926
- // src/ipfs/mimeTypes.ts
5927
- var HTML = "text/html";
5928
- var MARKDOWN = "text/markdown";
5929
- var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
5930
- var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
5931
- var TEXT_PLAIN = "text/plain";
5932
- var CSV = "text/csv";
5933
- var NUMBERS = ".numbers";
5934
- var EXCEL = ".xlsx";
5935
- var PDF = "application/pdf";
5936
- var JPG = "image/jpg";
5937
- var JPEG = "image/jpeg";
5938
- var PNG = "image/png";
5939
- var WEBP = "image/webp";
5940
- var SVG = "image/svg+xml";
5941
- var TIFF = "image/tiff";
5942
- var GIF = "image/gif";
5943
- var isImage = (mimeType) => {
5944
- if (!mimeType)
5945
- return false;
5946
- return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
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
+ };
5947
6057
  };
5948
- var DEFAULT_THUMBNAIL_CID_HASHES = {
5949
- ["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
5950
- ["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
5951
- ["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
5952
- ["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
5953
- // assuming all zip files are html directories
5954
- ["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
5955
- default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
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
+ };
5956
6089
  };
5957
- var MP4 = "video/mp4";
5958
- var QUICKTIME = "video/quicktime";
5959
- var M4V = "video/x-m4v";
5960
- var WEBM = "video/webm";
5961
- var M4A = "audio/x-m4a";
5962
- var MPEG = "audio/mpeg";
5963
- var MP3 = "audio/mp3";
5964
- var WAV = "audio/wav";
5965
- var VND_WAV = "audio/vnd.wav";
5966
- var VND_WAVE = "audio/vnd.wave";
5967
- var WAVE = "audio/wave";
5968
- var X_WAV = "audio/x-wav";
5969
- var AIFF = "audio/aiff";
5970
- var GLTF = "model/gltf+json";
5971
- var GLB = "model/gltf-binary";
5972
- var GLTF_EXT = ".gltf";
5973
- var GLB_EXT = ".glb";
5974
- var JSON_MIME_TYPE = "application/json";
5975
- var ZIP = "application/zip";
5976
- var mimeToMediaType = {
5977
- [HTML]: "HTML" /* HTML */,
5978
- [JPG]: "IMAGE" /* IMAGE */,
5979
- [JPEG]: "IMAGE" /* IMAGE */,
5980
- [PNG]: "IMAGE" /* IMAGE */,
5981
- [WEBP]: "IMAGE" /* IMAGE */,
5982
- [SVG]: "IMAGE" /* IMAGE */,
5983
- [TIFF]: "TIFF" /* TIFF */,
5984
- [GIF]: "IMAGE" /* IMAGE */,
5985
- [MP4]: "VIDEO" /* VIDEO */,
5986
- [WEBM]: "VIDEO" /* VIDEO */,
5987
- [QUICKTIME]: "VIDEO" /* VIDEO */,
5988
- [M4V]: "VIDEO" /* VIDEO */,
5989
- [MPEG]: "AUDIO" /* AUDIO */,
5990
- [MP3]: "AUDIO" /* AUDIO */,
5991
- [M4A]: "AUDIO" /* AUDIO */,
5992
- [VND_WAV]: "AUDIO" /* AUDIO */,
5993
- [VND_WAVE]: "AUDIO" /* AUDIO */,
5994
- [WAV]: "AUDIO" /* AUDIO */,
5995
- [WAVE]: "AUDIO" /* AUDIO */,
5996
- [X_WAV]: "AUDIO" /* AUDIO */,
5997
- [AIFF]: "AUDIO" /* AUDIO */,
5998
- [TEXT_PLAIN]: "TEXT" /* TEXT */,
5999
- [TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
6000
- [MARKDOWN]: "TEXT" /* TEXT */,
6001
- [MARKDOWN_UTF8]: "TEXT" /* TEXT */,
6002
- [CSV]: "CSV" /* CSV */,
6003
- [NUMBERS]: "NUMBERS" /* NUMBERS */,
6004
- [EXCEL]: "EXCEL" /* EXCEL */,
6005
- [PDF]: "PDF" /* PDF */,
6006
- [ZIP]: "ZIP" /* ZIP */,
6007
- [GLTF]: "MODEL" /* MODEL */,
6008
- [GLTF_EXT]: "MODEL" /* MODEL */,
6009
- [GLB]: "MODEL" /* MODEL */,
6010
- // GLTF returns 'application/json' as the mimetype,
6011
- // and as the only JSON-encoded media we currently support,
6012
- // we assume that if the mimetype is JSON, it's a GLTF
6013
- [JSON_MIME_TYPE]: "MODEL" /* MODEL */,
6014
- [GLB_EXT]: "MODEL" /* MODEL */
6090
+ var sumBalances = (mintAccountBalances) => {
6091
+ return mintAccountBalances.reduce((acc, curr) => {
6092
+ return acc + BigInt(curr.balance);
6093
+ }, BigInt(0));
6015
6094
  };
6016
- function mimeTypeToMedia(mimeType) {
6017
- if (!mimeType)
6018
- return "UNKNOWN" /* UNKNOWN */;
6019
- return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
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
+ });
6020
6186
  }
6021
- async function getMimeType(uri) {
6022
- if (!uri)
6023
- return uri;
6024
- const res = await fetch(uri, { method: "HEAD" });
6025
- let mimeType = res.headers.get("content-type");
6026
- return mimeType;
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
+ });
6027
6199
  }
6028
-
6029
- // src/ipfs/token-metadata.ts
6030
- var makeTextTokenMetadata = (parameters) => {
6031
- const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
6032
- const content = textFileUrl ? {
6033
- mime: TEXT_PLAIN,
6034
- uri: textFileUrl
6035
- } : null;
6036
- const image = thumbnailUrl;
6037
- 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
+ };
6038
6226
  return {
6039
- name,
6040
- image,
6041
- animation_url,
6042
- content,
6043
- attributes
6227
+ permit,
6228
+ typedData
6044
6229
  };
6045
- };
6046
- var makeMediaTokenMetadata = async ({
6047
- name,
6048
- description,
6049
- attributes = [],
6050
- mediaUrl,
6051
- 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
6052
6291
  }) => {
6053
- const contentUrl = mediaUrl;
6054
- const fetchableContentUrl = getFetchableUrl(contentUrl);
6055
- if (!fetchableContentUrl)
6056
- throw new Error(`Content url (${contentUrl}) is not fetchable`);
6057
- const mimeType = await getMimeType(fetchableContentUrl);
6058
- const mediaType = mimeTypeToMedia(mimeType);
6059
- let image = void 0;
6060
- let animation_url = null;
6061
- if (isImage(mimeType)) {
6062
- image = contentUrl;
6292
+ let safeTransferData;
6293
+ if (premint) {
6294
+ safeTransferData = encodePremintOnManager(premint);
6295
+ } else if (collect) {
6296
+ safeTransferData = encodeCollectOnManager(collect);
6063
6297
  } else {
6064
- image = thumbnailUrl;
6065
- animation_url = mediaUrl;
6298
+ throw new Error("Invalid operation");
6066
6299
  }
6067
- if (!image)
6068
- image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
6069
- const content = contentUrl ? {
6070
- mime: mimeType || "application/octet-stream",
6071
- uri: contentUrl
6072
- } : 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
+ });
6073
6352
  return {
6074
- name,
6075
- description,
6076
- image,
6077
- animation_url,
6078
- content,
6079
- 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)
6080
6358
  };
6081
- };
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
+ }
6082
6380
 
6083
6381
  // src/ipfs/text-metadata.ts
6084
6382
  var CHAR_LIMIT = 1111;
@@ -6173,6 +6471,26 @@ async function generateTextNftMetadataFiles(text) {
6173
6471
  thumbnailFile
6174
6472
  };
6175
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
+ };
6176
6494
  export {
6177
6495
  Create1155Client,
6178
6496
  Errors,
@@ -6184,7 +6502,6 @@ export {
6184
6502
  ZORA_API_BASE,
6185
6503
  applyUpdateToPremint,
6186
6504
  buildPremintMintCall,
6187
- collectOnchain,
6188
6505
  collectPremint,
6189
6506
  collectPremintV2WithMintsParams,
6190
6507
  collectWithMintsParams,
@@ -6192,6 +6509,7 @@ export {
6192
6509
  convertGetPremintApiResponse,
6193
6510
  convertGetPremintOfCollectionApiResponse,
6194
6511
  convertPremintFromApi,
6512
+ createAllowList,
6195
6513
  createCollectorClient,
6196
6514
  createCreatorClient,
6197
6515
  decodeCallFailedError,