@zoralabs/protocol-sdk 0.11.12 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +17 -0
  3. package/dist/apis/network-config.d.ts +3 -0
  4. package/dist/apis/network-config.d.ts.map +1 -0
  5. package/dist/create/contract-setup.d.ts +3 -4
  6. package/dist/create/contract-setup.d.ts.map +1 -1
  7. package/dist/create/create-client.d.ts +53 -0
  8. package/dist/create/create-client.d.ts.map +1 -0
  9. package/dist/create/types.d.ts +11 -3
  10. package/dist/create/types.d.ts.map +1 -1
  11. package/dist/fixtures/contract-setup.d.ts +2 -2
  12. package/dist/fixtures/contract-setup.d.ts.map +1 -1
  13. package/dist/fixtures/rewards-query-results.d.ts +0 -1
  14. package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
  15. package/dist/fixtures/secondary.d.ts +3 -6
  16. package/dist/fixtures/secondary.d.ts.map +1 -1
  17. package/dist/index.cjs +1613 -1483
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +12 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1594 -1483
  22. package/dist/index.js.map +1 -1
  23. package/dist/mint/mint-client.d.ts +21 -9
  24. package/dist/mint/mint-client.d.ts.map +1 -1
  25. package/dist/mint/mint-queries.d.ts +24 -22
  26. package/dist/mint/mint-queries.d.ts.map +1 -1
  27. package/dist/mint/strategies-parsing.d.ts +28 -0
  28. package/dist/mint/strategies-parsing.d.ts.map +1 -0
  29. package/dist/mint/subgraph-mint-getter.d.ts +2 -6
  30. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  31. package/dist/mint/types.d.ts +25 -8
  32. package/dist/mint/types.d.ts.map +1 -1
  33. package/dist/premint/premint-api-client.d.ts.map +1 -1
  34. package/dist/premint/premint-client.d.ts.map +1 -1
  35. package/dist/preminter.d.ts +5 -5
  36. package/dist/preminter.d.ts.map +1 -1
  37. package/dist/rewards/rewards-client.d.ts +7 -3
  38. package/dist/rewards/rewards-client.d.ts.map +1 -1
  39. package/dist/rewards/rewards-queries.d.ts +14 -11
  40. package/dist/rewards/rewards-queries.d.ts.map +1 -1
  41. package/dist/rewards/subgraph-queries.d.ts +0 -1
  42. package/dist/rewards/subgraph-queries.d.ts.map +1 -1
  43. package/dist/rewards/subgraph-rewards-getter.d.ts +2 -8
  44. package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
  45. package/dist/sdk.d.ts +9 -3
  46. package/dist/sdk.d.ts.map +1 -1
  47. package/dist/secondary/secondary-client.d.ts +7 -8
  48. package/dist/secondary/secondary-client.d.ts.map +1 -1
  49. package/dist/secondary/uniswap/uniswapQuote.d.ts +0 -1
  50. package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -1
  51. package/dist/secondary/utils.d.ts +1 -2
  52. package/dist/secondary/utils.d.ts.map +1 -1
  53. package/dist/types.d.ts +6 -3
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/utils.d.ts +2 -2
  56. package/dist/utils.d.ts.map +1 -1
  57. package/package.json +2 -2
  58. package/src/apis/network-config.ts +8 -0
  59. package/src/apis/subgraph-getter.ts +1 -1
  60. package/src/comments/comments.test.ts +11 -22
  61. package/src/create/contract-setup.ts +3 -4
  62. package/src/create/{1155-create-helper.test.ts → create-client.test.ts} +52 -88
  63. package/src/create/{1155-create-helper.ts → create-client.ts} +129 -63
  64. package/src/create/types.ts +13 -3
  65. package/src/fixtures/contract-setup.ts +3 -3
  66. package/src/fixtures/rewards-query-results.ts +2 -9
  67. package/src/fixtures/secondary.ts +16 -10
  68. package/src/index.ts +34 -4
  69. package/src/mint/mint-client.test.ts +37 -64
  70. package/src/mint/mint-client.ts +36 -32
  71. package/src/mint/mint-queries.ts +73 -54
  72. package/src/mint/strategies-parsing.ts +311 -0
  73. package/src/mint/subgraph-mint-getter.ts +4 -304
  74. package/src/mint/types.ts +36 -7
  75. package/src/premint/premint-api-client.ts +1 -1
  76. package/src/premint/premint-client.ts +1 -1
  77. package/src/rewards/rewards-client.test.ts +318 -21
  78. package/src/rewards/rewards-client.ts +15 -16
  79. package/src/rewards/rewards-queries.ts +116 -36
  80. package/src/rewards/subgraph-queries.ts +0 -2
  81. package/src/rewards/subgraph-rewards-getter.ts +3 -13
  82. package/src/sdk.ts +9 -7
  83. package/src/secondary/secondary-client.test.ts +39 -40
  84. package/src/secondary/secondary-client.ts +14 -33
  85. package/src/secondary/uniswap/uniswapQuote.ts +3 -2
  86. package/src/secondary/utils.ts +2 -2
  87. package/src/types.ts +15 -4
  88. package/src/utils.ts +9 -3
  89. package/dist/create/1155-create-helper.d.ts +0 -29
  90. package/dist/create/1155-create-helper.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -1932,10 +1932,12 @@ __export(src_exports, {
1932
1932
  PremintAPIClient: () => PremintAPIClient,
1933
1933
  PremintClient: () => PremintClient,
1934
1934
  PremintConfigVersion: () => PremintConfigVersion3,
1935
+ SubgraphContractGetter: () => SubgraphContractGetter,
1935
1936
  SubgraphMintGetter: () => SubgraphMintGetter,
1936
1937
  ZORA_API_BASE: () => ZORA_API_BASE,
1937
1938
  applyUpdateToPremint: () => applyUpdateToPremint,
1938
1939
  buildPremintMintCall: () => buildPremintMintCall,
1940
+ buy1155OnSecondary: () => buy1155OnSecondary,
1939
1941
  collectPremint: () => collectPremint,
1940
1942
  collectPremintV2WithMintsParams: () => collectPremintV2WithMintsParams,
1941
1943
  collectWithMintsParams: () => collectWithMintsParams,
@@ -1943,9 +1945,11 @@ __export(src_exports, {
1943
1945
  convertGetPremintApiResponse: () => convertGetPremintApiResponse,
1944
1946
  convertGetPremintOfCollectionApiResponse: () => convertGetPremintOfCollectionApiResponse,
1945
1947
  convertPremintFromApi: () => convertPremintFromApi,
1948
+ create1155: () => create1155,
1946
1949
  createAllowList: () => createAllowList,
1947
1950
  createCollectorClient: () => createCollectorClient,
1948
1951
  createCreatorClient: () => createCreatorClient,
1952
+ createNew1155Token: () => createNew1155Token,
1949
1953
  decodeCallFailedError: () => decodeCallFailedError,
1950
1954
  defaultAdditionalAdmins: () => defaultAdditionalAdmins,
1951
1955
  defaultTokenConfigV1MintArguments: () => defaultTokenConfigV1MintArguments,
@@ -1954,8 +1958,8 @@ __export(src_exports, {
1954
1958
  encodeCollectOnManager: () => encodeCollectOnManager,
1955
1959
  encodePostSignatureInput: () => encodePostSignatureInput,
1956
1960
  encodePremintForAPI: () => encodePremintForAPI,
1961
+ findTargetStrategyWithPrimaryOrSecondarySaleActive: () => findTargetStrategyWithPrimaryOrSecondarySaleActive,
1957
1962
  generateTextNftMetadataFiles: () => generateTextNftMetadataFiles,
1958
- getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
1959
1963
  getContractAddressFromReceipt: () => getContractAddressFromReceipt,
1960
1964
  getDataFromPremintReceipt: () => getDataFromPremintReceipt,
1961
1965
  getDefaultFixedPriceMinterAddress: () => getDefaultFixedPriceMinterAddress,
@@ -1968,32 +1972,47 @@ __export(src_exports, {
1968
1972
  getPremintMintFee: () => getPremintMintFee,
1969
1973
  getPremintPricePerToken: () => getPremintPricePerToken,
1970
1974
  getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
1975
+ getRewardsBalances: () => getRewardsBalances,
1976
+ getSecondaryInfo: () => getSecondaryInfo,
1971
1977
  getSignature: () => getSignature,
1978
+ getToken: () => getToken,
1972
1979
  getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
1980
+ getTokensOfContract: () => getTokensOfContract,
1981
+ is1155Mint: () => is1155Mint,
1973
1982
  isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
1983
+ isOnChainMint: () => isOnChainMint,
1974
1984
  isPremintConfigV1: () => isPremintConfigV1,
1975
1985
  isPremintConfigV2: () => isPremintConfigV2,
1976
1986
  isValidSignature: () => isValidSignature,
1977
1987
  makeCreateContractAndTokenCall: () => makeCreateContractAndTokenCall,
1988
+ makeCreateTokenCall: () => makeCreateTokenCall,
1978
1989
  makeMediaTokenMetadata: () => makeMediaTokenMetadata,
1979
1990
  makeMintRewardsRecipient: () => makeMintRewardsRecipient,
1980
1991
  makeNewPremint: () => makeNewPremint,
1992
+ makeOnchainPrepareMintFromCreate: () => makeOnchainPrepareMintFromCreate,
1981
1993
  makePermitToCollectPremintOrNonPremint: () => makePermitToCollectPremintOrNonPremint,
1982
1994
  makePermitTransferBatchAndTypeData: () => makePermitTransferBatchAndTypeData,
1983
1995
  makePermitTransferTypeData: () => makePermitTransferTypeData,
1984
1996
  makeTextTokenMetadata: () => makeTextTokenMetadata,
1985
1997
  makeUrls: () => makeUrls,
1986
1998
  migratePremintConfigToV2: () => migratePremintConfigToV2,
1999
+ mint: () => mint,
1987
2000
  mintWithEthParams: () => mintWithEthParams,
1988
2001
  mintsBalanceOfAccountParams: () => mintsBalanceOfAccountParams,
2002
+ new1155ContractVersion: () => new1155ContractVersion,
2003
+ parseAndFilterTokenQueryResult: () => parseAndFilterTokenQueryResult,
2004
+ prepareSetupActions: () => prepareSetupActions,
1989
2005
  recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
1990
2006
  recoverPremintSigner: () => recoverPremintSigner,
1991
2007
  selectMintsToCollectWithFromQueryResult: () => selectMintsToCollectWithFromQueryResult,
2008
+ sell1155OnSecondary: () => sell1155OnSecondary,
1992
2009
  sumBalances: () => sumBalances,
1993
2010
  supportedPremintVersions: () => supportedPremintVersions,
1994
2011
  supportsPremintVersion: () => supportsPremintVersion,
1995
2012
  toContractCreationConfigOrAddress: () => toContractCreationConfigOrAddress,
1996
- tryRecoverPremintSigner: () => tryRecoverPremintSigner
2013
+ toMintableReturn: () => toMintableReturn,
2014
+ tryRecoverPremintSigner: () => tryRecoverPremintSigner,
2015
+ withdrawRewards: () => withdrawRewards
1997
2016
  });
1998
2017
  module.exports = __toCommonJS(src_exports);
1999
2018
 
@@ -2551,1196 +2570,1210 @@ var toContractCreationConfigOrAddress = ({
2551
2570
  // src/premint/premint-client.ts
2552
2571
  var import_protocol_deployments4 = require("@zoralabs/protocol-deployments");
2553
2572
 
2554
- // src/mint/subgraph-queries.ts
2555
- var NFT_SALE_STRATEGY_FRAGMENT = `
2556
- fragment SaleStrategy on SalesStrategyConfig {
2557
- type
2558
- fixedPrice {
2559
- address
2560
- pricePerToken
2561
- saleEnd
2562
- saleStart
2563
- maxTokensPerAddress
2564
- }
2565
- erc20Minter {
2566
- address
2567
- pricePerToken
2568
- currency
2569
- saleEnd
2570
- saleStart
2571
- maxTokensPerAddress
2572
- }
2573
- presale {
2574
- address
2575
- presaleStart
2576
- presaleEnd
2577
- merkleRoot
2578
- }
2579
- zoraTimedMinter {
2580
- address
2581
- mintFee
2582
- saleStart
2583
- saleEnd
2584
- erc20Z {
2585
- id
2586
- pool
2587
- }
2588
- secondaryActivated
2589
- marketCountdown
2590
- minimumMarketEth
2591
- }
2592
- }`;
2593
- var TOKEN_FRAGMENT = `
2594
- fragment Token on ZoraCreateToken {
2595
- creator
2596
- tokenId
2597
- uri
2598
- totalMinted
2599
- maxSupply
2600
- tokenStandard
2601
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
2602
- ...SaleStrategy
2603
- }
2604
- contract {
2605
- address
2606
- mintFeePerQuantity
2607
- contractVersion
2608
- contractURI
2609
- name
2610
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
2611
- ...SaleStrategy
2612
- }
2613
- }
2614
- }`;
2615
- var FRAGMENTS = `
2616
- ${NFT_SALE_STRATEGY_FRAGMENT}
2617
- ${TOKEN_FRAGMENT}
2618
- `;
2619
- function buildNftTokenSalesQuery({
2620
- tokenId,
2621
- tokenAddress
2622
- }) {
2623
- return {
2624
- query: `
2625
- ${FRAGMENTS}
2626
- query ($id: ID!) {
2627
- zoraCreateToken(id: $id) {
2628
- ...Token
2629
- }
2630
- }
2631
- `,
2632
- variables: {
2633
- id: tokenId !== void 0 ? (
2634
- // Generic Token ID types all stringify down to the base numeric equivalent.
2635
- `${tokenAddress.toLowerCase()}-${tokenId}`
2636
- ) : `${tokenAddress.toLowerCase()}-0`
2637
- },
2638
- parseResponseData: (responseData) => responseData?.zoraCreateToken
2639
- };
2640
- }
2641
- function buildContractTokensQuery({
2642
- tokenAddress
2643
- }) {
2644
- return {
2645
- query: `
2646
- ${FRAGMENTS}
2647
- query ($contract: Bytes!) {
2648
- zoraCreateTokens(
2649
- where: {address: $contract}
2650
- ) {
2651
- ...Token
2652
- }
2653
- }
2654
- `,
2655
- variables: {
2656
- contract: tokenAddress.toLowerCase()
2657
- },
2658
- parseResponseData: (responseData) => responseData?.zoraCreateTokens
2659
- };
2660
- }
2661
- function buildPremintsOfContractQuery({
2662
- tokenAddress
2573
+ // src/utils.ts
2574
+ var makeContractParameters = (args) => args;
2575
+ function mintRecipientOrAccount({
2576
+ mintRecipient,
2577
+ minterAccount
2663
2578
  }) {
2664
- return {
2665
- query: `
2666
- query ($contractAddress: Bytes!) {
2667
- premints(where:{contractAddress:$contractAddress}) {
2668
- uid
2669
- tokenId
2670
- }
2671
- }
2672
- `,
2673
- variables: {
2674
- contractAddress: tokenAddress.toLowerCase()
2675
- },
2676
- parseResponseData: (responseData) => responseData?.premints
2677
- };
2579
+ return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
2678
2580
  }
2581
+ var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
2679
2582
 
2680
- // src/apis/subgraph-querier.ts
2681
- var SubgraphQuerier = class {
2682
- constructor(httpClient2) {
2683
- this.httpClient = httpClient2;
2684
- }
2685
- async query({
2686
- subgraphUrl,
2687
- query,
2688
- variables
2689
- }) {
2690
- const { retries: retries2, post: post2 } = this.httpClient;
2691
- const result = await retries2(async () => {
2692
- return await post2(subgraphUrl, {
2693
- query,
2694
- variables
2695
- });
2696
- });
2697
- return result?.data;
2583
+ // src/apis/network-config.ts
2584
+ var getApiNetworkConfigForChain = (chainId) => {
2585
+ if (!networkConfigByChain[chainId]) {
2586
+ throw new Error(`chain id ${chainId} network not configured `);
2698
2587
  }
2588
+ return networkConfigByChain[chainId];
2699
2589
  };
2700
2590
 
2701
- // src/retries.ts
2702
- async function wait(delayMs) {
2703
- return new Promise((resolve) => {
2704
- setTimeout(resolve, delayMs);
2705
- });
2706
- }
2707
- var retryInternal = async ({
2708
- tryFn,
2709
- maxTries = 3,
2710
- atTry,
2711
- linearBackoffMS = 200,
2712
- shouldRetryOnError = () => true
2591
+ // src/premint/premint-client.ts
2592
+ var defaultTokenConfigV1MintArguments = () => ({
2593
+ maxSupply: OPEN_EDITION_MINT_SIZE,
2594
+ maxTokensPerAddress: 0n,
2595
+ pricePerToken: 0n,
2596
+ mintDuration: 0n,
2597
+ mintStart: 0n,
2598
+ royaltyMintSchedule: 0,
2599
+ royaltyBPS: 1e3
2600
+ // 10%,
2601
+ });
2602
+ var pickTokenConfigV1 = (tokenConfig) => ({
2603
+ maxSupply: tokenConfig.maxSupply,
2604
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
2605
+ pricePerToken: tokenConfig.pricePerToken,
2606
+ mintDuration: tokenConfig.mintDuration,
2607
+ mintStart: tokenConfig.mintStart,
2608
+ royaltyBPS: tokenConfig.royaltyBPS,
2609
+ tokenURI: tokenConfig.tokenURI,
2610
+ royaltyRecipient: tokenConfig.payoutRecipient
2611
+ });
2612
+ var pickTokenConfigV2 = (tokenConfig) => ({
2613
+ maxSupply: tokenConfig.maxSupply,
2614
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
2615
+ pricePerToken: tokenConfig.pricePerToken,
2616
+ mintDuration: tokenConfig.mintDuration,
2617
+ mintStart: tokenConfig.mintStart,
2618
+ royaltyBPS: tokenConfig.royaltyBPS,
2619
+ tokenURI: tokenConfig.tokenURI,
2620
+ payoutRecipient: tokenConfig.payoutRecipient,
2621
+ createReferral: tokenConfig.createReferral || import_viem4.zeroAddress
2622
+ });
2623
+ var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
2624
+ ...pickTokenConfigV1(tokenConfig),
2625
+ ...defaultTokenConfigV1MintArguments(),
2626
+ fixedPriceMinter
2627
+ });
2628
+ var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
2629
+ ...pickTokenConfigV2(tokenConfig),
2630
+ ...defaultTokenConfigV2MintArguments(),
2631
+ fixedPriceMinter
2632
+ });
2633
+ var defaultTokenConfigV2MintArguments = () => ({
2634
+ maxSupply: OPEN_EDITION_MINT_SIZE,
2635
+ maxTokensPerAddress: 0n,
2636
+ pricePerToken: 0n,
2637
+ mintDuration: 0n,
2638
+ mintStart: 0n,
2639
+ royaltyBPS: 1e3
2640
+ // 10%,
2641
+ });
2642
+ var makeTokenConfigWithDefaults = ({
2643
+ chainId,
2644
+ tokenCreationConfig,
2645
+ supportedPremintVersions: supportedPremintVersions2
2713
2646
  }) => {
2714
- try {
2715
- return await tryFn();
2716
- } catch (err) {
2717
- if (shouldRetryOnError(err)) {
2718
- if (atTry <= maxTries) {
2719
- await wait(atTry * linearBackoffMS);
2720
- return await retryInternal({
2721
- tryFn,
2722
- maxTries,
2723
- atTry: atTry + 1,
2724
- linearBackoffMS,
2725
- shouldRetryOnError
2726
- });
2727
- }
2647
+ const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
2648
+ if (!supportedPremintVersions2.includes(import_protocol_deployments4.PremintConfigVersion.V2)) {
2649
+ if (tokenCreationConfig.createReferral) {
2650
+ throw new Error("Contract does not support create referral");
2728
2651
  }
2729
- throw err;
2652
+ return {
2653
+ premintConfigVersion: import_protocol_deployments4.PremintConfigVersion.V1,
2654
+ tokenConfig: tokenConfigV1WithDefault(
2655
+ tokenCreationConfig,
2656
+ fixedPriceMinter
2657
+ )
2658
+ };
2730
2659
  }
2660
+ return {
2661
+ premintConfigVersion: import_protocol_deployments4.PremintConfigVersion.V2,
2662
+ tokenConfig: tokenConfigV2WithDefault(
2663
+ tokenCreationConfig,
2664
+ fixedPriceMinter
2665
+ )
2666
+ };
2731
2667
  };
2732
- var retriesGeneric = async (params) => {
2733
- return retryInternal({
2734
- ...params,
2735
- atTry: 1
2736
- });
2737
- };
2738
-
2739
- // src/apis/http-api-base.ts
2740
- var BadResponseError = class extends Error {
2741
- constructor(message, status, json) {
2742
- super(message);
2743
- this.name = "BadResponseError";
2744
- this.status = status;
2745
- this.json = json;
2746
- }
2747
- };
2748
- var get = async (url) => {
2749
- const response = await fetch(url, { method: "GET" });
2750
- if (response.status !== 200) {
2751
- let json;
2668
+ function getPremintedLogFromReceipt(receipt) {
2669
+ for (const data of receipt.logs) {
2752
2670
  try {
2753
- json = await response.json();
2754
- } catch (e) {
2671
+ const decodedLog = (0, import_viem4.decodeEventLog)({
2672
+ abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
2673
+ eventName: "PremintedV2",
2674
+ ...data
2675
+ });
2676
+ if (decodedLog.eventName === "PremintedV2") {
2677
+ return decodedLog.args;
2678
+ }
2679
+ } catch (err) {
2755
2680
  }
2756
- throw new BadResponseError(
2757
- `Invalid response, status ${response.status}`,
2758
- response.status,
2759
- json
2760
- );
2761
2681
  }
2762
- return await response.json();
2763
- };
2764
- var post = async (url, data) => {
2765
- const controller = new AbortController();
2766
- const { signal } = controller;
2767
- const timeout = 30 * 60 * 1e3;
2768
- const timeoutId = setTimeout(() => controller.abort(), timeout);
2769
- const response = await fetch(url, {
2770
- method: "POST",
2771
- headers: {
2772
- "content-type": "application/json",
2773
- accept: "application/json"
2774
- },
2775
- body: JSON.stringify(data),
2776
- signal
2777
- });
2778
- clearTimeout(timeoutId);
2779
- if (response.status !== 200) {
2780
- let json;
2781
- try {
2782
- json = await response.json();
2783
- } catch (e) {
2784
- }
2785
- throw new BadResponseError(
2786
- `Bad response: ${response.status}`,
2787
- response.status,
2788
- json
2789
- );
2682
+ }
2683
+ var PremintClient = class {
2684
+ constructor({
2685
+ chainId,
2686
+ publicClient,
2687
+ premintApi
2688
+ }) {
2689
+ this.chainId = chainId;
2690
+ this.apiClient = premintApi;
2691
+ this.publicClient = publicClient;
2790
2692
  }
2791
- return await response.json();
2792
- };
2793
- var defaultShouldRetry = (err) => {
2794
- return err instanceof BadResponseError && err.status >= 500;
2795
- };
2796
- var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
2797
- return retriesGeneric({
2798
- tryFn,
2799
- maxTries,
2800
- linearBackoffMS,
2801
- shouldRetryOnError: shouldRetry
2802
- });
2803
- };
2804
- var httpClient = {
2805
- get,
2806
- post,
2807
- retries
2808
- };
2809
-
2810
- // src/apis/subgraph-getter.ts
2811
- var SubgraphGetter = class {
2812
- constructor(chainId, subgraphQuerier) {
2813
- this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
2814
- this.networkConfig = getApiNetworkConfigForChain(chainId);
2693
+ getDataFromPremintReceipt(receipt, blockExplorerUrl) {
2694
+ return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
2815
2695
  }
2816
- async querySubgraphWithRetries({
2817
- query,
2818
- variables,
2819
- parseResponseData
2696
+ /**
2697
+ * Prepares data for updating a premint
2698
+ *
2699
+ * @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
2700
+ * @returns A PremintReturn. {@link PremintReturn}
2701
+ */
2702
+ async updatePremint(args) {
2703
+ return await updatePremint({
2704
+ ...args,
2705
+ apiClient: this.apiClient,
2706
+ publicClient: this.publicClient,
2707
+ chainId: this.chainId
2708
+ });
2709
+ }
2710
+ /**
2711
+ * Prepares data for deleting a premint
2712
+ *
2713
+ * @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
2714
+ * @returns A PremintReturn. {@link PremintReturn}
2715
+ */
2716
+ async deletePremint(params) {
2717
+ return deletePremint({
2718
+ ...params,
2719
+ apiClient: this.apiClient,
2720
+ publicClient: this.publicClient,
2721
+ chainId: this.chainId
2722
+ });
2723
+ }
2724
+ /**
2725
+ * Prepares data for creating a premint
2726
+ *
2727
+ * @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
2728
+ * @returns A PremintReturn. {@link PremintReturn}
2729
+ */
2730
+ async createPremint(parameters) {
2731
+ return createPremint({
2732
+ ...parameters,
2733
+ publicClient: this.publicClient,
2734
+ apiClient: this.apiClient,
2735
+ chainId: this.chainId
2736
+ });
2737
+ }
2738
+ /**
2739
+ * Fetches given premint data from the ZORA API.
2740
+ *
2741
+ * @param address Address for the premint contract
2742
+ * @param uid UID for the desired premint
2743
+ * @returns PremintSignatureGetResponse of premint data from the API
2744
+ */
2745
+ async getPremint({ address, uid }) {
2746
+ return await this.apiClient.get({
2747
+ collectionAddress: address,
2748
+ uid
2749
+ });
2750
+ }
2751
+ /**
2752
+ * Gets the deterministic contract address for a premint collection
2753
+ * @param collection Collection to get the address for
2754
+ * @returns deterministic contract address
2755
+ */
2756
+ async getCollectionAddress(collection) {
2757
+ return await getPremintCollectionAddress({
2758
+ contract: collection,
2759
+ publicClient: this.publicClient
2760
+ });
2761
+ }
2762
+ async getMintCosts({
2763
+ tokenContract,
2764
+ quantityToMint,
2765
+ pricePerToken
2820
2766
  }) {
2821
- const responseData = await this.subgraphQuerier.query({
2822
- subgraphUrl: this.networkConfig.subgraphUrl,
2823
- query,
2824
- variables
2767
+ return await getPremintMintCosts({
2768
+ publicClient: this.publicClient,
2769
+ quantityToMint,
2770
+ tokenContract,
2771
+ tokenPrice: pricePerToken
2825
2772
  });
2826
- return parseResponseData(responseData);
2827
2773
  }
2828
- };
2829
-
2830
- // src/mint/subgraph-mint-getter.ts
2831
- var getApiNetworkConfigForChain = (chainId) => {
2832
- if (!networkConfigByChain[chainId]) {
2833
- throw new Error(`chain id ${chainId} network not configured `);
2774
+ /**
2775
+ * Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
2776
+ * tokens on that contract for the mint recipient.
2777
+ *
2778
+ * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
2779
+ * @returns receipt, log, zoraURL
2780
+ */
2781
+ async makeMintParameters({
2782
+ minterAccount,
2783
+ tokenContract,
2784
+ uid,
2785
+ mintArguments,
2786
+ firstMinter
2787
+ }) {
2788
+ return await collectPremint({
2789
+ uid,
2790
+ tokenContract,
2791
+ minterAccount,
2792
+ quantityToMint: mintArguments?.quantityToMint || 1n,
2793
+ mintComment: mintArguments?.mintComment,
2794
+ mintReferral: mintArguments?.mintReferral,
2795
+ mintRecipient: mintArguments?.mintRecipient,
2796
+ firstMinter,
2797
+ premintGetter: this.apiClient,
2798
+ publicClient: this.publicClient
2799
+ });
2834
2800
  }
2835
- return networkConfigByChain[chainId];
2836
2801
  };
2837
- function parseFixedPriceSalesConfig(fixedPrice, contractMintFee, blockTime) {
2838
- const saleEnd = BigInt(fixedPrice.saleEnd);
2839
- return {
2840
- salesStrategy: {
2841
- saleType: "fixedPrice",
2842
- ...fixedPrice,
2843
- maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
2844
- pricePerToken: BigInt(fixedPrice.pricePerToken),
2845
- mintFeePerQuantity: contractMintFee
2846
- },
2847
- saleEnd,
2848
- saleActive: BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime
2849
- };
2850
- }
2851
- function parseERC20SalesConfig(erc20Minter, blockTime) {
2852
- const saleEnd = BigInt(erc20Minter.saleEnd);
2853
- return {
2854
- salesStrategy: {
2855
- saleType: "erc20",
2856
- ...erc20Minter,
2857
- maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
2858
- pricePerToken: BigInt(erc20Minter.pricePerToken),
2859
- mintFeePerQuantity: 0n
2860
- },
2861
- saleEnd,
2862
- saleActive: BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime
2863
- };
2864
- }
2865
- function parsePresaleSalesConfig(presale, contractMintFee, blockTime) {
2866
- const saleEnd = BigInt(presale.presaleEnd);
2802
+ function getDataFromPremintReceipt(receipt, chainId, blockExplorerUrl) {
2803
+ const premintedLog = getPremintedLogFromReceipt(receipt);
2867
2804
  return {
2868
- salesStrategy: {
2869
- saleType: "allowlist",
2870
- address: presale.address,
2871
- merkleRoot: presale.merkleRoot,
2872
- saleStart: presale.presaleStart,
2873
- saleEnd: presale.presaleEnd,
2874
- mintFeePerQuantity: contractMintFee
2875
- },
2876
- saleEnd,
2877
- saleActive: BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime
2805
+ tokenId: premintedLog?.tokenId,
2806
+ collectionAddres: premintedLog?.contractAddress,
2807
+ premintedLog,
2808
+ urls: makeUrls({
2809
+ address: premintedLog?.contractAddress,
2810
+ tokenId: premintedLog?.tokenId,
2811
+ chainId,
2812
+ blockExplorerUrl
2813
+ })
2878
2814
  };
2879
2815
  }
2880
- function parseZoraTimedSalesConfig(zoraTimedMinter, blockTime) {
2881
- const saleEnd = BigInt(zoraTimedMinter.saleEnd);
2882
- const hasSaleEnd = saleEnd > 0n;
2883
- return {
2884
- salesStrategy: {
2885
- saleType: "timed",
2886
- address: zoraTimedMinter.address,
2887
- mintFee: BigInt(zoraTimedMinter.mintFee),
2888
- saleStart: zoraTimedMinter.saleStart,
2889
- saleEnd: zoraTimedMinter.saleEnd,
2890
- erc20Z: zoraTimedMinter.erc20Z.id,
2891
- pool: zoraTimedMinter.erc20Z.pool,
2892
- secondaryActivated: zoraTimedMinter.secondaryActivated,
2893
- mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
2894
- marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
2895
- minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
2896
- },
2897
- saleEnd: hasSaleEnd ? saleEnd : void 0,
2898
- secondaryMarketActive: zoraTimedMinter.secondaryActivated,
2899
- saleActive: BigInt(zoraTimedMinter.saleStart) <= blockTime && (hasSaleEnd ? saleEnd > blockTime : true)
2900
- };
2901
- }
2902
- function parseSalesConfig(targetStrategy, contractMintFee, blockTime) {
2903
- switch (targetStrategy.type) {
2904
- case "FIXED_PRICE":
2905
- return parseFixedPriceSalesConfig(
2906
- targetStrategy.fixedPrice,
2907
- contractMintFee,
2908
- blockTime
2909
- );
2910
- case "ERC_20_MINTER":
2911
- return parseERC20SalesConfig(targetStrategy.erc20Minter, blockTime);
2912
- case "PRESALE":
2913
- return parsePresaleSalesConfig(
2914
- targetStrategy.presale,
2915
- contractMintFee,
2916
- blockTime
2917
- );
2918
- case "ZORA_TIMED":
2919
- return parseZoraTimedSalesConfig(
2920
- targetStrategy.zoraTimedMinter,
2921
- blockTime
2922
- );
2923
- default:
2924
- throw new Error("Unknown saleType");
2925
- }
2926
- }
2927
- function getTargetStrategy({
2928
- tokenId,
2929
- preferredSaleType,
2930
- token,
2931
- blockTime,
2932
- contractMintFee
2816
+ function makePremintReturn({
2817
+ premintConfig,
2818
+ premintConfigVersion,
2819
+ publicClient,
2820
+ apiClient,
2821
+ chainId,
2822
+ ...collectionAndAddress
2933
2823
  }) {
2934
- const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
2935
- const parsedStrategies = allStrategies.map(
2936
- (strategy) => parseSalesConfig(strategy, contractMintFee, blockTime)
2937
- );
2938
- const stillValidSalesStrategies = parsedStrategies.filter(
2939
- (strategy) => strategy.saleActive || strategy.secondaryMarketActive
2940
- );
2941
- const saleStrategies = stillValidSalesStrategies.sort(
2942
- (a, b) => (a.saleEnd ?? 0n) > (b.saleEnd ?? 0n) ? 1 : -1
2943
- );
2944
- let targetStrategy;
2945
- if (!preferredSaleType) {
2946
- return saleStrategies[0];
2947
- } else {
2948
- targetStrategy = saleStrategies.find(
2949
- ({ salesStrategy }) => salesStrategy.saleType === preferredSaleType
2950
- );
2951
- if (!targetStrategy) {
2952
- const targetStrategy2 = saleStrategies.find(
2953
- ({ salesStrategy }) => salesStrategy.saleType === "timed" || salesStrategy.saleType === "fixedPrice" || salesStrategy.saleType === "erc20"
2954
- );
2955
- if (!targetStrategy2)
2956
- throw new Error("Cannot find valid sale strategy");
2957
- return targetStrategy2;
2824
+ const { collection, collectionAddress } = collectionAndAddress;
2825
+ const typedDataDefinition = (0, import_protocol_deployments4.premintTypedDataDefinition)({
2826
+ verifyingContract: collectionAddress,
2827
+ premintConfig,
2828
+ premintConfigVersion,
2829
+ chainId
2830
+ });
2831
+ const signAndSubmit = async ({
2832
+ walletClient,
2833
+ account,
2834
+ checkSignature
2835
+ }) => {
2836
+ const { signature, signerAccount } = await signPremint({
2837
+ account,
2838
+ walletClient,
2839
+ typedDataDefinition
2840
+ });
2841
+ await submit({
2842
+ signature,
2843
+ checkSignature,
2844
+ account: signerAccount
2845
+ });
2846
+ return {
2847
+ signature,
2848
+ signerAccount
2849
+ };
2850
+ };
2851
+ const submit = async ({
2852
+ signature,
2853
+ checkSignature,
2854
+ account
2855
+ }) => {
2856
+ if (checkSignature) {
2857
+ const isAuthorized = await isAuthorizedToCreatePremint({
2858
+ collectionAddress,
2859
+ additionalAdmins: collection?.additionalAdmins,
2860
+ contractAdmin: collection?.contractAdmin,
2861
+ publicClient,
2862
+ signer: account
2863
+ });
2864
+ if (!isAuthorized) {
2865
+ throw new Error("Not authorized to create premint");
2866
+ }
2958
2867
  }
2959
- }
2960
- return targetStrategy;
2868
+ await apiClient.postSignature({
2869
+ ...toContractCreationConfigOrAddress(collectionAndAddress),
2870
+ signature,
2871
+ premintConfig,
2872
+ premintConfigVersion
2873
+ });
2874
+ };
2875
+ const urls = makeUrls({
2876
+ chainId,
2877
+ address: collectionAddress,
2878
+ uid: premintConfig.uid
2879
+ });
2880
+ return {
2881
+ premintConfig,
2882
+ premintConfigVersion,
2883
+ typedDataDefinition,
2884
+ collectionAddress,
2885
+ signAndSubmit,
2886
+ submit,
2887
+ urls
2888
+ };
2961
2889
  }
2962
- var SubgraphMintGetter = class extends SubgraphGetter {
2963
- constructor(chainId, subgraphQuerier) {
2964
- super(chainId, subgraphQuerier);
2965
- this.getMintable = async ({
2966
- tokenAddress,
2967
- tokenId,
2968
- preferredSaleType: saleType,
2969
- blockTime
2970
- }) => {
2971
- const token = await this.querySubgraphWithRetries(
2972
- buildNftTokenSalesQuery({
2973
- tokenId,
2974
- tokenAddress
2975
- })
2976
- );
2977
- if (!token) {
2978
- throw new Error("Cannot find token");
2979
- }
2980
- const defaultMintFee = await this.getContractMintFee(token.contract);
2981
- return parseTokenQueryResult({
2982
- token,
2983
- defaultMintFee,
2984
- tokenId,
2985
- preferredSaleType: saleType,
2986
- blockTime
2987
- });
2988
- };
2989
- }
2990
- async getContractMintFee(contract) {
2991
- return BigInt(contract.mintFeePerQuantity);
2992
- }
2993
- async getContractMintable({
2994
- tokenAddress,
2995
- preferredSaleType,
2996
- blockTime
2997
- }) {
2998
- const tokens = await this.querySubgraphWithRetries(
2999
- buildContractTokensQuery({
3000
- tokenAddress
3001
- })
3002
- );
3003
- if (!tokens || tokens.length === 0)
3004
- return [];
3005
- const defaultMintFee = await this.getContractMintFee(tokens[0].contract);
3006
- return tokens.filter((x) => x.tokenId !== "0").map(
3007
- (token) => parseTokenQueryResult({
3008
- token,
3009
- tokenId: token.tokenId,
3010
- preferredSaleType,
3011
- defaultMintFee,
3012
- blockTime
3013
- })
3014
- );
2890
+ async function signPremint({
2891
+ account,
2892
+ walletClient,
2893
+ typedDataDefinition
2894
+ }) {
2895
+ if (!account) {
2896
+ account = walletClient.account;
3015
2897
  }
3016
- async getContractPremintTokenIds({
3017
- tokenAddress
3018
- }) {
3019
- const premints = await this.querySubgraphWithRetries(
3020
- buildPremintsOfContractQuery({
3021
- tokenAddress
3022
- })
3023
- );
3024
- return premints?.map((premint) => ({
3025
- tokenId: BigInt(premint.tokenId),
3026
- uid: +premint.uid
3027
- })) || [];
2898
+ if (!account) {
2899
+ throw new Error("No account provided");
3028
2900
  }
3029
- };
3030
- function getTargetStrategyAndMintFeeAndSaleActive({
3031
- token,
3032
- tokenId,
3033
- preferredSaleType,
3034
- defaultMintFee,
3035
- blockTime
3036
- }) {
3037
- const targetStrategy = getTargetStrategy({
3038
- tokenId,
3039
- preferredSaleType,
3040
- token,
3041
- blockTime,
3042
- contractMintFee: defaultMintFee
2901
+ const signature = await walletClient.signTypedData({
2902
+ account,
2903
+ ...typedDataDefinition
3043
2904
  });
3044
- return targetStrategy;
2905
+ return {
2906
+ signature,
2907
+ signerAccount: account
2908
+ };
3045
2909
  }
3046
- function parseTokenQueryResult({
3047
- token,
3048
- tokenId,
3049
- preferredSaleType,
3050
- defaultMintFee,
3051
- blockTime
2910
+ async function createPremint({
2911
+ token: tokenCreationConfig,
2912
+ uid,
2913
+ publicClient,
2914
+ apiClient,
2915
+ chainId,
2916
+ ...collectionOrAddress
3052
2917
  }) {
3053
- const salesStrategyAndMintInfo = getTargetStrategyAndMintFeeAndSaleActive({
3054
- token,
3055
- tokenId,
3056
- preferredSaleType,
3057
- defaultMintFee,
3058
- blockTime
2918
+ const {
2919
+ premintConfig,
2920
+ premintConfigVersion,
2921
+ collectionAddress: collectionAddressToUse
2922
+ } = await prepareCreatePremintConfig({
2923
+ ...collectionOrAddress,
2924
+ tokenCreationConfig,
2925
+ uid,
2926
+ publicClient,
2927
+ apiClient,
2928
+ chainId
3059
2929
  });
3060
- const tokenInfo = parseTokenInfo({
3061
- token
2930
+ return makePremintReturn({
2931
+ premintConfig,
2932
+ premintConfigVersion,
2933
+ collectionAddress: collectionAddressToUse,
2934
+ collection: collectionOrAddress.contract,
2935
+ publicClient,
2936
+ apiClient,
2937
+ chainId
3062
2938
  });
3063
- return {
3064
- salesConfigAndTokenInfo: {
3065
- ...tokenInfo,
3066
- salesConfig: salesStrategyAndMintInfo?.salesStrategy
3067
- },
3068
- primaryMintActive: salesStrategyAndMintInfo?.saleActive ?? false,
3069
- primaryMintEnd: salesStrategyAndMintInfo?.saleEnd,
3070
- secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
3071
- };
3072
2939
  }
3073
- function parseTokenInfo({
3074
- token
2940
+ async function prepareCreatePremintConfig({
2941
+ tokenCreationConfig,
2942
+ uid,
2943
+ publicClient,
2944
+ apiClient,
2945
+ chainId,
2946
+ ...collectionOrAddress
3075
2947
  }) {
2948
+ const newContractAddress = await getPremintCollectionAddress({
2949
+ publicClient,
2950
+ ...collectionOrAddress
2951
+ });
2952
+ let uidToUse = uid;
2953
+ if (typeof uidToUse !== "number") {
2954
+ uidToUse = await apiClient.getNextUID(newContractAddress);
2955
+ }
2956
+ const supportedVersions = await supportedPremintVersions({
2957
+ tokenContract: newContractAddress,
2958
+ publicClient
2959
+ });
2960
+ const tokenConfigAndVersion = makeTokenConfigWithDefaults({
2961
+ tokenCreationConfig,
2962
+ chainId,
2963
+ supportedPremintVersions: supportedVersions
2964
+ });
2965
+ const premintConfig = makeNewPremint({
2966
+ ...tokenConfigAndVersion,
2967
+ uid: uidToUse
2968
+ });
2969
+ const premintConfigAndVersion = {
2970
+ premintConfig,
2971
+ premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
2972
+ };
3076
2973
  return {
3077
- contract: {
3078
- address: token.contract.address,
3079
- name: token.contract.name,
3080
- URI: token.contract.contractURI
3081
- },
3082
- tokenURI: token.uri,
3083
- tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
3084
- mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
3085
- creator: token.creator,
3086
- totalMinted: BigInt(token.totalMinted),
3087
- maxSupply: BigInt(token.maxSupply),
3088
- contractVersion: token.contract.contractVersion
2974
+ ...premintConfigAndVersion,
2975
+ collectionAddress: newContractAddress
3089
2976
  };
3090
2977
  }
3091
-
3092
- // src/utils.ts
3093
- var makeContractParameters = (args) => args;
3094
- function mintRecipientOrAccount({
2978
+ async function updatePremint({
2979
+ uid,
2980
+ collection,
2981
+ tokenConfigUpdates,
2982
+ apiClient,
2983
+ publicClient,
2984
+ chainId
2985
+ }) {
2986
+ const {
2987
+ premint: { premintConfig, premintConfigVersion },
2988
+ collection: collectionCreationConfig
2989
+ } = await apiClient.get({
2990
+ collectionAddress: collection,
2991
+ uid
2992
+ });
2993
+ const updatedPremint = applyUpdateToPremint({
2994
+ uid: premintConfig.uid,
2995
+ version: premintConfig.version,
2996
+ tokenConfig: premintConfig.tokenConfig,
2997
+ tokenConfigUpdates
2998
+ });
2999
+ return makePremintReturn({
3000
+ premintConfig: updatedPremint,
3001
+ premintConfigVersion,
3002
+ collectionAddress: collection,
3003
+ collection: collectionCreationConfig,
3004
+ publicClient,
3005
+ apiClient,
3006
+ chainId
3007
+ });
3008
+ }
3009
+ async function deletePremint({
3010
+ uid,
3011
+ collection,
3012
+ publicClient,
3013
+ apiClient,
3014
+ chainId
3015
+ }) {
3016
+ const {
3017
+ premint: { premintConfig, premintConfigVersion },
3018
+ collection: collectionCreationConfig,
3019
+ collectionAddress
3020
+ } = await apiClient.get({
3021
+ collectionAddress: collection,
3022
+ uid
3023
+ });
3024
+ const deletedPremint = {
3025
+ ...premintConfig,
3026
+ version: premintConfig.version + 1,
3027
+ deleted: true
3028
+ };
3029
+ return makePremintReturn({
3030
+ premintConfig: deletedPremint,
3031
+ premintConfigVersion,
3032
+ collectionAddress,
3033
+ collection: collectionCreationConfig,
3034
+ publicClient,
3035
+ apiClient,
3036
+ chainId
3037
+ });
3038
+ }
3039
+ async function collectPremint({
3040
+ uid,
3041
+ tokenContract,
3042
+ minterAccount,
3043
+ quantityToMint,
3044
+ mintComment = "",
3045
+ mintReferral,
3095
3046
  mintRecipient,
3096
- minterAccount
3047
+ firstMinter,
3048
+ premintGetter,
3049
+ publicClient
3097
3050
  }) {
3098
- return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
3051
+ if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
3052
+ throw new Error("Quantity to mint cannot be below 1");
3053
+ }
3054
+ const premint = await premintGetter.get({
3055
+ collectionAddress: tokenContract,
3056
+ uid
3057
+ });
3058
+ const mintFee = await getPremintMintFee({
3059
+ tokenContract,
3060
+ publicClient
3061
+ });
3062
+ return buildPremintMintCall({
3063
+ mintArguments: {
3064
+ minterAccount,
3065
+ quantityToMint,
3066
+ firstMinter,
3067
+ mintComment,
3068
+ mintRecipient,
3069
+ mintReferral
3070
+ },
3071
+ mintFee,
3072
+ premint
3073
+ });
3099
3074
  }
3100
- var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
3101
-
3102
- // src/premint/premint-client.ts
3103
- var defaultTokenConfigV1MintArguments = () => ({
3104
- maxSupply: OPEN_EDITION_MINT_SIZE,
3105
- maxTokensPerAddress: 0n,
3106
- pricePerToken: 0n,
3107
- mintDuration: 0n,
3108
- mintStart: 0n,
3109
- royaltyMintSchedule: 0,
3110
- royaltyBPS: 1e3
3111
- // 10%,
3112
- });
3113
- var pickTokenConfigV1 = (tokenConfig) => ({
3114
- maxSupply: tokenConfig.maxSupply,
3115
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
3116
- pricePerToken: tokenConfig.pricePerToken,
3117
- mintDuration: tokenConfig.mintDuration,
3118
- mintStart: tokenConfig.mintStart,
3119
- royaltyBPS: tokenConfig.royaltyBPS,
3120
- tokenURI: tokenConfig.tokenURI,
3121
- royaltyRecipient: tokenConfig.payoutRecipient
3122
- });
3123
- var pickTokenConfigV2 = (tokenConfig) => ({
3124
- maxSupply: tokenConfig.maxSupply,
3125
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
3126
- pricePerToken: tokenConfig.pricePerToken,
3127
- mintDuration: tokenConfig.mintDuration,
3128
- mintStart: tokenConfig.mintStart,
3129
- royaltyBPS: tokenConfig.royaltyBPS,
3130
- tokenURI: tokenConfig.tokenURI,
3131
- payoutRecipient: tokenConfig.payoutRecipient,
3132
- createReferral: tokenConfig.createReferral || import_viem4.zeroAddress
3133
- });
3134
- var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
3135
- ...pickTokenConfigV1(tokenConfig),
3136
- ...defaultTokenConfigV1MintArguments(),
3137
- fixedPriceMinter
3138
- });
3139
- var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
3140
- ...pickTokenConfigV2(tokenConfig),
3141
- ...defaultTokenConfigV2MintArguments(),
3142
- fixedPriceMinter
3143
- });
3144
- var defaultTokenConfigV2MintArguments = () => ({
3145
- maxSupply: OPEN_EDITION_MINT_SIZE,
3146
- maxTokensPerAddress: 0n,
3147
- pricePerToken: 0n,
3148
- mintDuration: 0n,
3149
- mintStart: 0n,
3150
- royaltyBPS: 1e3
3151
- // 10%,
3152
- });
3153
- var makeTokenConfigWithDefaults = ({
3154
- chainId,
3155
- tokenCreationConfig,
3156
- supportedPremintVersions: supportedPremintVersions2
3075
+ var buildPremintMintCall = ({
3076
+ mintArguments: {
3077
+ minterAccount,
3078
+ mintComment = "",
3079
+ mintRecipient,
3080
+ mintReferral,
3081
+ firstMinter,
3082
+ quantityToMint
3083
+ },
3084
+ premint: { collection, collectionAddress, premint, signature },
3085
+ mintFee
3157
3086
  }) => {
3158
- const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
3159
- if (!supportedPremintVersions2.includes(import_protocol_deployments4.PremintConfigVersion.V2)) {
3160
- if (tokenCreationConfig.createReferral) {
3161
- throw new Error("Contract does not support create referral");
3162
- }
3163
- return {
3164
- premintConfigVersion: import_protocol_deployments4.PremintConfigVersion.V1,
3165
- tokenConfig: tokenConfigV1WithDefault(
3166
- tokenCreationConfig,
3167
- fixedPriceMinter
3168
- )
3169
- };
3170
- }
3171
- return {
3172
- premintConfigVersion: import_protocol_deployments4.PremintConfigVersion.V2,
3173
- tokenConfig: tokenConfigV2WithDefault(
3174
- tokenCreationConfig,
3175
- fixedPriceMinter
3176
- )
3087
+ const mintArgumentsContract = {
3088
+ mintComment,
3089
+ mintRecipient: mintRecipientOrAccount({
3090
+ mintRecipient,
3091
+ minterAccount
3092
+ }),
3093
+ mintRewardsRecipients: makeMintRewardsRecipient({
3094
+ mintReferral
3095
+ })
3177
3096
  };
3097
+ const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
3098
+ const collectionAddressToSubmit = collection ? import_viem4.zeroAddress : collectionAddress;
3099
+ const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
3100
+ if (premint.premintConfigVersion === import_protocol_deployments4.PremintConfigVersion.V3) {
3101
+ throw new Error("PremintV3 not supported in premint SDK");
3102
+ }
3103
+ const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
3104
+ return makeContractParameters({
3105
+ account: minterAccount,
3106
+ abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
3107
+ functionName: "premint",
3108
+ value,
3109
+ address: getPremintExecutorAddress(),
3110
+ args: [
3111
+ collectionOrEmpty,
3112
+ collectionAddressToSubmit,
3113
+ (0, import_protocol_deployments3.encodePremintConfig)(premint),
3114
+ signature,
3115
+ BigInt(quantityToMint),
3116
+ mintArgumentsContract,
3117
+ firstMinterToSubmit,
3118
+ import_viem4.zeroAddress
3119
+ ]
3120
+ });
3178
3121
  };
3179
- function getPremintedLogFromReceipt(receipt) {
3180
- for (const data of receipt.logs) {
3181
- try {
3182
- const decodedLog = (0, import_viem4.decodeEventLog)({
3183
- abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
3184
- eventName: "PremintedV2",
3185
- ...data
3186
- });
3187
- if (decodedLog.eventName === "PremintedV2") {
3188
- return decodedLog.args;
3189
- }
3190
- } catch (err) {
3191
- }
3122
+ function makeUrls({
3123
+ uid,
3124
+ address,
3125
+ tokenId,
3126
+ chainId,
3127
+ blockExplorerUrl
3128
+ }) {
3129
+ if ((!uid || !tokenId) && !address) {
3130
+ return { explorer: null, zoraCollect: null, zoraManage: null };
3192
3131
  }
3132
+ const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
3133
+ const network = getApiNetworkConfigForChain(chainId);
3134
+ return {
3135
+ explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
3136
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
3137
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
3138
+ };
3193
3139
  }
3194
- var PremintClient = class {
3195
- constructor({
3196
- chainId,
3197
- publicClient,
3198
- premintApi
3199
- }) {
3200
- this.chainId = chainId;
3201
- this.apiClient = premintApi;
3202
- this.publicClient = publicClient;
3203
- }
3204
- getDataFromPremintReceipt(receipt, blockExplorerUrl) {
3205
- return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
3206
- }
3207
- /**
3208
- * Prepares data for updating a premint
3209
- *
3210
- * @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
3211
- * @returns A PremintReturn. {@link PremintReturn}
3212
- */
3213
- async updatePremint(args) {
3214
- return await updatePremint({
3215
- ...args,
3216
- apiClient: this.apiClient,
3217
- publicClient: this.publicClient,
3218
- chainId: this.chainId
3219
- });
3220
- }
3221
- /**
3222
- * Prepares data for deleting a premint
3223
- *
3224
- * @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
3225
- * @returns A PremintReturn. {@link PremintReturn}
3226
- */
3227
- async deletePremint(params) {
3228
- return deletePremint({
3229
- ...params,
3230
- apiClient: this.apiClient,
3231
- publicClient: this.publicClient,
3232
- chainId: this.chainId
3233
- });
3234
- }
3235
- /**
3236
- * Prepares data for creating a premint
3237
- *
3238
- * @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
3239
- * @returns A PremintReturn. {@link PremintReturn}
3240
- */
3241
- async createPremint(parameters) {
3242
- return createPremint({
3243
- ...parameters,
3244
- publicClient: this.publicClient,
3245
- apiClient: this.apiClient,
3246
- chainId: this.chainId
3247
- });
3248
- }
3249
- /**
3250
- * Fetches given premint data from the ZORA API.
3251
- *
3252
- * @param address Address for the premint contract
3253
- * @param uid UID for the desired premint
3254
- * @returns PremintSignatureGetResponse of premint data from the API
3255
- */
3256
- async getPremint({ address, uid }) {
3257
- return await this.apiClient.get({
3258
- collectionAddress: address,
3259
- uid
3260
- });
3261
- }
3262
- /**
3263
- * Gets the deterministic contract address for a premint collection
3264
- * @param collection Collection to get the address for
3265
- * @returns deterministic contract address
3266
- */
3267
- async getCollectionAddress(collection) {
3268
- return await getPremintCollectionAddress({
3269
- contract: collection,
3270
- publicClient: this.publicClient
3271
- });
3140
+
3141
+ // src/premint/contract-types.ts
3142
+ var import_protocol_deployments5 = require("@zoralabs/protocol-deployments");
3143
+ var PremintConfigVersion3 = ((PremintConfigVersion4) => {
3144
+ PremintConfigVersion4[PremintConfigVersion4["V1"] = import_protocol_deployments5.PremintConfigVersion.V1] = "V1";
3145
+ PremintConfigVersion4[PremintConfigVersion4["V2"] = import_protocol_deployments5.PremintConfigVersion.V2] = "V2";
3146
+ PremintConfigVersion4[PremintConfigVersion4["V3"] = import_protocol_deployments5.PremintConfigVersion.V3] = "V3";
3147
+ return PremintConfigVersion4;
3148
+ })(PremintConfigVersion3 || {});
3149
+
3150
+ // src/retries.ts
3151
+ async function wait(delayMs) {
3152
+ return new Promise((resolve) => {
3153
+ setTimeout(resolve, delayMs);
3154
+ });
3155
+ }
3156
+ var retryInternal = async ({
3157
+ tryFn,
3158
+ maxTries = 3,
3159
+ atTry,
3160
+ linearBackoffMS = 200,
3161
+ shouldRetryOnError = () => true
3162
+ }) => {
3163
+ try {
3164
+ return await tryFn();
3165
+ } catch (err) {
3166
+ if (shouldRetryOnError(err)) {
3167
+ if (atTry <= maxTries) {
3168
+ await wait(atTry * linearBackoffMS);
3169
+ return await retryInternal({
3170
+ tryFn,
3171
+ maxTries,
3172
+ atTry: atTry + 1,
3173
+ linearBackoffMS,
3174
+ shouldRetryOnError
3175
+ });
3176
+ }
3177
+ }
3178
+ throw err;
3272
3179
  }
3273
- async getMintCosts({
3274
- tokenContract,
3275
- quantityToMint,
3276
- pricePerToken
3277
- }) {
3278
- return await getPremintMintCosts({
3279
- publicClient: this.publicClient,
3280
- quantityToMint,
3281
- tokenContract,
3282
- tokenPrice: pricePerToken
3283
- });
3180
+ };
3181
+ var retriesGeneric = async (params) => {
3182
+ return retryInternal({
3183
+ ...params,
3184
+ atTry: 1
3185
+ });
3186
+ };
3187
+
3188
+ // src/apis/http-api-base.ts
3189
+ var BadResponseError = class extends Error {
3190
+ constructor(message, status, json) {
3191
+ super(message);
3192
+ this.name = "BadResponseError";
3193
+ this.status = status;
3194
+ this.json = json;
3284
3195
  }
3285
- /**
3286
- * Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
3287
- * tokens on that contract for the mint recipient.
3288
- *
3289
- * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
3290
- * @returns receipt, log, zoraURL
3291
- */
3292
- async makeMintParameters({
3293
- minterAccount,
3294
- tokenContract,
3295
- uid,
3296
- mintArguments,
3297
- firstMinter
3298
- }) {
3299
- return await collectPremint({
3300
- uid,
3301
- tokenContract,
3302
- minterAccount,
3303
- quantityToMint: mintArguments?.quantityToMint || 1n,
3304
- mintComment: mintArguments?.mintComment,
3305
- mintReferral: mintArguments?.mintReferral,
3306
- mintRecipient: mintArguments?.mintRecipient,
3307
- firstMinter,
3308
- premintGetter: this.apiClient,
3309
- publicClient: this.publicClient
3310
- });
3196
+ };
3197
+ var get = async (url) => {
3198
+ const response = await fetch(url, { method: "GET" });
3199
+ if (response.status !== 200) {
3200
+ let json;
3201
+ try {
3202
+ json = await response.json();
3203
+ } catch (e) {
3204
+ }
3205
+ throw new BadResponseError(
3206
+ `Invalid response, status ${response.status}`,
3207
+ response.status,
3208
+ json
3209
+ );
3311
3210
  }
3211
+ return await response.json();
3312
3212
  };
3313
- function getDataFromPremintReceipt(receipt, chainId, blockExplorerUrl) {
3314
- const premintedLog = getPremintedLogFromReceipt(receipt);
3315
- return {
3316
- tokenId: premintedLog?.tokenId,
3317
- collectionAddres: premintedLog?.contractAddress,
3318
- premintedLog,
3319
- urls: makeUrls({
3320
- address: premintedLog?.contractAddress,
3321
- tokenId: premintedLog?.tokenId,
3322
- chainId,
3323
- blockExplorerUrl
3324
- })
3325
- };
3326
- }
3327
- function makePremintReturn({
3328
- premintConfig,
3329
- premintConfigVersion,
3330
- publicClient,
3331
- apiClient,
3332
- chainId,
3333
- ...collectionAndAddress
3334
- }) {
3335
- const { collection, collectionAddress } = collectionAndAddress;
3336
- const typedDataDefinition = (0, import_protocol_deployments4.premintTypedDataDefinition)({
3337
- verifyingContract: collectionAddress,
3338
- premintConfig,
3339
- premintConfigVersion,
3340
- chainId
3213
+ var post = async (url, data) => {
3214
+ const controller = new AbortController();
3215
+ const { signal } = controller;
3216
+ const timeout = 30 * 60 * 1e3;
3217
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
3218
+ const response = await fetch(url, {
3219
+ method: "POST",
3220
+ headers: {
3221
+ "content-type": "application/json",
3222
+ accept: "application/json"
3223
+ },
3224
+ body: JSON.stringify(data),
3225
+ signal
3341
3226
  });
3342
- const signAndSubmit = async ({
3343
- walletClient,
3344
- account,
3345
- checkSignature
3346
- }) => {
3347
- const { signature, signerAccount } = await signPremint({
3348
- account,
3349
- walletClient,
3350
- typedDataDefinition
3351
- });
3352
- await submit({
3353
- signature,
3354
- checkSignature,
3355
- account: signerAccount
3356
- });
3357
- return {
3227
+ clearTimeout(timeoutId);
3228
+ if (response.status !== 200) {
3229
+ let json;
3230
+ try {
3231
+ json = await response.json();
3232
+ } catch (e) {
3233
+ }
3234
+ throw new BadResponseError(
3235
+ `Bad response: ${response.status}`,
3236
+ response.status,
3237
+ json
3238
+ );
3239
+ }
3240
+ return await response.json();
3241
+ };
3242
+ var defaultShouldRetry = (err) => {
3243
+ return err instanceof BadResponseError && err.status >= 500;
3244
+ };
3245
+ var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
3246
+ return retriesGeneric({
3247
+ tryFn,
3248
+ maxTries,
3249
+ linearBackoffMS,
3250
+ shouldRetryOnError: shouldRetry
3251
+ });
3252
+ };
3253
+ var httpClient = {
3254
+ get,
3255
+ post,
3256
+ retries
3257
+ };
3258
+
3259
+ // src/premint/premint-api-client.ts
3260
+ var postSignature = async ({
3261
+ httpClient: { post: post2, retries: retries2 } = httpClient,
3262
+ ...data
3263
+ }) => retries2(
3264
+ () => post2(`${ZORA_API_BASE}premint/signature`, data)
3265
+ );
3266
+ var getNextUID = async ({
3267
+ chainId,
3268
+ collection_address,
3269
+ httpClient: { retries: retries2, get: get2 } = httpClient
3270
+ }) => retries2(
3271
+ () => get2(
3272
+ `${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
3273
+ )
3274
+ );
3275
+ var getSignature = async ({
3276
+ collectionAddress,
3277
+ uid,
3278
+ chainId,
3279
+ httpClient: { retries: retries2, get: get2 } = httpClient
3280
+ }) => {
3281
+ const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
3282
+ const result = await retries2(
3283
+ () => get2(
3284
+ `${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
3285
+ )
3286
+ );
3287
+ return convertGetPremintApiResponse(result);
3288
+ };
3289
+ var getOfCollection = async ({
3290
+ collectionAddress,
3291
+ chainId,
3292
+ httpClient: { retries: retries2, get: get2 } = httpClient
3293
+ }) => {
3294
+ const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
3295
+ const result = await retries2(
3296
+ () => get2(
3297
+ `${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
3298
+ )
3299
+ );
3300
+ return convertGetPremintOfCollectionApiResponse(result);
3301
+ };
3302
+ var PremintAPIClient = class {
3303
+ constructor(chainId, httpClient2) {
3304
+ this.postSignature = ({
3358
3305
  signature,
3359
- signerAccount
3306
+ ...rest
3307
+ }) => {
3308
+ const data = encodePostSignatureInput({
3309
+ ...rest,
3310
+ chainId: this.chainId,
3311
+ signature
3312
+ });
3313
+ return postSignature({
3314
+ ...data,
3315
+ httpClient: this.httpClient
3316
+ });
3360
3317
  };
3361
- };
3362
- const submit = async ({
3363
- signature,
3364
- checkSignature,
3365
- account
3366
- }) => {
3367
- if (checkSignature) {
3368
- const isAuthorized = await isAuthorizedToCreatePremint({
3318
+ this.getNextUID = async (collectionAddress) => (await getNextUID({
3319
+ collection_address: collectionAddress.toLowerCase(),
3320
+ chainId: this.chainId,
3321
+ httpClient: this.httpClient
3322
+ })).next_uid;
3323
+ this.get = async ({ collectionAddress, uid }) => {
3324
+ return getSignature({
3369
3325
  collectionAddress,
3370
- additionalAdmins: collection?.additionalAdmins,
3371
- contractAdmin: collection?.contractAdmin,
3372
- publicClient,
3373
- signer: account
3326
+ uid,
3327
+ chainId: this.chainId,
3328
+ httpClient: this.httpClient
3374
3329
  });
3375
- if (!isAuthorized) {
3376
- throw new Error("Not authorized to create premint");
3330
+ };
3331
+ this.getOfCollection = async ({
3332
+ collectionAddress
3333
+ }) => {
3334
+ return getOfCollection({
3335
+ collectionAddress,
3336
+ chainId: this.chainId,
3337
+ httpClient: this.httpClient
3338
+ });
3339
+ };
3340
+ this.chainId = chainId;
3341
+ this.httpClient = httpClient2 || httpClient;
3342
+ }
3343
+ };
3344
+
3345
+ // src/mint/subgraph-queries.ts
3346
+ var NFT_SALE_STRATEGY_FRAGMENT = `
3347
+ fragment SaleStrategy on SalesStrategyConfig {
3348
+ type
3349
+ fixedPrice {
3350
+ address
3351
+ pricePerToken
3352
+ saleEnd
3353
+ saleStart
3354
+ maxTokensPerAddress
3355
+ }
3356
+ erc20Minter {
3357
+ address
3358
+ pricePerToken
3359
+ currency
3360
+ saleEnd
3361
+ saleStart
3362
+ maxTokensPerAddress
3363
+ }
3364
+ presale {
3365
+ address
3366
+ presaleStart
3367
+ presaleEnd
3368
+ merkleRoot
3369
+ }
3370
+ zoraTimedMinter {
3371
+ address
3372
+ mintFee
3373
+ saleStart
3374
+ saleEnd
3375
+ erc20Z {
3376
+ id
3377
+ pool
3378
+ }
3379
+ secondaryActivated
3380
+ marketCountdown
3381
+ minimumMarketEth
3382
+ }
3383
+ }`;
3384
+ var TOKEN_FRAGMENT = `
3385
+ fragment Token on ZoraCreateToken {
3386
+ creator
3387
+ tokenId
3388
+ uri
3389
+ totalMinted
3390
+ maxSupply
3391
+ tokenStandard
3392
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
3393
+ ...SaleStrategy
3394
+ }
3395
+ contract {
3396
+ address
3397
+ mintFeePerQuantity
3398
+ contractVersion
3399
+ contractURI
3400
+ name
3401
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
3402
+ ...SaleStrategy
3377
3403
  }
3378
3404
  }
3379
- await apiClient.postSignature({
3380
- ...toContractCreationConfigOrAddress(collectionAndAddress),
3381
- signature,
3382
- premintConfig,
3383
- premintConfigVersion
3384
- });
3385
- };
3386
- const urls = makeUrls({
3387
- chainId,
3388
- address: collectionAddress,
3389
- uid: premintConfig.uid
3390
- });
3405
+ }`;
3406
+ var FRAGMENTS = `
3407
+ ${NFT_SALE_STRATEGY_FRAGMENT}
3408
+ ${TOKEN_FRAGMENT}
3409
+ `;
3410
+ function buildNftTokenSalesQuery({
3411
+ tokenId,
3412
+ tokenAddress
3413
+ }) {
3391
3414
  return {
3392
- premintConfig,
3393
- premintConfigVersion,
3394
- typedDataDefinition,
3395
- collectionAddress,
3396
- signAndSubmit,
3397
- submit,
3398
- urls
3415
+ query: `
3416
+ ${FRAGMENTS}
3417
+ query ($id: ID!) {
3418
+ zoraCreateToken(id: $id) {
3419
+ ...Token
3420
+ }
3421
+ }
3422
+ `,
3423
+ variables: {
3424
+ id: tokenId !== void 0 ? (
3425
+ // Generic Token ID types all stringify down to the base numeric equivalent.
3426
+ `${tokenAddress.toLowerCase()}-${tokenId}`
3427
+ ) : `${tokenAddress.toLowerCase()}-0`
3428
+ },
3429
+ parseResponseData: (responseData) => responseData?.zoraCreateToken
3399
3430
  };
3400
3431
  }
3401
- async function signPremint({
3402
- account,
3403
- walletClient,
3404
- typedDataDefinition
3432
+ function buildContractTokensQuery({
3433
+ tokenAddress
3405
3434
  }) {
3406
- if (!account) {
3407
- account = walletClient.account;
3408
- }
3409
- if (!account) {
3410
- throw new Error("No account provided");
3411
- }
3412
- const signature = await walletClient.signTypedData({
3413
- account,
3414
- ...typedDataDefinition
3415
- });
3416
3435
  return {
3417
- signature,
3418
- signerAccount: account
3436
+ query: `
3437
+ ${FRAGMENTS}
3438
+ query ($contract: Bytes!) {
3439
+ zoraCreateTokens(
3440
+ where: {address: $contract}
3441
+ ) {
3442
+ ...Token
3443
+ }
3444
+ }
3445
+ `,
3446
+ variables: {
3447
+ contract: tokenAddress.toLowerCase()
3448
+ },
3449
+ parseResponseData: (responseData) => responseData?.zoraCreateTokens
3419
3450
  };
3420
3451
  }
3421
- async function createPremint({
3422
- token: tokenCreationConfig,
3423
- uid,
3424
- publicClient,
3425
- apiClient,
3426
- chainId,
3427
- ...collectionOrAddress
3452
+ function buildPremintsOfContractQuery({
3453
+ tokenAddress
3428
3454
  }) {
3429
- const {
3430
- premintConfig,
3431
- premintConfigVersion,
3432
- collectionAddress: collectionAddressToUse
3433
- } = await prepareCreatePremintConfig({
3434
- ...collectionOrAddress,
3435
- tokenCreationConfig,
3436
- uid,
3437
- publicClient,
3438
- apiClient,
3439
- chainId
3440
- });
3441
- return makePremintReturn({
3442
- premintConfig,
3443
- premintConfigVersion,
3444
- collectionAddress: collectionAddressToUse,
3445
- collection: collectionOrAddress.contract,
3446
- publicClient,
3447
- apiClient,
3448
- chainId
3449
- });
3455
+ return {
3456
+ query: `
3457
+ query ($contractAddress: Bytes!) {
3458
+ premints(where:{contractAddress:$contractAddress}) {
3459
+ uid
3460
+ tokenId
3461
+ }
3462
+ }
3463
+ `,
3464
+ variables: {
3465
+ contractAddress: tokenAddress.toLowerCase()
3466
+ },
3467
+ parseResponseData: (responseData) => responseData?.premints
3468
+ };
3450
3469
  }
3451
- async function prepareCreatePremintConfig({
3452
- tokenCreationConfig,
3453
- uid,
3454
- publicClient,
3455
- apiClient,
3456
- chainId,
3457
- ...collectionOrAddress
3458
- }) {
3459
- const newContractAddress = await getPremintCollectionAddress({
3460
- publicClient,
3461
- ...collectionOrAddress
3462
- });
3463
- let uidToUse = uid;
3464
- if (typeof uidToUse !== "number") {
3465
- uidToUse = await apiClient.getNextUID(newContractAddress);
3470
+
3471
+ // src/apis/subgraph-querier.ts
3472
+ var SubgraphQuerier = class {
3473
+ constructor(httpClient2) {
3474
+ this.httpClient = httpClient2;
3466
3475
  }
3467
- const supportedVersions = await supportedPremintVersions({
3468
- tokenContract: newContractAddress,
3469
- publicClient
3470
- });
3471
- const tokenConfigAndVersion = makeTokenConfigWithDefaults({
3472
- tokenCreationConfig,
3473
- chainId,
3474
- supportedPremintVersions: supportedVersions
3475
- });
3476
- const premintConfig = makeNewPremint({
3477
- ...tokenConfigAndVersion,
3478
- uid: uidToUse
3479
- });
3480
- const premintConfigAndVersion = {
3481
- premintConfig,
3482
- premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
3476
+ async query({
3477
+ subgraphUrl,
3478
+ query,
3479
+ variables
3480
+ }) {
3481
+ const { retries: retries2, post: post2 } = this.httpClient;
3482
+ const result = await retries2(async () => {
3483
+ return await post2(subgraphUrl, {
3484
+ query,
3485
+ variables
3486
+ });
3487
+ });
3488
+ return result?.data;
3489
+ }
3490
+ };
3491
+
3492
+ // src/apis/subgraph-getter.ts
3493
+ var SubgraphGetter = class {
3494
+ constructor(chainId, subgraphQuerier) {
3495
+ this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
3496
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
3497
+ }
3498
+ async querySubgraphWithRetries({
3499
+ query,
3500
+ variables,
3501
+ parseResponseData
3502
+ }) {
3503
+ const responseData = await this.subgraphQuerier.query({
3504
+ subgraphUrl: this.networkConfig.subgraphUrl,
3505
+ query,
3506
+ variables
3507
+ });
3508
+ return parseResponseData(responseData);
3509
+ }
3510
+ };
3511
+
3512
+ // src/mint/strategies-parsing.ts
3513
+ function parseFixedPriceSalesConfig(fixedPrice, contractMintFee) {
3514
+ return {
3515
+ salesStrategy: {
3516
+ saleType: "fixedPrice",
3517
+ ...fixedPrice,
3518
+ maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
3519
+ pricePerToken: BigInt(fixedPrice.pricePerToken),
3520
+ mintFeePerQuantity: contractMintFee
3521
+ },
3522
+ saleEnd: BigInt(fixedPrice.saleEnd),
3523
+ saleStart: BigInt(fixedPrice.saleStart)
3524
+ // saleActive:
3525
+ // BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime,
3483
3526
  };
3527
+ }
3528
+ function parseERC20SalesConfig(erc20Minter) {
3484
3529
  return {
3485
- ...premintConfigAndVersion,
3486
- collectionAddress: newContractAddress
3530
+ salesStrategy: {
3531
+ saleType: "erc20",
3532
+ ...erc20Minter,
3533
+ maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
3534
+ pricePerToken: BigInt(erc20Minter.pricePerToken),
3535
+ mintFeePerQuantity: 0n
3536
+ },
3537
+ saleEnd: BigInt(erc20Minter.saleEnd),
3538
+ saleStart: BigInt(erc20Minter.saleStart)
3539
+ // saleActive:
3540
+ // BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime,
3487
3541
  };
3488
3542
  }
3489
- async function updatePremint({
3490
- uid,
3491
- collection,
3492
- tokenConfigUpdates,
3493
- apiClient,
3494
- publicClient,
3495
- chainId
3543
+ function parsePresaleSalesConfig(presale, contractMintFee) {
3544
+ return {
3545
+ salesStrategy: {
3546
+ saleType: "allowlist",
3547
+ address: presale.address,
3548
+ merkleRoot: presale.merkleRoot,
3549
+ saleStart: presale.presaleStart,
3550
+ saleEnd: presale.presaleEnd,
3551
+ mintFeePerQuantity: contractMintFee
3552
+ },
3553
+ saleEnd: BigInt(presale.presaleEnd),
3554
+ saleStart: BigInt(presale.presaleStart)
3555
+ // saleActive:
3556
+ // BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime,
3557
+ };
3558
+ }
3559
+ function parseZoraTimedSalesConfig(zoraTimedMinter) {
3560
+ const saleEnd = BigInt(zoraTimedMinter.saleEnd);
3561
+ return {
3562
+ salesStrategy: {
3563
+ saleType: "timed",
3564
+ address: zoraTimedMinter.address,
3565
+ mintFee: BigInt(zoraTimedMinter.mintFee),
3566
+ saleStart: zoraTimedMinter.saleStart,
3567
+ saleEnd: zoraTimedMinter.saleEnd,
3568
+ erc20Z: zoraTimedMinter.erc20Z.id,
3569
+ pool: zoraTimedMinter.erc20Z.pool,
3570
+ secondaryActivated: zoraTimedMinter.secondaryActivated,
3571
+ mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
3572
+ marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
3573
+ minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
3574
+ },
3575
+ saleEnd: saleEnd > 0n ? saleEnd : void 0,
3576
+ saleStart: BigInt(zoraTimedMinter.saleStart)
3577
+ // saleActive:
3578
+ // BigInt(zoraTimedMinter.saleStart) <= blockTime &&
3579
+ // (hasSaleEnd ? saleEnd > blockTime : true),
3580
+ };
3581
+ }
3582
+ function parseSalesConfig(targetStrategy, contractMintFee) {
3583
+ switch (targetStrategy.type) {
3584
+ case "FIXED_PRICE":
3585
+ return parseFixedPriceSalesConfig(
3586
+ targetStrategy.fixedPrice,
3587
+ contractMintFee
3588
+ // blockTime,
3589
+ );
3590
+ case "ERC_20_MINTER":
3591
+ return parseERC20SalesConfig(targetStrategy.erc20Minter);
3592
+ case "PRESALE":
3593
+ return parsePresaleSalesConfig(
3594
+ targetStrategy.presale,
3595
+ contractMintFee
3596
+ // blockTime,
3597
+ );
3598
+ case "ZORA_TIMED":
3599
+ return parseZoraTimedSalesConfig(
3600
+ targetStrategy.zoraTimedMinter
3601
+ // blockTime,
3602
+ );
3603
+ default:
3604
+ throw new Error("Unknown saleType");
3605
+ }
3606
+ }
3607
+ function isPrimaryMintActive(sale, blockTime) {
3608
+ if (sale.saleStart > blockTime)
3609
+ return false;
3610
+ if (!sale.saleEnd)
3611
+ return true;
3612
+ return sale.saleEnd > blockTime;
3613
+ }
3614
+ function isSecondaryMinter(result) {
3615
+ return result.saleType === "timed";
3616
+ }
3617
+ function isSecondaryMarketActive(sale) {
3618
+ const salesStrategy = sale.salesStrategy;
3619
+ if (isSecondaryMinter(salesStrategy)) {
3620
+ return salesStrategy.secondaryActivated;
3621
+ }
3622
+ return false;
3623
+ }
3624
+ function getTargetStrategy({
3625
+ preferredSaleType,
3626
+ blockTime,
3627
+ parsedStrategies
3496
3628
  }) {
3497
- const {
3498
- premint: { premintConfig, premintConfigVersion },
3499
- collection: collectionCreationConfig
3500
- } = await apiClient.get({
3501
- collectionAddress: collection,
3502
- uid
3503
- });
3504
- const updatedPremint = applyUpdateToPremint({
3505
- uid: premintConfig.uid,
3506
- version: premintConfig.version,
3507
- tokenConfig: premintConfig.tokenConfig,
3508
- tokenConfigUpdates
3509
- });
3510
- return makePremintReturn({
3511
- premintConfig: updatedPremint,
3512
- premintConfigVersion,
3513
- collectionAddress: collection,
3514
- collection: collectionCreationConfig,
3515
- publicClient,
3516
- apiClient,
3517
- chainId
3518
- });
3629
+ const withPrimaryAndSecondaryMintActive = parsedStrategies.map(
3630
+ (strategy) => ({
3631
+ strategy,
3632
+ primaryMintActive: isPrimaryMintActive(strategy, blockTime),
3633
+ secondaryMarketActive: isSecondaryMarketActive(strategy)
3634
+ })
3635
+ );
3636
+ const stillValidSalesStrategies = withPrimaryAndSecondaryMintActive.filter(
3637
+ ({ primaryMintActive, secondaryMarketActive }) => primaryMintActive || secondaryMarketActive
3638
+ );
3639
+ const saleStrategies = stillValidSalesStrategies.sort(
3640
+ (a, b) => (a.strategy.saleEnd ?? 0n) > (b.strategy.saleEnd ?? 0n) ? 1 : -1
3641
+ );
3642
+ let targetStrategy;
3643
+ if (!preferredSaleType) {
3644
+ return saleStrategies[0];
3645
+ } else {
3646
+ targetStrategy = saleStrategies.find(
3647
+ ({ strategy: { salesStrategy } }) => salesStrategy.saleType === preferredSaleType
3648
+ );
3649
+ if (!targetStrategy) {
3650
+ targetStrategy = saleStrategies.find(
3651
+ ({ strategy: { salesStrategy } }) => salesStrategy.saleType === "timed" || salesStrategy.saleType === "fixedPrice" || salesStrategy.saleType === "erc20"
3652
+ );
3653
+ if (!targetStrategy)
3654
+ throw new Error("Cannot find valid sale strategy");
3655
+ return targetStrategy;
3656
+ }
3657
+ }
3658
+ return targetStrategy;
3519
3659
  }
3520
- async function deletePremint({
3521
- uid,
3522
- collection,
3523
- publicClient,
3524
- apiClient,
3525
- chainId
3660
+ function findTargetStrategyWithPrimaryOrSecondarySaleActive({
3661
+ token,
3662
+ tokenId,
3663
+ preferredSaleType,
3664
+ defaultMintFee,
3665
+ blockTime
3526
3666
  }) {
3527
- const {
3528
- premint: { premintConfig, premintConfigVersion },
3529
- collection: collectionCreationConfig,
3530
- collectionAddress
3531
- } = await apiClient.get({
3532
- collectionAddress: collection,
3533
- uid
3534
- });
3535
- const deletedPremint = {
3536
- ...premintConfig,
3537
- version: premintConfig.version + 1,
3538
- deleted: true
3539
- };
3540
- return makePremintReturn({
3541
- premintConfig: deletedPremint,
3542
- premintConfigVersion,
3543
- collectionAddress,
3544
- collection: collectionCreationConfig,
3545
- publicClient,
3546
- apiClient,
3547
- chainId
3667
+ const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
3668
+ const parsedStrategies = allStrategies.map(
3669
+ (strategy) => parseSalesConfig(strategy, defaultMintFee)
3670
+ );
3671
+ const targetStrategy = getTargetStrategy({
3672
+ preferredSaleType,
3673
+ blockTime,
3674
+ parsedStrategies
3548
3675
  });
3676
+ return targetStrategy;
3549
3677
  }
3550
- async function collectPremint({
3551
- uid,
3552
- tokenContract,
3553
- minterAccount,
3554
- quantityToMint,
3555
- mintComment = "",
3556
- mintReferral,
3557
- mintRecipient,
3558
- firstMinter,
3559
- premintGetter,
3560
- publicClient
3678
+ function parseAndFilterTokenQueryResult({
3679
+ token,
3680
+ tokenId,
3681
+ preferredSaleType,
3682
+ blockTime
3561
3683
  }) {
3562
- if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
3563
- throw new Error("Quantity to mint cannot be below 1");
3564
- }
3565
- const premint = await premintGetter.get({
3566
- collectionAddress: tokenContract,
3567
- uid
3684
+ const defaultMintFee = BigInt(token.contract.mintFeePerQuantity);
3685
+ const salesStrategyAndMintInfo = findTargetStrategyWithPrimaryOrSecondarySaleActive({
3686
+ token,
3687
+ tokenId,
3688
+ preferredSaleType,
3689
+ defaultMintFee,
3690
+ blockTime
3568
3691
  });
3569
- const mintFee = await getPremintMintFee({
3570
- tokenContract,
3571
- publicClient
3692
+ const tokenInfo = parseTokenInfo({
3693
+ token
3572
3694
  });
3573
- return buildPremintMintCall({
3574
- mintArguments: {
3575
- minterAccount,
3576
- quantityToMint,
3577
- firstMinter,
3578
- mintComment,
3579
- mintRecipient,
3580
- mintReferral
3695
+ return {
3696
+ salesConfigAndTokenInfo: {
3697
+ ...tokenInfo,
3698
+ salesConfig: salesStrategyAndMintInfo?.strategy.salesStrategy
3581
3699
  },
3582
- mintFee,
3583
- premint
3584
- });
3585
- }
3586
- var buildPremintMintCall = ({
3587
- mintArguments: {
3588
- minterAccount,
3589
- mintComment = "",
3590
- mintRecipient,
3591
- mintReferral,
3592
- firstMinter,
3593
- quantityToMint
3594
- },
3595
- premint: { collection, collectionAddress, premint, signature },
3596
- mintFee
3597
- }) => {
3598
- const mintArgumentsContract = {
3599
- mintComment,
3600
- mintRecipient: mintRecipientOrAccount({
3601
- mintRecipient,
3602
- minterAccount
3603
- }),
3604
- mintRewardsRecipients: makeMintRewardsRecipient({
3605
- mintReferral
3606
- })
3700
+ primaryMintActive: salesStrategyAndMintInfo?.primaryMintActive ?? false,
3701
+ primaryMintEnd: salesStrategyAndMintInfo?.strategy.saleEnd,
3702
+ secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
3607
3703
  };
3608
- const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
3609
- const collectionAddressToSubmit = collection ? import_viem4.zeroAddress : collectionAddress;
3610
- const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
3611
- if (premint.premintConfigVersion === import_protocol_deployments4.PremintConfigVersion.V3) {
3612
- throw new Error("PremintV3 not supported in premint SDK");
3613
- }
3614
- const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
3615
- return makeContractParameters({
3616
- account: minterAccount,
3617
- abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
3618
- functionName: "premint",
3619
- value,
3620
- address: getPremintExecutorAddress(),
3621
- args: [
3622
- collectionOrEmpty,
3623
- collectionAddressToSubmit,
3624
- (0, import_protocol_deployments3.encodePremintConfig)(premint),
3625
- signature,
3626
- BigInt(quantityToMint),
3627
- mintArgumentsContract,
3628
- firstMinterToSubmit,
3629
- import_viem4.zeroAddress
3630
- ]
3631
- });
3632
- };
3633
- function makeUrls({
3634
- uid,
3635
- address,
3636
- tokenId,
3637
- chainId,
3638
- blockExplorerUrl
3704
+ }
3705
+ function parseTokenInfo({
3706
+ token
3639
3707
  }) {
3640
- if ((!uid || !tokenId) && !address) {
3641
- return { explorer: null, zoraCollect: null, zoraManage: null };
3642
- }
3643
- const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
3644
- const network = getApiNetworkConfigForChain(chainId);
3645
3708
  return {
3646
- explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
3647
- zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
3648
- zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
3709
+ contract: {
3710
+ address: token.contract.address,
3711
+ name: token.contract.name,
3712
+ URI: token.contract.contractURI
3713
+ },
3714
+ tokenURI: token.uri,
3715
+ tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
3716
+ mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
3717
+ creator: token.creator,
3718
+ totalMinted: BigInt(token.totalMinted),
3719
+ maxSupply: BigInt(token.maxSupply),
3720
+ contractVersion: token.contract.contractVersion
3649
3721
  };
3650
3722
  }
3651
3723
 
3652
- // src/premint/contract-types.ts
3653
- var import_protocol_deployments5 = require("@zoralabs/protocol-deployments");
3654
- var PremintConfigVersion3 = ((PremintConfigVersion4) => {
3655
- PremintConfigVersion4[PremintConfigVersion4["V1"] = import_protocol_deployments5.PremintConfigVersion.V1] = "V1";
3656
- PremintConfigVersion4[PremintConfigVersion4["V2"] = import_protocol_deployments5.PremintConfigVersion.V2] = "V2";
3657
- PremintConfigVersion4[PremintConfigVersion4["V3"] = import_protocol_deployments5.PremintConfigVersion.V3] = "V3";
3658
- return PremintConfigVersion4;
3659
- })(PremintConfigVersion3 || {});
3660
-
3661
- // src/premint/premint-api-client.ts
3662
- var postSignature = async ({
3663
- httpClient: { post: post2, retries: retries2 } = httpClient,
3664
- ...data
3665
- }) => retries2(
3666
- () => post2(`${ZORA_API_BASE}premint/signature`, data)
3667
- );
3668
- var getNextUID = async ({
3669
- chainId,
3670
- collection_address,
3671
- httpClient: { retries: retries2, get: get2 } = httpClient
3672
- }) => retries2(
3673
- () => get2(
3674
- `${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
3675
- )
3676
- );
3677
- var getSignature = async ({
3678
- collectionAddress,
3679
- uid,
3680
- chainId,
3681
- httpClient: { retries: retries2, get: get2 } = httpClient
3682
- }) => {
3683
- const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
3684
- const result = await retries2(
3685
- () => get2(
3686
- `${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
3687
- )
3688
- );
3689
- return convertGetPremintApiResponse(result);
3690
- };
3691
- var getOfCollection = async ({
3692
- collectionAddress,
3693
- chainId,
3694
- httpClient: { retries: retries2, get: get2 } = httpClient
3695
- }) => {
3696
- const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
3697
- const result = await retries2(
3698
- () => get2(
3699
- `${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
3700
- )
3701
- );
3702
- return convertGetPremintOfCollectionApiResponse(result);
3703
- };
3704
- var PremintAPIClient = class {
3705
- constructor(chainId, httpClient2) {
3706
- this.postSignature = ({
3707
- signature,
3708
- ...rest
3709
- }) => {
3710
- const data = encodePostSignatureInput({
3711
- ...rest,
3712
- chainId: this.chainId,
3713
- signature
3714
- });
3715
- return postSignature({
3716
- ...data,
3717
- httpClient: this.httpClient
3718
- });
3719
- };
3720
- this.getNextUID = async (collectionAddress) => (await getNextUID({
3721
- collection_address: collectionAddress.toLowerCase(),
3722
- chainId: this.chainId,
3723
- httpClient: this.httpClient
3724
- })).next_uid;
3725
- this.get = async ({ collectionAddress, uid }) => {
3726
- return getSignature({
3727
- collectionAddress,
3728
- uid,
3729
- chainId: this.chainId,
3730
- httpClient: this.httpClient
3731
- });
3732
- };
3733
- this.getOfCollection = async ({
3734
- collectionAddress
3724
+ // src/mint/subgraph-mint-getter.ts
3725
+ var SubgraphMintGetter = class extends SubgraphGetter {
3726
+ constructor(chainId, subgraphQuerier) {
3727
+ super(chainId, subgraphQuerier);
3728
+ this.getMintable = async ({
3729
+ tokenAddress,
3730
+ tokenId
3735
3731
  }) => {
3736
- return getOfCollection({
3737
- collectionAddress,
3738
- chainId: this.chainId,
3739
- httpClient: this.httpClient
3740
- });
3732
+ const token = await this.querySubgraphWithRetries(
3733
+ buildNftTokenSalesQuery({
3734
+ tokenId,
3735
+ tokenAddress
3736
+ })
3737
+ );
3738
+ if (!token) {
3739
+ throw new Error("Cannot find token");
3740
+ }
3741
+ return token;
3741
3742
  };
3742
- this.chainId = chainId;
3743
- this.httpClient = httpClient2 || httpClient;
3743
+ }
3744
+ async getContractMintable({
3745
+ tokenAddress,
3746
+ preferredSaleType,
3747
+ blockTime
3748
+ }) {
3749
+ const tokens = await this.querySubgraphWithRetries(
3750
+ buildContractTokensQuery({
3751
+ tokenAddress
3752
+ })
3753
+ );
3754
+ if (!tokens || tokens.length === 0)
3755
+ return [];
3756
+ return tokens.filter((x) => x.tokenId !== "0").map(
3757
+ (token) => parseAndFilterTokenQueryResult({
3758
+ token,
3759
+ tokenId: token.tokenId,
3760
+ preferredSaleType,
3761
+ blockTime
3762
+ })
3763
+ );
3764
+ }
3765
+ async getContractPremintTokenIds({
3766
+ tokenAddress
3767
+ }) {
3768
+ const premints = await this.querySubgraphWithRetries(
3769
+ buildPremintsOfContractQuery({
3770
+ tokenAddress
3771
+ })
3772
+ );
3773
+ return premints?.map((premint) => ({
3774
+ tokenId: BigInt(premint.tokenId),
3775
+ uid: +premint.uid
3776
+ })) || [];
3744
3777
  }
3745
3778
  };
3746
3779
 
@@ -4035,32 +4068,33 @@ function parseMintCosts({
4035
4068
  }
4036
4069
 
4037
4070
  // src/mint/mint-queries.ts
4038
- async function getMint({
4039
- params,
4040
- mintGetter,
4041
- premintGetter,
4042
- publicClient,
4043
- chainId
4044
- }) {
4045
- const { tokenContract } = params;
4071
+ async function getToken(params) {
4072
+ const { premintGetter, publicClient } = params;
4073
+ const chainId = publicClient.chain.id;
4046
4074
  if (isOnChainMint(params)) {
4047
4075
  const tokenId = is1155Mint(params) ? params.tokenId : void 0;
4048
4076
  const blockTime = (await publicClient.getBlock()).timestamp;
4049
- const result = await mintGetter.getMintable({
4077
+ const mintGetterOrDefault = params.mintGetter ?? new SubgraphMintGetter(chainId);
4078
+ const result = await mintGetterOrDefault.getMintable({
4079
+ tokenId,
4080
+ tokenAddress: params.tokenContract
4081
+ });
4082
+ const token = parseAndFilterTokenQueryResult({
4083
+ token: result,
4050
4084
  tokenId,
4051
- tokenAddress: tokenContract,
4052
4085
  preferredSaleType: params.preferredSaleType,
4053
4086
  blockTime
4054
4087
  });
4055
- return toMintableReturn(result, chainId);
4088
+ return toMintableReturn(token, chainId);
4056
4089
  }
4057
- const premint = await premintGetter.get({
4058
- collectionAddress: tokenContract,
4090
+ const premintGetterOrDefault = premintGetter ?? new PremintAPIClient(chainId);
4091
+ const premint = await premintGetterOrDefault.get({
4092
+ collectionAddress: params.tokenContract,
4059
4093
  uid: params.uid
4060
4094
  });
4061
4095
  const mintFee = await getPremintMintFee({
4062
4096
  publicClient,
4063
- tokenContract
4097
+ tokenContract: params.tokenContract
4064
4098
  });
4065
4099
  return toPremintMintReturn({ premint, mintFee });
4066
4100
  }
@@ -4086,19 +4120,20 @@ async function getPremintsOfCollectionWithTokenIds({
4086
4120
  premints: premintsWithTokenId
4087
4121
  };
4088
4122
  }
4089
- async function getMintsOfContract({
4090
- params,
4123
+ async function getTokensOfContract({
4091
4124
  mintGetter,
4092
4125
  premintGetter,
4093
4126
  publicClient,
4094
- chainId
4127
+ ...params
4095
4128
  }) {
4096
- const onchainMints = (await mintGetter.getContractMintable({
4129
+ const chainId = publicClient.chain.id;
4130
+ const mintGetterOrDefault = mintGetter ?? new SubgraphMintGetter(chainId);
4131
+ const onchainMints = (await mintGetterOrDefault.getContractMintable({
4097
4132
  tokenAddress: params.tokenContract
4098
4133
  })).map((result) => toMintableReturn(result, chainId));
4099
4134
  const offchainMints = await getPremintsOfContractMintable({
4100
- mintGetter,
4101
- premintGetter,
4135
+ mintGetter: mintGetterOrDefault,
4136
+ premintGetter: premintGetter ?? new PremintAPIClient(chainId),
4102
4137
  publicClient,
4103
4138
  params: {
4104
4139
  tokenContract: params.tokenContract
@@ -4121,16 +4156,20 @@ async function getMintCosts({
4121
4156
  if (isOnChainMint(params)) {
4122
4157
  const tokenId = is1155Mint(params) ? params.tokenId : void 0;
4123
4158
  const blockTime = (await publicClient.getBlock()).timestamp;
4124
- const { salesConfigAndTokenInfo } = await mintGetter.getMintable({
4159
+ const result = await mintGetter.getMintable({
4160
+ tokenId,
4161
+ tokenAddress: collection
4162
+ });
4163
+ const token = parseAndFilterTokenQueryResult({
4164
+ token: result,
4125
4165
  tokenId,
4126
- tokenAddress: collection,
4127
4166
  blockTime
4128
4167
  });
4129
- if (!salesConfigAndTokenInfo.salesConfig) {
4168
+ if (!token.salesConfigAndTokenInfo.salesConfig) {
4130
4169
  throw new Error("No valid sales config found for token");
4131
4170
  }
4132
4171
  return parseMintCosts({
4133
- salesConfig: salesConfigAndTokenInfo.salesConfig,
4172
+ salesConfig: token.salesConfigAndTokenInfo.salesConfig,
4134
4173
  quantityToMint: BigInt(quantityToMint),
4135
4174
  allowListEntry
4136
4175
  });
@@ -4180,7 +4219,7 @@ async function getPremintsOfContractMintable({
4180
4219
  });
4181
4220
  });
4182
4221
  }
4183
- function isPrimaryMintActive(premint) {
4222
+ function isPrimaryMintActive2(premint) {
4184
4223
  const currentTime = (/* @__PURE__ */ new Date()).getTime() / 1e3;
4185
4224
  return premint.premintConfig.tokenConfig.mintStart < currentTime;
4186
4225
  }
@@ -4273,7 +4312,7 @@ function toPremintMintReturn({
4273
4312
  mintFee
4274
4313
  }) {
4275
4314
  const mintable = parsePremint({ premint, mintFee });
4276
- const primaryMintActive = isPrimaryMintActive(premint.premint);
4315
+ const primaryMintActive = isPrimaryMintActive2(premint.premint);
4277
4316
  if (!primaryMintActive) {
4278
4317
  return {
4279
4318
  token: mintable,
@@ -4312,13 +4351,11 @@ var MintClient = class {
4312
4351
  constructor({
4313
4352
  publicClient,
4314
4353
  premintGetter,
4315
- mintGetter,
4316
- chainId
4354
+ mintGetter
4317
4355
  }) {
4318
4356
  this.publicClient = publicClient;
4319
4357
  this.mintGetter = mintGetter;
4320
4358
  this.premintGetter = premintGetter;
4321
- this.chainId = chainId;
4322
4359
  }
4323
4360
  /**
4324
4361
  * Returns the parameters needed to prepare a transaction mint a token.
@@ -4329,26 +4366,24 @@ var MintClient = class {
4329
4366
  */
4330
4367
  async mint(parameters) {
4331
4368
  return mint({
4332
- parameters,
4369
+ ...parameters,
4333
4370
  publicClient: this.publicClient,
4334
4371
  mintGetter: this.mintGetter,
4335
- premintGetter: this.premintGetter,
4336
- chainId: this.chainId
4372
+ premintGetter: this.premintGetter
4337
4373
  });
4338
4374
  }
4339
4375
  /**
4340
4376
  * Gets an 1155, 721, or premint, and returns both information about it, and a function
4341
4377
  * that can be used to build a mint transaction for a quantity of items to mint.
4342
- * @param parameters - Token to get {@link GetMintParameters}
4378
+ * @param parameters - Token to get {@link GetMintParametersArguments}
4343
4379
  * @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
4344
4380
  */
4345
4381
  async get(parameters) {
4346
- return getMint({
4347
- params: parameters,
4382
+ return getToken({
4383
+ ...parameters,
4348
4384
  mintGetter: this.mintGetter,
4349
4385
  premintGetter: this.premintGetter,
4350
- publicClient: this.publicClient,
4351
- chainId: this.chainId
4386
+ publicClient: this.publicClient
4352
4387
  });
4353
4388
  }
4354
4389
  /**
@@ -4358,17 +4393,16 @@ var MintClient = class {
4358
4393
  * @Returns Array of tokens, each containing information about the token and a function to build a mint transaction.
4359
4394
  */
4360
4395
  async getOfContract(params) {
4361
- return getMintsOfContract({
4362
- params,
4396
+ return getTokensOfContract({
4397
+ ...params,
4363
4398
  mintGetter: this.mintGetter,
4364
4399
  premintGetter: this.premintGetter,
4365
- publicClient: this.publicClient,
4366
- chainId: this.chainId
4400
+ publicClient: this.publicClient
4367
4401
  });
4368
4402
  }
4369
4403
  /**
4370
4404
  * Gets the costs to mint the quantity of tokens specified for a mint.
4371
- * @param parameters - Parameters for the mint {@link GetMintCostsParameters}
4405
+ * @param parameters - Parameters for the mint {@link GetMintCostsParameterArguments}
4372
4406
  * @returns Costs to mint the quantity of tokens specified
4373
4407
  */
4374
4408
  async getMintCosts(parameters) {
@@ -4381,18 +4415,16 @@ var MintClient = class {
4381
4415
  }
4382
4416
  };
4383
4417
  async function mint({
4384
- parameters,
4385
4418
  publicClient,
4386
4419
  mintGetter,
4387
4420
  premintGetter,
4388
- chainId
4421
+ ...parameters
4389
4422
  }) {
4390
- const { prepareMint, primaryMintActive } = await getMint({
4391
- params: parameters,
4423
+ const { prepareMint, primaryMintActive } = await getToken({
4424
+ ...parameters,
4392
4425
  mintGetter,
4393
4426
  premintGetter,
4394
- publicClient,
4395
- chainId
4427
+ publicClient
4396
4428
  });
4397
4429
  if (!primaryMintActive) {
4398
4430
  throw new Error("Primary mint is not active");
@@ -4407,7 +4439,7 @@ async function mint({
4407
4439
  });
4408
4440
  }
4409
4441
 
4410
- // src/create/1155-create-helper.ts
4442
+ // src/create/create-client.ts
4411
4443
  var import_protocol_deployments10 = require("@zoralabs/protocol-deployments");
4412
4444
  var import_viem11 = require("viem");
4413
4445
 
@@ -4424,9 +4456,9 @@ async function getDeterministicContractAddress({
4424
4456
  publicClient,
4425
4457
  account,
4426
4458
  setupActions,
4427
- contract,
4428
- chainId
4459
+ contract
4429
4460
  }) {
4461
+ const chainId = publicClient.chain.id;
4430
4462
  const contractAddress = await publicClient.readContract({
4431
4463
  abi: import_protocol_deployments7.zoraCreator1155FactoryImplABI,
4432
4464
  address: import_protocol_deployments7.zoraCreator1155FactoryImplAddress[chainId],
@@ -4946,27 +4978,85 @@ function makeOnchainPrepareMintFromCreate({
4946
4978
  salesConfig: result
4947
4979
  });
4948
4980
  return {
4949
- parameters: makePrepareMint1155TokenParams({
4950
- salesConfigAndTokenInfo: {
4951
- salesConfig: subgraphSalesConfig,
4952
- contractVersion
4953
- },
4954
- ...params,
4955
- tokenContract: contractAddress,
4956
- tokenId,
4957
- chainId
4958
- }),
4959
- costs: parseMintCosts({
4960
- allowListEntry: params.allowListEntry,
4961
- quantityToMint: BigInt(params.quantityToMint),
4962
- salesConfig: subgraphSalesConfig
4963
- }),
4964
- erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
4981
+ parameters: makePrepareMint1155TokenParams({
4982
+ salesConfigAndTokenInfo: {
4983
+ salesConfig: subgraphSalesConfig,
4984
+ contractVersion
4985
+ },
4986
+ ...params,
4987
+ tokenContract: contractAddress,
4988
+ tokenId,
4989
+ chainId
4990
+ }),
4991
+ costs: parseMintCosts({
4992
+ allowListEntry: params.allowListEntry,
4993
+ quantityToMint: BigInt(params.quantityToMint),
4994
+ salesConfig: subgraphSalesConfig
4995
+ }),
4996
+ erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
4997
+ };
4998
+ };
4999
+ }
5000
+
5001
+ // src/create/subgraph-queries.ts
5002
+ function buildContractInfoQuery({
5003
+ contractAddress
5004
+ }) {
5005
+ return {
5006
+ query: `
5007
+ query ($contractAddress: Bytes!) {
5008
+ zoraCreateContract(id: $contractAddress) {
5009
+ contractVersion
5010
+ name
5011
+ mintFeePerQuantity
5012
+ tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
5013
+ tokenId
5014
+ }
5015
+ }
5016
+ }
5017
+ `,
5018
+ variables: {
5019
+ contractAddress: contractAddress.toLowerCase()
5020
+ },
5021
+ parseResponseData: (responseData) => responseData.zoraCreateContract
5022
+ };
5023
+ }
5024
+
5025
+ // src/create/contract-getter.ts
5026
+ var SubgraphContractGetter = class extends SubgraphGetter {
5027
+ constructor(chainId, subgraphQuerier) {
5028
+ super(chainId, subgraphQuerier);
5029
+ }
5030
+ async getContractInfo({
5031
+ contractAddress,
5032
+ retries: retries2 = 1
5033
+ }) {
5034
+ const tryFn = async () => {
5035
+ const responseData2 = await this.querySubgraphWithRetries(
5036
+ buildContractInfoQuery({ contractAddress })
5037
+ );
5038
+ if (!responseData2) {
5039
+ console.log("could not find contract");
5040
+ throw new Error("Cannot find contract");
5041
+ }
5042
+ return responseData2;
5043
+ };
5044
+ const responseData = await retriesGeneric({
5045
+ tryFn,
5046
+ maxTries: retries2,
5047
+ linearBackoffMS: 1e3
5048
+ });
5049
+ const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
5050
+ return {
5051
+ name: responseData.name,
5052
+ contractVersion: responseData.contractVersion,
5053
+ mintFee: BigInt(responseData.mintFeePerQuantity),
5054
+ nextTokenId
4965
5055
  };
4966
- };
4967
- }
5056
+ }
5057
+ };
4968
5058
 
4969
- // src/create/1155-create-helper.ts
5059
+ // src/create/create-client.ts
4970
5060
  var ROYALTY_BPS_DEFAULT = 1e3;
4971
5061
  var getTokenIdFromCreateReceipt = (receipt) => {
4972
5062
  for (const data of receipt.logs) {
@@ -5047,19 +5137,16 @@ function makeCreateTokenCall({
5047
5137
  }
5048
5138
  var Create1155Client = class {
5049
5139
  constructor({
5050
- chainId,
5051
5140
  publicClient,
5052
5141
  contractGetter
5053
5142
  }) {
5054
- this.chainId = chainId;
5055
5143
  this.publicClient = publicClient;
5056
5144
  this.contractGetter = contractGetter;
5057
5145
  }
5058
5146
  async createNew1155(props) {
5059
- return createNew1155ContractAndToken({
5147
+ return create1155({
5060
5148
  ...props,
5061
- publicClient: this.publicClient,
5062
- chainId: this.chainId
5149
+ publicClient: this.publicClient
5063
5150
  });
5064
5151
  }
5065
5152
  async createNew1155OnExistingContract({
@@ -5073,83 +5160,100 @@ var Create1155Client = class {
5073
5160
  account,
5074
5161
  token,
5075
5162
  getAdditionalSetupActions,
5076
- publicClient: this.publicClient,
5077
- chainId: this.chainId,
5078
- contractGetter: this.contractGetter
5163
+ contractGetter: this.contractGetter,
5164
+ chainId: this.publicClient.chain.id
5079
5165
  });
5080
5166
  }
5081
5167
  };
5082
- async function createNew1155ContractAndToken({
5168
+ async function create1155({
5083
5169
  contract,
5084
5170
  account,
5085
- chainId,
5086
5171
  token,
5087
5172
  publicClient,
5088
5173
  getAdditionalSetupActions
5089
5174
  }) {
5090
5175
  const nextTokenId = 1n;
5176
+ const chainId = publicClient.chain.id;
5091
5177
  const contractVersion = new1155ContractVersion(chainId);
5092
- const {
5093
- minter,
5094
- newToken,
5095
- setupActions: tokenSetupActions
5096
- } = prepareSetupActions({
5097
- chainId,
5098
- account,
5099
- contractVersion,
5100
- nextTokenId,
5101
- token,
5102
- getAdditionalSetupActions,
5103
- contractName: contract.name
5104
- });
5105
- const request = makeCreateContractAndTokenCall({
5178
+ const result = prepareNew1155ContractAndToken({
5106
5179
  contract,
5107
5180
  account,
5108
5181
  chainId,
5109
- tokenSetupActions,
5110
- fundsRecipient: token.payoutRecipient,
5111
- royaltyBPS: token.royaltyBPS
5182
+ token,
5183
+ getAdditionalSetupActions,
5184
+ nextTokenId,
5185
+ contractVersion
5112
5186
  });
5113
5187
  const contractAddress = await getDeterministicContractAddress({
5114
5188
  account: typeof account === "string" ? account : account.address,
5115
5189
  publicClient,
5116
- setupActions: tokenSetupActions,
5117
- chainId,
5190
+ setupActions: result.setupActions,
5118
5191
  contract
5119
5192
  });
5120
5193
  const prepareMint = makeOnchainPrepareMintFromCreate({
5121
5194
  contractAddress,
5122
5195
  contractVersion,
5123
- minter,
5124
- result: newToken.salesConfig,
5196
+ minter: result.minter,
5197
+ result: result.newToken.salesConfig,
5125
5198
  tokenId: nextTokenId,
5199
+ chainId,
5126
5200
  // to get the contract wide mint fee, we get what it would be for a new contract
5127
5201
  getContractMintFee: async () => getNewContractMintFee({
5128
5202
  publicClient,
5129
5203
  chainId
5130
- }),
5131
- chainId
5204
+ })
5132
5205
  });
5133
5206
  return {
5134
- parameters: request,
5135
- tokenSetupActions,
5136
- newTokenId: nextTokenId,
5137
- newToken,
5207
+ ...result,
5208
+ prepareMint,
5138
5209
  contractAddress,
5139
5210
  contractVersion,
5140
- minter,
5141
- prepareMint
5211
+ newTokenId: nextTokenId
5142
5212
  };
5143
5213
  }
5144
- async function createNew1155Token({
5214
+ function prepareNew1155ContractAndToken({
5215
+ account,
5216
+ chainId,
5217
+ token,
5218
+ getAdditionalSetupActions,
5219
+ nextTokenId,
5220
+ contractVersion,
5221
+ contract
5222
+ }) {
5223
+ const { minter, newToken, setupActions } = prepareSetupActions({
5224
+ chainId,
5225
+ account,
5226
+ contractVersion,
5227
+ nextTokenId,
5228
+ token,
5229
+ getAdditionalSetupActions,
5230
+ contractName: contract.name
5231
+ });
5232
+ const request = makeCreateContractAndTokenCall({
5233
+ contract,
5234
+ account,
5235
+ chainId,
5236
+ tokenSetupActions: setupActions,
5237
+ fundsRecipient: token.payoutRecipient,
5238
+ royaltyBPS: token.royaltyBPS
5239
+ });
5240
+ return {
5241
+ parameters: request,
5242
+ setupActions,
5243
+ newToken,
5244
+ minter
5245
+ };
5246
+ }
5247
+ function prepareNew1155Token({
5145
5248
  contractAddress,
5146
5249
  account,
5147
5250
  getAdditionalSetupActions,
5148
5251
  token,
5149
5252
  chainId,
5150
- contractGetter
5253
+ nextTokenId,
5254
+ contractVersion,
5255
+ contractName
5151
5256
  }) {
5152
- const { nextTokenId, contractVersion, mintFee, name } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
5153
5257
  const {
5154
5258
  minter,
5155
5259
  newToken,
@@ -5161,30 +5265,57 @@ async function createNew1155Token({
5161
5265
  nextTokenId,
5162
5266
  token,
5163
5267
  getAdditionalSetupActions,
5164
- contractName: name
5268
+ contractName
5165
5269
  });
5166
5270
  const request = makeCreateTokenCall({
5167
5271
  contractAddress,
5168
5272
  account,
5169
5273
  tokenSetupActions
5170
5274
  });
5275
+ return {
5276
+ parameters: request,
5277
+ setupActions: tokenSetupActions,
5278
+ newToken,
5279
+ minter
5280
+ };
5281
+ }
5282
+ async function createNew1155Token({
5283
+ contractAddress,
5284
+ account,
5285
+ getAdditionalSetupActions,
5286
+ token,
5287
+ chainId,
5288
+ contractGetter
5289
+ }) {
5290
+ const contractGetterOrDefault = contractGetter ?? new SubgraphContractGetter(chainId);
5291
+ const { nextTokenId, contractVersion, mintFee, name } = await contractGetterOrDefault.getContractInfo({
5292
+ contractAddress,
5293
+ retries: 5
5294
+ });
5295
+ const preparedToken = prepareNew1155Token({
5296
+ contractAddress,
5297
+ account,
5298
+ getAdditionalSetupActions,
5299
+ token,
5300
+ chainId,
5301
+ nextTokenId,
5302
+ contractVersion,
5303
+ contractName: name
5304
+ });
5171
5305
  const prepareMint = makeOnchainPrepareMintFromCreate({
5172
5306
  contractAddress,
5173
5307
  contractVersion,
5174
- minter,
5175
- result: newToken.salesConfig,
5308
+ minter: preparedToken.minter,
5309
+ result: preparedToken.newToken.salesConfig,
5176
5310
  tokenId: nextTokenId,
5177
5311
  getContractMintFee: async () => mintFee,
5178
5312
  chainId
5179
5313
  });
5180
5314
  return {
5181
- parameters: request,
5182
- tokenSetupActions,
5315
+ ...preparedToken,
5316
+ prepareMint,
5183
5317
  newTokenId: nextTokenId,
5184
- newToken,
5185
- contractVersion,
5186
- minter,
5187
- prepareMint
5318
+ contractVersion
5188
5319
  };
5189
5320
  }
5190
5321
  function prepareSetupActions({
@@ -5448,119 +5579,61 @@ var makePermitToCollectPremintOrNonPremint = ({
5448
5579
  deadline,
5449
5580
  tokenIds,
5450
5581
  // this quantity of MINTs will be used to collect premint
5451
- // and will be burned. This same quantity is the quantity of
5452
- // premint to collect.
5453
- quantities,
5454
- nonce,
5455
- premint,
5456
- collect
5457
- }) => {
5458
- let safeTransferData;
5459
- if (premint) {
5460
- safeTransferData = encodePremintOnManager(premint);
5461
- } else if (collect) {
5462
- safeTransferData = encodeCollectOnManager(collect);
5463
- } else {
5464
- throw new Error("Invalid operation");
5465
- }
5466
- return makePermitTransferBatchAndTypeData({
5467
- tokenIds,
5468
- quantities,
5469
- chainId,
5470
- mintsOwner,
5471
- nonce,
5472
- deadline,
5473
- safeTransferData,
5474
- to: import_protocol_deployments11.zoraMintsManagerImplConfig.address[chainId]
5475
- });
5476
- };
5477
- function collectPremintV2WithMintsParams({
5478
- tokenIds,
5479
- quantities,
5480
- paidMintPricePerToken,
5481
- account,
5482
- chainId,
5483
- ...rest
5484
- }) {
5485
- const call = encodePremintOnManager({
5486
- ...rest
5487
- });
5488
- return makeContractParameters({
5489
- abi: import_protocol_deployments11.zoraMints1155Config.abi,
5490
- address: import_protocol_deployments11.zoraMints1155Config.address[chainId],
5491
- functionName: "transferBatchToManagerAndCall",
5492
- args: [tokenIds, quantities, call],
5493
- value: getPaidMintValue(quantities, paidMintPricePerToken),
5494
- account
5495
- });
5496
- }
5497
- function decodeCallFailedError(error) {
5498
- if (error.data?.errorName !== "CallFailed")
5499
- throw new Error("Not a CallFailed error");
5500
- const internalErrorData = error.data?.args?.[0];
5501
- return (0, import_viem12.decodeErrorResult)({
5502
- abi: import_protocol_deployments11.zoraMintsManagerImplABI,
5503
- data: internalErrorData
5504
- });
5505
- }
5506
-
5507
- // src/create/subgraph-queries.ts
5508
- function buildContractInfoQuery({
5509
- contractAddress
5510
- }) {
5511
- return {
5512
- query: `
5513
- query ($contractAddress: Bytes!) {
5514
- zoraCreateContract(id: $contractAddress) {
5515
- contractVersion
5516
- name
5517
- mintFeePerQuantity
5518
- tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
5519
- tokenId
5520
- }
5521
- }
5522
- }
5523
- `,
5524
- variables: {
5525
- contractAddress: contractAddress.toLowerCase()
5526
- },
5527
- parseResponseData: (responseData) => responseData.zoraCreateContract
5528
- };
5529
- }
5530
-
5531
- // src/create/contract-getter.ts
5532
- var SubgraphContractGetter = class extends SubgraphGetter {
5533
- constructor(chainId, subgraphQuerier) {
5534
- super(chainId, subgraphQuerier);
5535
- }
5536
- async getContractInfo({
5537
- contractAddress,
5538
- retries: retries2 = 1
5539
- }) {
5540
- const tryFn = async () => {
5541
- const responseData2 = await this.querySubgraphWithRetries(
5542
- buildContractInfoQuery({ contractAddress })
5543
- );
5544
- if (!responseData2) {
5545
- console.log("could not find contract");
5546
- throw new Error("Cannot find contract");
5547
- }
5548
- return responseData2;
5549
- };
5550
- const responseData = await retriesGeneric({
5551
- tryFn,
5552
- maxTries: retries2,
5553
- linearBackoffMS: 1e3
5554
- });
5555
- const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
5556
- return {
5557
- name: responseData.name,
5558
- contractVersion: responseData.contractVersion,
5559
- mintFee: BigInt(responseData.mintFeePerQuantity),
5560
- nextTokenId
5561
- };
5582
+ // and will be burned. This same quantity is the quantity of
5583
+ // premint to collect.
5584
+ quantities,
5585
+ nonce,
5586
+ premint,
5587
+ collect
5588
+ }) => {
5589
+ let safeTransferData;
5590
+ if (premint) {
5591
+ safeTransferData = encodePremintOnManager(premint);
5592
+ } else if (collect) {
5593
+ safeTransferData = encodeCollectOnManager(collect);
5594
+ } else {
5595
+ throw new Error("Invalid operation");
5562
5596
  }
5597
+ return makePermitTransferBatchAndTypeData({
5598
+ tokenIds,
5599
+ quantities,
5600
+ chainId,
5601
+ mintsOwner,
5602
+ nonce,
5603
+ deadline,
5604
+ safeTransferData,
5605
+ to: import_protocol_deployments11.zoraMintsManagerImplConfig.address[chainId]
5606
+ });
5563
5607
  };
5608
+ function collectPremintV2WithMintsParams({
5609
+ tokenIds,
5610
+ quantities,
5611
+ paidMintPricePerToken,
5612
+ account,
5613
+ chainId,
5614
+ ...rest
5615
+ }) {
5616
+ const call = encodePremintOnManager({
5617
+ ...rest
5618
+ });
5619
+ return makeContractParameters({
5620
+ abi: import_protocol_deployments11.zoraMints1155Config.abi,
5621
+ address: import_protocol_deployments11.zoraMints1155Config.address[chainId],
5622
+ functionName: "transferBatchToManagerAndCall",
5623
+ args: [tokenIds, quantities, call],
5624
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
5625
+ account
5626
+ });
5627
+ }
5628
+ function decodeCallFailedError(error) {
5629
+ if (error.data?.errorName !== "CallFailed")
5630
+ throw new Error("Not a CallFailed error");
5631
+ const internalErrorData = error.data?.args?.[0];
5632
+ return (0, import_viem12.decodeErrorResult)({
5633
+ abi: import_protocol_deployments11.zoraMintsManagerImplABI,
5634
+ data: internalErrorData
5635
+ });
5636
+ }
5564
5637
 
5565
5638
  // src/rewards/rewards-queries.ts
5566
5639
  var import_protocol_deployments12 = require("@zoralabs/protocol-deployments");
@@ -5578,6 +5651,56 @@ var multicall3Abi = [
5578
5651
  ];
5579
5652
  var multicall3Address = "0xcA11bde05977b3631167028862bE2a173976CA11";
5580
5653
 
5654
+ // src/rewards/subgraph-queries.ts
5655
+ function buildCreatorERC20zs({
5656
+ address
5657
+ }) {
5658
+ return {
5659
+ query: `
5660
+ query ($address: Bytes!) {
5661
+ zoraCreateTokens(
5662
+ where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
5663
+ ) {
5664
+ royalties {
5665
+ user
5666
+ }
5667
+ salesStrategies {
5668
+ zoraTimedMinter {
5669
+ erc20Z {
5670
+ id
5671
+ }
5672
+ }
5673
+ }
5674
+ }
5675
+ }
5676
+ `,
5677
+ variables: { address },
5678
+ parseResponseData: (responseData) => {
5679
+ return responseData?.zoraCreateTokens;
5680
+ }
5681
+ };
5682
+ }
5683
+
5684
+ // src/rewards/subgraph-rewards-getter.ts
5685
+ var SubgraphRewardsGetter = class extends SubgraphGetter {
5686
+ constructor(chainId, subgraphQuerier) {
5687
+ super(chainId, subgraphQuerier);
5688
+ }
5689
+ async getErc20ZzForCreator({ address }) {
5690
+ const queryResults = await this.querySubgraphWithRetries(
5691
+ buildCreatorERC20zs({ address })
5692
+ );
5693
+ const results = (queryResults?.map((result) => {
5694
+ const timedMinter = result.salesStrategies[0].zoraTimedMinter;
5695
+ if (!timedMinter) {
5696
+ return null;
5697
+ }
5698
+ return timedMinter.erc20Z.id;
5699
+ }) || []).filter((id) => !!id);
5700
+ return results;
5701
+ }
5702
+ };
5703
+
5581
5704
  // src/rewards/rewards-queries.ts
5582
5705
  function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
5583
5706
  let ethBalance = 0n;
@@ -5604,21 +5727,47 @@ function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
5604
5727
  erc20: unclaimedFeesAggregate
5605
5728
  };
5606
5729
  }
5607
- var getRewardsBalance = async ({
5730
+ var getErc20zsWithPositions = async ({
5731
+ address,
5732
+ publicClient,
5733
+ rewardsGetter
5734
+ }) => {
5735
+ const chainId = publicClient.chain.id;
5736
+ const rewardsGetterOrDefault = rewardsGetter ?? new SubgraphRewardsGetter(chainId);
5737
+ const erc20zsForCreator = await rewardsGetterOrDefault.getErc20ZzForCreator({
5738
+ address
5739
+ });
5740
+ const royaltiesAddress = import_protocol_deployments12.erc20ZRoyaltiesAddress[chainId];
5741
+ const positionsByErc20z = await publicClient.multicall({
5742
+ contracts: erc20zsForCreator.map((erc20z) => ({
5743
+ address: royaltiesAddress,
5744
+ abi: import_protocol_deployments12.erc20ZRoyaltiesABI,
5745
+ functionName: "positionsByErc20z",
5746
+ args: [erc20z]
5747
+ })),
5748
+ multicallAddress: multicall3Address,
5749
+ allowFailure: false
5750
+ });
5751
+ const erc20zsWithPositions = erc20zsForCreator.filter(
5752
+ (_, i) => positionsByErc20z[i] !== 0n
5753
+ );
5754
+ return erc20zsWithPositions;
5755
+ };
5756
+ var getRewardsBalances = async ({
5608
5757
  account,
5609
5758
  // The account to check rewards for (Address or Account object)
5610
5759
  publicClient,
5611
5760
  // The public client for making blockchain queries
5612
- chainId,
5613
- // The ID of the blockchain network
5614
5761
  rewardsGetter
5615
5762
  // Interface for getting ERC20Z tokens for a creator
5616
5763
  }) => {
5764
+ const chainId = publicClient.chain.id;
5617
5765
  const address = typeof account === "string" ? account : account.address;
5618
- const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
5619
- { address }
5620
- );
5621
- const validErc20Zs = erc20ZsAndSecondaryActivated.filter(({ secondaryActivated }) => secondaryActivated).map(({ erc20z }) => erc20z);
5766
+ const erc20zsWithPositions = await getErc20zsWithPositions({
5767
+ address,
5768
+ publicClient,
5769
+ rewardsGetter
5770
+ });
5622
5771
  const result = await publicClient.multicall({
5623
5772
  contracts: [
5624
5773
  {
@@ -5631,7 +5780,7 @@ var getRewardsBalance = async ({
5631
5780
  address: import_protocol_deployments12.erc20ZRoyaltiesAddress[chainId],
5632
5781
  abi: import_protocol_deployments12.erc20ZRoyaltiesABI,
5633
5782
  functionName: "getUnclaimedFeesBatch",
5634
- args: [validErc20Zs]
5783
+ args: [erc20zsWithPositions]
5635
5784
  }
5636
5785
  ],
5637
5786
  multicallAddress: multicall3Address,
@@ -5662,12 +5811,14 @@ var withdrawProtocolRewards = ({
5662
5811
  var makeClaimSecondaryRoyaltiesCalls = async ({
5663
5812
  claimFor,
5664
5813
  chainId,
5665
- rewardsGetter
5814
+ rewardsGetter,
5815
+ publicClient
5666
5816
  }) => {
5667
- const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
5668
- { address: claimFor }
5669
- );
5670
- const erc20z = erc20ZsAndSecondaryActivated.filter(({ secondaryActivated }) => secondaryActivated).map(({ erc20z: erc20z2 }) => erc20z2);
5817
+ const erc20z = await getErc20zsWithPositions({
5818
+ address: claimFor,
5819
+ publicClient,
5820
+ rewardsGetter
5821
+ });
5671
5822
  const royaltiesAddress = import_protocol_deployments12.erc20ZRoyaltiesAddress[chainId];
5672
5823
  if (erc20z.length === 0) {
5673
5824
  return [];
@@ -5698,37 +5849,57 @@ var createMulticallParameters = (calls, account) => makeContractParameters({
5698
5849
  args: [calls],
5699
5850
  account
5700
5851
  });
5701
- var withdrawRewards = async ({
5702
- account,
5703
- withdrawFor,
5704
- claimSecondaryRoyalties = true,
5852
+ var handleProtocolRewardsOnly = ({
5705
5853
  chainId,
5706
- rewardsGetter
5854
+ withdrawFor,
5855
+ account
5856
+ }) => ({
5857
+ ...withdrawProtocolRewards({ chainId, withdrawFor }),
5858
+ account
5859
+ });
5860
+ var handleAllRewards = async ({
5861
+ withdrawFor,
5862
+ account,
5863
+ rewardsGetter,
5864
+ publicClient
5707
5865
  }) => {
5708
- if (!claimSecondaryRoyalties) {
5709
- return {
5710
- ...withdrawProtocolRewards({ chainId, withdrawFor }),
5711
- account
5712
- };
5713
- }
5866
+ const chainId = publicClient.chain.id;
5714
5867
  const protocolRewardsCall = createProtocolRewardsCall(chainId, withdrawFor);
5715
5868
  const secondaryRoyaltiesCalls = await makeClaimSecondaryRoyaltiesCalls({
5716
5869
  chainId,
5717
5870
  claimFor: withdrawFor,
5718
- rewardsGetter
5871
+ rewardsGetter,
5872
+ publicClient
5719
5873
  });
5720
5874
  const allCalls = [protocolRewardsCall, ...secondaryRoyaltiesCalls];
5721
5875
  return createMulticallParameters(allCalls, account);
5722
5876
  };
5877
+ var withdrawRewards = async ({
5878
+ account,
5879
+ withdrawFor,
5880
+ claimSecondaryRoyalties = true,
5881
+ rewardsGetter,
5882
+ publicClient
5883
+ }) => {
5884
+ const parameters = claimSecondaryRoyalties ? await handleAllRewards({
5885
+ withdrawFor,
5886
+ account,
5887
+ rewardsGetter,
5888
+ publicClient
5889
+ }) : await handleProtocolRewardsOnly({
5890
+ chainId: publicClient.chain.id,
5891
+ withdrawFor,
5892
+ account
5893
+ });
5894
+ return { parameters };
5895
+ };
5723
5896
 
5724
5897
  // src/rewards/rewards-client.ts
5725
5898
  var RewardsClient = class {
5726
5899
  constructor({
5727
- chainId,
5728
5900
  publicClient,
5729
5901
  rewardsGetter
5730
5902
  }) {
5731
- this.chainId = chainId;
5732
5903
  this.publicClient = publicClient;
5733
5904
  this.rewardsGetter = rewardsGetter;
5734
5905
  }
@@ -5738,83 +5909,24 @@ var RewardsClient = class {
5738
5909
  withdrawFor,
5739
5910
  claimSecondaryRoyalties
5740
5911
  }) {
5741
- return {
5742
- parameters: await withdrawRewards({
5743
- chainId: this.chainId,
5744
- rewardsGetter: this.rewardsGetter,
5745
- withdrawFor,
5746
- claimSecondaryRoyalties,
5747
- account
5748
- })
5749
- };
5912
+ return await withdrawRewards({
5913
+ rewardsGetter: this.rewardsGetter,
5914
+ withdrawFor,
5915
+ claimSecondaryRoyalties,
5916
+ account,
5917
+ publicClient: this.publicClient
5918
+ });
5750
5919
  }
5751
5920
  /** Retrieves the rewards balances for a given account */
5752
5921
  async getRewardsBalances(params) {
5753
- return getRewardsBalance({
5922
+ return getRewardsBalances({
5754
5923
  account: params.account,
5755
- chainId: this.chainId,
5756
5924
  publicClient: this.publicClient,
5757
5925
  rewardsGetter: this.rewardsGetter
5758
5926
  });
5759
5927
  }
5760
5928
  };
5761
5929
 
5762
- // src/rewards/subgraph-queries.ts
5763
- function buildCreatorERC20zs({
5764
- address
5765
- }) {
5766
- return {
5767
- query: `
5768
- query ($address: Bytes!) {
5769
- zoraCreateTokens(
5770
- where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
5771
- ) {
5772
- royalties {
5773
- user
5774
- }
5775
- salesStrategies {
5776
- zoraTimedMinter {
5777
- secondaryActivated
5778
- erc20Z {
5779
- id
5780
- }
5781
- }
5782
- }
5783
- }
5784
- }
5785
- `,
5786
- variables: { address },
5787
- parseResponseData: (responseData) => {
5788
- return responseData?.zoraCreateTokens;
5789
- }
5790
- };
5791
- }
5792
-
5793
- // src/rewards/subgraph-rewards-getter.ts
5794
- var SubgraphRewardsGetter = class extends SubgraphGetter {
5795
- constructor(chainId, subgraphQuerier) {
5796
- super(chainId, subgraphQuerier);
5797
- }
5798
- async getErc20ZzForCreator({ address }) {
5799
- const queryResults = await this.querySubgraphWithRetries(
5800
- buildCreatorERC20zs({ address })
5801
- );
5802
- const results = (queryResults?.map((result) => {
5803
- const timedMinter = result.salesStrategies[0].zoraTimedMinter;
5804
- if (!timedMinter) {
5805
- return null;
5806
- }
5807
- return {
5808
- secondaryActivated: timedMinter.secondaryActivated,
5809
- erc20z: timedMinter.erc20Z.id
5810
- };
5811
- }) || []).filter(
5812
- (idAndActivated) => !!idAndActivated
5813
- );
5814
- return results;
5815
- }
5816
- };
5817
-
5818
5930
  // src/secondary/secondary-client.ts
5819
5931
  var import_viem19 = require("viem");
5820
5932
  var import_protocol_deployments15 = require("@zoralabs/protocol-deployments");
@@ -5986,7 +6098,8 @@ async function getPoolInfo({
5986
6098
  };
5987
6099
  }
5988
6100
  async function getUniswapQuote(input, client) {
5989
- const { type, quantity, poolAddress, chainId, erc20z } = input;
6101
+ const { type, quantity, poolAddress, erc20z } = input;
6102
+ const chainId = client.chain.id;
5990
6103
  const WETH = import_protocol_deployments13.wethAddress[chainId];
5991
6104
  const pool = await getPoolInfo({ poolAddress, WETH, erc20z, client });
5992
6105
  const { fee, wethBalance, erc20zBalance } = pool;
@@ -6054,10 +6167,10 @@ var MARKET_REWARD = (0, import_viem18.parseEther)("0.0000222");
6054
6167
  async function getSecondaryInfo({
6055
6168
  contract,
6056
6169
  tokenId,
6057
- publicClient,
6058
- chainId
6170
+ publicClient
6059
6171
  }) {
6060
6172
  let result;
6173
+ const chainId = publicClient.chain.id;
6061
6174
  try {
6062
6175
  result = await publicClient.readContract({
6063
6176
  abi: import_protocol_deployments14.zoraTimedSaleStrategyABI,
@@ -6109,7 +6222,6 @@ async function makeBuy({
6109
6222
  quantity,
6110
6223
  account,
6111
6224
  recipient,
6112
- chainId,
6113
6225
  slippage,
6114
6226
  publicClient,
6115
6227
  comment
@@ -6130,7 +6242,7 @@ async function makeBuy({
6130
6242
  return handleBuyWithComment({
6131
6243
  accountAddress,
6132
6244
  recipient,
6133
- chainId,
6245
+ chainId: publicClient.chain.id,
6134
6246
  quantity,
6135
6247
  contract,
6136
6248
  tokenId,
@@ -6145,7 +6257,7 @@ async function makeBuy({
6145
6257
  recipient,
6146
6258
  accountAddress,
6147
6259
  costWithSlippage,
6148
- chainId,
6260
+ chainId: publicClient.chain.id,
6149
6261
  account
6150
6262
  });
6151
6263
  }
@@ -6229,12 +6341,11 @@ function handleBuyWithoutComment({
6229
6341
  })
6230
6342
  };
6231
6343
  }
6232
- async function buyWithSlippage({
6344
+ async function buy1155OnSecondary({
6233
6345
  contract,
6234
6346
  tokenId,
6235
6347
  publicClient,
6236
6348
  quantity,
6237
- chainId,
6238
6349
  account,
6239
6350
  slippage = UNISWAP_SLIPPAGE,
6240
6351
  recipient,
@@ -6243,8 +6354,7 @@ async function buyWithSlippage({
6243
6354
  const secondaryInfo = await getSecondaryInfo({
6244
6355
  contract,
6245
6356
  tokenId,
6246
- publicClient,
6247
- chainId
6357
+ publicClient
6248
6358
  });
6249
6359
  if (!secondaryInfo) {
6250
6360
  return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
@@ -6258,8 +6368,7 @@ async function buyWithSlippage({
6258
6368
  type: "buy",
6259
6369
  quantity,
6260
6370
  poolAddress: pool,
6261
- erc20z,
6262
- chainId
6371
+ erc20z
6263
6372
  },
6264
6373
  publicClient
6265
6374
  );
@@ -6272,7 +6381,6 @@ async function buyWithSlippage({
6272
6381
  quantity,
6273
6382
  account,
6274
6383
  recipient,
6275
- chainId,
6276
6384
  slippage,
6277
6385
  comment,
6278
6386
  publicClient
@@ -6290,7 +6398,6 @@ async function makeSell({
6290
6398
  quantity,
6291
6399
  account,
6292
6400
  recipient,
6293
- chainId,
6294
6401
  slippage,
6295
6402
  publicClient
6296
6403
  }) {
@@ -6315,6 +6422,7 @@ async function makeSell({
6315
6422
  receivedWithSlippage,
6316
6423
  0n
6317
6424
  ]);
6425
+ const chainId = publicClient.chain.id;
6318
6426
  return {
6319
6427
  parameters: makeContractParameters({
6320
6428
  abi: import_protocol_deployments15.zoraCreator1155ImplABI,
@@ -6331,12 +6439,11 @@ async function makeSell({
6331
6439
  })
6332
6440
  };
6333
6441
  }
6334
- async function sellWithSlippage({
6442
+ async function sell1155OnSecondary({
6335
6443
  contract,
6336
6444
  tokenId,
6337
6445
  publicClient,
6338
6446
  quantity,
6339
- chainId,
6340
6447
  account,
6341
6448
  slippage = UNISWAP_SLIPPAGE,
6342
6449
  recipient
@@ -6344,8 +6451,7 @@ async function sellWithSlippage({
6344
6451
  const secondaryInfo = await getSecondaryInfo({
6345
6452
  contract,
6346
6453
  tokenId,
6347
- publicClient,
6348
- chainId
6454
+ publicClient
6349
6455
  });
6350
6456
  if (!secondaryInfo) {
6351
6457
  return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
@@ -6355,7 +6461,7 @@ async function sellWithSlippage({
6355
6461
  return makeError(ERROR_SECONDARY_NOT_STARTED);
6356
6462
  }
6357
6463
  const { poolBalance, amount, price } = await getUniswapQuote(
6358
- { type: "sell", quantity, poolAddress: pool, chainId, erc20z },
6464
+ { type: "sell", quantity, poolAddress: pool, erc20z },
6359
6465
  publicClient
6360
6466
  );
6361
6467
  const call = await makeSell({
@@ -6366,7 +6472,6 @@ async function sellWithSlippage({
6366
6472
  quantity,
6367
6473
  account,
6368
6474
  recipient,
6369
- chainId,
6370
6475
  slippage,
6371
6476
  publicClient
6372
6477
  });
@@ -6381,12 +6486,8 @@ var SecondaryClient = class {
6381
6486
  * @param publicClient - The public client for interacting with the blockchain.
6382
6487
  * @param chainId - The ID of the blockchain network.
6383
6488
  */
6384
- constructor({
6385
- publicClient,
6386
- chainId
6387
- }) {
6489
+ constructor({ publicClient }) {
6388
6490
  this.publicClient = publicClient;
6389
- this.chainId = chainId;
6390
6491
  }
6391
6492
  /**
6392
6493
  * Get the secondary info for a given contract and token ID.
@@ -6401,8 +6502,7 @@ var SecondaryClient = class {
6401
6502
  return getSecondaryInfo({
6402
6503
  contract,
6403
6504
  tokenId,
6404
- publicClient: this.publicClient,
6405
- chainId: this.chainId
6505
+ publicClient: this.publicClient
6406
6506
  });
6407
6507
  }
6408
6508
  /**
@@ -6411,10 +6511,9 @@ var SecondaryClient = class {
6411
6511
  * @returns A promise that resolves to the result of the buy operation, including price breakdown and transaction parameters.
6412
6512
  */
6413
6513
  async buy1155OnSecondary(input) {
6414
- return buyWithSlippage({
6514
+ return buy1155OnSecondary({
6415
6515
  ...input,
6416
- publicClient: this.publicClient,
6417
- chainId: this.chainId
6516
+ publicClient: this.publicClient
6418
6517
  });
6419
6518
  }
6420
6519
  /**
@@ -6423,10 +6522,9 @@ var SecondaryClient = class {
6423
6522
  * @returns A promise that resolves to the result of the sell operation, including price breakdown and transaction parameters.
6424
6523
  */
6425
6524
  async sell1155OnSecondary(input) {
6426
- return sellWithSlippage({
6525
+ return sell1155OnSecondary({
6427
6526
  ...input,
6428
- publicClient: this.publicClient,
6429
- chainId: this.chainId
6527
+ publicClient: this.publicClient
6430
6528
  });
6431
6529
  }
6432
6530
  };
@@ -6439,12 +6537,10 @@ function createCreatorClient(clientConfig) {
6439
6537
  premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
6440
6538
  });
6441
6539
  const create1155CreatorClient = new Create1155Client({
6442
- chainId: clientConfig.chainId,
6443
6540
  publicClient: clientConfig.publicClient,
6444
6541
  contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
6445
6542
  });
6446
6543
  const rewardsClient = new RewardsClient({
6447
- chainId: clientConfig.chainId,
6448
6544
  publicClient: clientConfig.publicClient,
6449
6545
  rewardsGetter: clientConfig.rewardsGetter || new SubgraphRewardsGetter(clientConfig.chainId)
6450
6546
  });
@@ -6464,12 +6560,10 @@ function createCollectorClient(params) {
6464
6560
  const mintClient = new MintClient({
6465
6561
  publicClient: params.publicClient,
6466
6562
  premintGetter: premintGetterToUse,
6467
- mintGetter: mintGetterToUse,
6468
- chainId: params.chainId
6563
+ mintGetter: mintGetterToUse
6469
6564
  });
6470
6565
  const secondaryClient = new SecondaryClient({
6471
- publicClient: params.publicClient,
6472
- chainId: params.chainId
6566
+ publicClient: params.publicClient
6473
6567
  });
6474
6568
  return {
6475
6569
  getPremint: (p) => premintGetterToUse.get({
@@ -6492,7 +6586,7 @@ function isArweaveURL(url) {
6492
6586
  return url && typeof url === "string" ? url.startsWith("ar://") : false;
6493
6587
  }
6494
6588
 
6495
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
6589
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bytes.js
6496
6590
  var empty = new Uint8Array(0);
6497
6591
  function equals(aa, bb) {
6498
6592
  if (aa === bb)
@@ -6518,7 +6612,7 @@ function coerce3(o) {
6518
6612
  throw new Error("Unknown type, must be binary type");
6519
6613
  }
6520
6614
 
6521
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
6615
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/vendor/base-x.js
6522
6616
  function base3(ALPHABET, name) {
6523
6617
  if (ALPHABET.length >= 255) {
6524
6618
  throw new TypeError("Alphabet too long");
@@ -6654,7 +6748,7 @@ var src = base3;
6654
6748
  var _brrp__multiformats_scope_baseX = src;
6655
6749
  var base_x_default = _brrp__multiformats_scope_baseX;
6656
6750
 
6657
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
6751
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base.js
6658
6752
  var Encoder = class {
6659
6753
  constructor(name, prefix, baseEncode) {
6660
6754
  __publicField(this, "name");
@@ -6680,10 +6774,11 @@ var Decoder = class {
6680
6774
  __publicField(this, "prefixCodePoint");
6681
6775
  this.name = name;
6682
6776
  this.prefix = prefix;
6683
- if (prefix.codePointAt(0) === void 0) {
6777
+ const prefixCodePoint = prefix.codePointAt(0);
6778
+ if (prefixCodePoint === void 0) {
6684
6779
  throw new Error("Invalid prefix character");
6685
6780
  }
6686
- this.prefixCodePoint = prefix.codePointAt(0);
6781
+ this.prefixCodePoint = prefixCodePoint;
6687
6782
  this.baseDecode = baseDecode;
6688
6783
  }
6689
6784
  decode(text) {
@@ -6825,7 +6920,7 @@ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
6825
6920
  });
6826
6921
  }
6827
6922
 
6828
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
6923
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base32.js
6829
6924
  var base32 = rfc4648({
6830
6925
  prefix: "b",
6831
6926
  name: "base32",
@@ -6881,7 +6976,19 @@ var base32z = rfc4648({
6881
6976
  bitsPerChar: 5
6882
6977
  });
6883
6978
 
6884
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
6979
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base36.js
6980
+ var base36 = baseX({
6981
+ prefix: "k",
6982
+ name: "base36",
6983
+ alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
6984
+ });
6985
+ var base36upper = baseX({
6986
+ prefix: "K",
6987
+ name: "base36upper",
6988
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6989
+ });
6990
+
6991
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base58.js
6885
6992
  var base58btc = baseX({
6886
6993
  name: "base58btc",
6887
6994
  prefix: "z",
@@ -6893,7 +7000,7 @@ var base58flickr = baseX({
6893
7000
  alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
6894
7001
  });
6895
7002
 
6896
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
7003
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/vendor/varint.js
6897
7004
  var encode_1 = encode2;
6898
7005
  var MSB = 128;
6899
7006
  var REST = 127;
@@ -6952,7 +7059,7 @@ var varint = {
6952
7059
  var _brrp_varint = varint;
6953
7060
  var varint_default = _brrp_varint;
6954
7061
 
6955
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
7062
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/varint.js
6956
7063
  function decode3(data, offset = 0) {
6957
7064
  const code = varint_default.decode(data, offset);
6958
7065
  return [code, varint_default.decode.bytes];
@@ -6965,7 +7072,7 @@ function encodingLength(int) {
6965
7072
  return varint_default.encodingLength(int);
6966
7073
  }
6967
7074
 
6968
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
7075
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/hashes/digest.js
6969
7076
  function create(code, digest) {
6970
7077
  const size = digest.byteLength;
6971
7078
  const sizeOffset = encodingLength(code);
@@ -7010,7 +7117,7 @@ var Digest = class {
7010
7117
  }
7011
7118
  };
7012
7119
 
7013
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
7120
+ // ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/cid.js
7014
7121
  function format(link, base4) {
7015
7122
  const { bytes, version } = link;
7016
7123
  switch (version) {
@@ -7296,9 +7403,13 @@ function parseCIDtoBytes(source, base4) {
7296
7403
  const decoder = base4 ?? base32;
7297
7404
  return [base32.prefix, decoder.decode(source)];
7298
7405
  }
7406
+ case base36.prefix: {
7407
+ const decoder = base4 ?? base36;
7408
+ return [base36.prefix, decoder.decode(source)];
7409
+ }
7299
7410
  default: {
7300
7411
  if (base4 == null) {
7301
- throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
7412
+ throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
7302
7413
  }
7303
7414
  return [source[0], base4.decode(source)];
7304
7415
  }
@@ -7714,10 +7825,12 @@ var createAllowList = async ({
7714
7825
  PremintAPIClient,
7715
7826
  PremintClient,
7716
7827
  PremintConfigVersion,
7828
+ SubgraphContractGetter,
7717
7829
  SubgraphMintGetter,
7718
7830
  ZORA_API_BASE,
7719
7831
  applyUpdateToPremint,
7720
7832
  buildPremintMintCall,
7833
+ buy1155OnSecondary,
7721
7834
  collectPremint,
7722
7835
  collectPremintV2WithMintsParams,
7723
7836
  collectWithMintsParams,
@@ -7725,9 +7838,11 @@ var createAllowList = async ({
7725
7838
  convertGetPremintApiResponse,
7726
7839
  convertGetPremintOfCollectionApiResponse,
7727
7840
  convertPremintFromApi,
7841
+ create1155,
7728
7842
  createAllowList,
7729
7843
  createCollectorClient,
7730
7844
  createCreatorClient,
7845
+ createNew1155Token,
7731
7846
  decodeCallFailedError,
7732
7847
  defaultAdditionalAdmins,
7733
7848
  defaultTokenConfigV1MintArguments,
@@ -7736,8 +7851,8 @@ var createAllowList = async ({
7736
7851
  encodeCollectOnManager,
7737
7852
  encodePostSignatureInput,
7738
7853
  encodePremintForAPI,
7854
+ findTargetStrategyWithPrimaryOrSecondarySaleActive,
7739
7855
  generateTextNftMetadataFiles,
7740
- getApiNetworkConfigForChain,
7741
7856
  getContractAddressFromReceipt,
7742
7857
  getDataFromPremintReceipt,
7743
7858
  getDefaultFixedPriceMinterAddress,
@@ -7750,31 +7865,46 @@ var createAllowList = async ({
7750
7865
  getPremintMintFee,
7751
7866
  getPremintPricePerToken,
7752
7867
  getPremintedLogFromReceipt,
7868
+ getRewardsBalances,
7869
+ getSecondaryInfo,
7753
7870
  getSignature,
7871
+ getToken,
7754
7872
  getTokenIdFromCreateReceipt,
7873
+ getTokensOfContract,
7874
+ is1155Mint,
7755
7875
  isAuthorizedToCreatePremint,
7876
+ isOnChainMint,
7756
7877
  isPremintConfigV1,
7757
7878
  isPremintConfigV2,
7758
7879
  isValidSignature,
7759
7880
  makeCreateContractAndTokenCall,
7881
+ makeCreateTokenCall,
7760
7882
  makeMediaTokenMetadata,
7761
7883
  makeMintRewardsRecipient,
7762
7884
  makeNewPremint,
7885
+ makeOnchainPrepareMintFromCreate,
7763
7886
  makePermitToCollectPremintOrNonPremint,
7764
7887
  makePermitTransferBatchAndTypeData,
7765
7888
  makePermitTransferTypeData,
7766
7889
  makeTextTokenMetadata,
7767
7890
  makeUrls,
7768
7891
  migratePremintConfigToV2,
7892
+ mint,
7769
7893
  mintWithEthParams,
7770
7894
  mintsBalanceOfAccountParams,
7895
+ new1155ContractVersion,
7896
+ parseAndFilterTokenQueryResult,
7897
+ prepareSetupActions,
7771
7898
  recoverCreatorFromCreatorAttribution,
7772
7899
  recoverPremintSigner,
7773
7900
  selectMintsToCollectWithFromQueryResult,
7901
+ sell1155OnSecondary,
7774
7902
  sumBalances,
7775
7903
  supportedPremintVersions,
7776
7904
  supportsPremintVersion,
7777
7905
  toContractCreationConfigOrAddress,
7778
- tryRecoverPremintSigner
7906
+ toMintableReturn,
7907
+ tryRecoverPremintSigner,
7908
+ withdrawRewards
7779
7909
  });
7780
7910
  //# sourceMappingURL=index.cjs.map