@zoralabs/protocol-sdk 0.5.7 → 0.5.8-DEV.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.
package/dist/index.js CHANGED
@@ -486,6 +486,13 @@ var networkConfigByChain = {
486
486
  subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
487
487
  }
488
488
  };
489
+ var getSubgraphUrl = (chainId) => {
490
+ const networkConfig = networkConfigByChain[chainId];
491
+ if (!networkConfig) {
492
+ throw new Error(`Network not configured for chain id ${chainId}`);
493
+ }
494
+ return networkConfig.subgraphUrl;
495
+ };
489
496
 
490
497
  // src/mint/mint-api-client.ts
491
498
  var getApiNetworkConfigForChain = (chainId) => {
@@ -1558,7 +1565,7 @@ function create1155CreatorClient({
1558
1565
  throw new Error("Invariant: contract cannot be missing and an address");
1559
1566
  }
1560
1567
  if (!contractExists && typeof contract !== "string") {
1561
- const request = {
1568
+ const request2 = {
1562
1569
  abi: zoraCreator1155FactoryImplABI,
1563
1570
  functionName: "createContractDeterministic",
1564
1571
  account,
@@ -1577,13 +1584,13 @@ function create1155CreatorClient({
1577
1584
  ]
1578
1585
  };
1579
1586
  return {
1580
- request,
1587
+ request: request2,
1581
1588
  tokenSetupActions,
1582
1589
  contractAddress,
1583
1590
  contractExists
1584
1591
  };
1585
1592
  } else if (contractExists) {
1586
- const request = {
1593
+ const request2 = {
1587
1594
  abi: zoraCreator1155ImplABI3,
1588
1595
  functionName: "multicall",
1589
1596
  account,
@@ -1591,7 +1598,7 @@ function create1155CreatorClient({
1591
1598
  args: [tokenSetupActions]
1592
1599
  };
1593
1600
  return {
1594
- request,
1601
+ request: request2,
1595
1602
  tokenSetupActions,
1596
1603
  contractAddress,
1597
1604
  contractExists
@@ -1601,6 +1608,377 @@ function create1155CreatorClient({
1601
1608
  }
1602
1609
  return { createNew1155Token };
1603
1610
  }
1611
+
1612
+ // src/mints/mints-queries.ts
1613
+ import { request, gql } from "graphql-request";
1614
+ var getMintsAccountBalanceWithPriceQuery = (account) => {
1615
+ const query = gql`
1616
+ query GetMintAccountBalances($account: String!) {
1617
+ mintAccountBalances(where: { account: $account }) {
1618
+ balance
1619
+ mintToken {
1620
+ id
1621
+ pricePerToken
1622
+ }
1623
+ }
1624
+ }
1625
+ `;
1626
+ return {
1627
+ query,
1628
+ variables: { account }
1629
+ };
1630
+ };
1631
+ var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
1632
+ const parsed = mintAccountBalances.map((r) => {
1633
+ return {
1634
+ tokenId: BigInt(r.mintToken.id),
1635
+ quantity: BigInt(r.balance),
1636
+ pricePerToken: BigInt(r.mintToken.pricePerToken)
1637
+ };
1638
+ });
1639
+ const sorted = parsed.sort((a, b) => {
1640
+ if (a.pricePerToken < b.pricePerToken) {
1641
+ return -1;
1642
+ }
1643
+ return 1;
1644
+ });
1645
+ let remainingQuantity = quantityToCollect;
1646
+ const tokenIds = [];
1647
+ const quantities = [];
1648
+ while (remainingQuantity > 0) {
1649
+ const next = sorted.shift();
1650
+ if (!next) {
1651
+ throw new Error("Not enough MINTs to collect with");
1652
+ }
1653
+ const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
1654
+ tokenIds.push(next.tokenId);
1655
+ quantities.push(quantityToUse);
1656
+ remainingQuantity -= quantityToUse;
1657
+ }
1658
+ return {
1659
+ tokenIds,
1660
+ quantities
1661
+ };
1662
+ };
1663
+ var sumBalances = (mintAccountBalances) => {
1664
+ return mintAccountBalances.reduce((acc, curr) => {
1665
+ return acc + BigInt(curr.balance);
1666
+ }, BigInt(0));
1667
+ };
1668
+ var getMINTsToCollectWith = async ({
1669
+ account,
1670
+ chainId,
1671
+ quantityToCollect
1672
+ }) => {
1673
+ const subgraphUrl = getSubgraphUrl(chainId);
1674
+ const { query, variables } = getMintsAccountBalanceWithPriceQuery(account);
1675
+ const result = await request(
1676
+ subgraphUrl,
1677
+ query,
1678
+ variables
1679
+ );
1680
+ return selectMintsToCollectWithFromQueryResult(
1681
+ result.mintTokenBalances,
1682
+ quantityToCollect
1683
+ );
1684
+ };
1685
+ var getMINTsBalance = async ({
1686
+ chainId,
1687
+ account
1688
+ }) => {
1689
+ const subgraphUrl = getSubgraphUrl(chainId);
1690
+ const { query, variables } = getMintsAccountBalanceWithPriceQuery(account);
1691
+ const result = await request(
1692
+ subgraphUrl,
1693
+ query,
1694
+ variables
1695
+ );
1696
+ return sumBalances(result.mintTokenBalances);
1697
+ };
1698
+
1699
+ // src/mints/mints-contracts.ts
1700
+ import {
1701
+ zoraMints1155Config,
1702
+ zoraMintsManagerImplConfig
1703
+ } from "@zoralabs/protocol-deployments";
1704
+ import {
1705
+ encodeFunctionData as encodeFunctionData2,
1706
+ zeroAddress as zeroAddress5
1707
+ } from "viem";
1708
+ function mintWithEthParams({
1709
+ quantity,
1710
+ recipient,
1711
+ chainId,
1712
+ pricePerMint,
1713
+ account
1714
+ }) {
1715
+ return {
1716
+ abi: zoraMintsManagerImplConfig.abi,
1717
+ address: zoraMintsManagerImplConfig.address[chainId],
1718
+ functionName: "mintWithEth",
1719
+ args: [quantity, recipient],
1720
+ value: pricePerMint * quantity,
1721
+ account
1722
+ };
1723
+ }
1724
+ var getPaidMintValue = (quantities, pricePerMint) => {
1725
+ if (!pricePerMint || pricePerMint === 0n)
1726
+ return;
1727
+ return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
1728
+ };
1729
+ var mintsBalanceOfAccountParams = ({
1730
+ account,
1731
+ chainId
1732
+ }) => ({
1733
+ abi: zoraMints1155Config.abi,
1734
+ address: zoraMints1155Config.address[chainId],
1735
+ functionName: "balanceOfAccount",
1736
+ args: [account]
1737
+ });
1738
+ var accountNonceParams = ({
1739
+ chainId,
1740
+ account
1741
+ }) => ({
1742
+ abi: zoraMints1155Config.abi,
1743
+ address: zoraMints1155Config.address[chainId],
1744
+ functionName: "nonces",
1745
+ args: [account]
1746
+ });
1747
+ var encodeCollectOnManager = ({
1748
+ tokenIds,
1749
+ quantities,
1750
+ zoraCreator1155Contract,
1751
+ minter,
1752
+ zoraCreator1155TokenId,
1753
+ mintArguments
1754
+ }) => encodeFunctionData2({
1755
+ abi: zoraMintsManagerImplConfig.abi,
1756
+ functionName: "collect",
1757
+ args: [
1758
+ tokenIds,
1759
+ quantities,
1760
+ zoraCreator1155Contract,
1761
+ minter,
1762
+ zoraCreator1155TokenId,
1763
+ mintArguments
1764
+ ]
1765
+ });
1766
+ function collectWithMintsParams({
1767
+ tokenIds,
1768
+ quantities,
1769
+ chainId,
1770
+ pricePerToken,
1771
+ account,
1772
+ ...rest
1773
+ }) {
1774
+ const call = encodeCollectOnManager({
1775
+ tokenIds,
1776
+ quantities,
1777
+ ...rest
1778
+ });
1779
+ return {
1780
+ abi: zoraMints1155Config.abi,
1781
+ address: zoraMints1155Config.address[chainId],
1782
+ functionName: "transferBatchToManagerAndCall",
1783
+ args: [tokenIds, quantities, "0x", call],
1784
+ value: getPaidMintValue(quantities, pricePerToken),
1785
+ account
1786
+ };
1787
+ }
1788
+ var collectWithMintsTypedDataDefinition = ({
1789
+ tokenIds,
1790
+ quantities,
1791
+ chainId,
1792
+ account,
1793
+ nonce,
1794
+ deadline,
1795
+ ...rest
1796
+ }) => {
1797
+ const call = encodeCollectOnManager({
1798
+ tokenIds,
1799
+ quantities,
1800
+ ...rest
1801
+ });
1802
+ return makePermitAndTypeData({
1803
+ tokenIds,
1804
+ quantities,
1805
+ chainId,
1806
+ account,
1807
+ nonce,
1808
+ deadline,
1809
+ call
1810
+ });
1811
+ };
1812
+ var collectPremintWithMintsTypedDataDefinition = ({
1813
+ tokenIds,
1814
+ quantities,
1815
+ chainId,
1816
+ account,
1817
+ nonce,
1818
+ deadline,
1819
+ ...rest
1820
+ }) => {
1821
+ const call = encodePremintOnManager({
1822
+ tokenIds,
1823
+ quantities,
1824
+ ...rest
1825
+ });
1826
+ return makePermitAndTypeData({
1827
+ tokenIds,
1828
+ quantities,
1829
+ chainId,
1830
+ account,
1831
+ nonce,
1832
+ deadline,
1833
+ call
1834
+ });
1835
+ };
1836
+ function makePermitAndTypeData({
1837
+ tokenIds,
1838
+ quantities,
1839
+ chainId,
1840
+ account,
1841
+ nonce,
1842
+ deadline,
1843
+ call
1844
+ }) {
1845
+ const permit = {
1846
+ owner: typeof account === "string" ? account : account.address,
1847
+ tokenIds,
1848
+ quantities,
1849
+ call,
1850
+ deadline,
1851
+ safeTransferData: "0x"
1852
+ };
1853
+ const typedData = permitTypedDataDefinition({
1854
+ chainId,
1855
+ nonce,
1856
+ permit,
1857
+ account
1858
+ });
1859
+ return {
1860
+ permit,
1861
+ typedData
1862
+ };
1863
+ }
1864
+ var encodePremintOnManager = ({
1865
+ tokenIds,
1866
+ quantities,
1867
+ contractCreationConfig,
1868
+ premintConfig,
1869
+ premintSignature,
1870
+ mintArguments,
1871
+ signerContract = zeroAddress5
1872
+ }) => encodeFunctionData2({
1873
+ abi: zoraMintsManagerImplConfig.abi,
1874
+ functionName: "collectPremintV2",
1875
+ args: [
1876
+ tokenIds,
1877
+ quantities,
1878
+ contractCreationConfig,
1879
+ premintConfig,
1880
+ premintSignature,
1881
+ mintArguments,
1882
+ signerContract
1883
+ ]
1884
+ });
1885
+ function collectPremintV2WithMintsParams({
1886
+ tokenIds,
1887
+ quantities,
1888
+ pricePerToken,
1889
+ account,
1890
+ chainId,
1891
+ ...rest
1892
+ }) {
1893
+ const call = encodePremintOnManager({
1894
+ tokenIds,
1895
+ quantities,
1896
+ ...rest
1897
+ });
1898
+ return {
1899
+ abi: zoraMints1155Config.abi,
1900
+ address: zoraMints1155Config.address[chainId],
1901
+ functionName: "transferBatchToManagerAndCall",
1902
+ args: [tokenIds, quantities, "0x", call],
1903
+ value: getPaidMintValue(quantities, pricePerToken),
1904
+ account
1905
+ };
1906
+ }
1907
+ function makeTypeData(args) {
1908
+ return args;
1909
+ }
1910
+ function permitTypedDataDefinition({
1911
+ permit,
1912
+ chainId,
1913
+ nonce,
1914
+ account
1915
+ }) {
1916
+ return makeTypeData({
1917
+ primaryType: "Permit",
1918
+ types: {
1919
+ Permit: [
1920
+ {
1921
+ name: "owner",
1922
+ type: "address"
1923
+ },
1924
+ {
1925
+ name: "tokenIds",
1926
+ type: "uint256[]"
1927
+ },
1928
+ {
1929
+ name: "quantities",
1930
+ type: "uint256[]"
1931
+ },
1932
+ {
1933
+ name: "safeTransferData",
1934
+ type: "bytes"
1935
+ },
1936
+ {
1937
+ name: "call",
1938
+ type: "bytes"
1939
+ },
1940
+ {
1941
+ name: "nonce",
1942
+ type: "uint256"
1943
+ },
1944
+ {
1945
+ name: "deadline",
1946
+ type: "uint256"
1947
+ }
1948
+ ]
1949
+ },
1950
+ message: {
1951
+ owner: permit.owner,
1952
+ tokenIds: permit.tokenIds,
1953
+ quantities: permit.quantities,
1954
+ safeTransferData: permit.safeTransferData,
1955
+ call: permit.call,
1956
+ nonce,
1957
+ deadline: permit.deadline
1958
+ },
1959
+ domain: {
1960
+ chainId,
1961
+ name: "Mints",
1962
+ version: "1",
1963
+ verifyingContract: zoraMints1155Config.address[chainId]
1964
+ },
1965
+ // signing account must be permit owner
1966
+ account
1967
+ });
1968
+ }
1969
+ var permitTransferBatchToManagerAndCallParams = ({
1970
+ permit,
1971
+ chainId,
1972
+ signature
1973
+ }) => {
1974
+ const result = {
1975
+ abi: zoraMints1155Config.abi,
1976
+ address: zoraMints1155Config.address[chainId],
1977
+ functionName: "permitTransferBatchToManagerAndCall",
1978
+ args: [permit, signature]
1979
+ };
1980
+ return result;
1981
+ };
1604
1982
  export {
1605
1983
  DEFAULT_SALE_SETTINGS,
1606
1984
  Errors,
@@ -1609,7 +1987,12 @@ export {
1609
1987
  PremintConfigVersion,
1610
1988
  PreminterDomain,
1611
1989
  ZORA_API_BASE,
1990
+ accountNonceParams,
1612
1991
  applyUpdateToPremint,
1992
+ collectPremintV2WithMintsParams,
1993
+ collectPremintWithMintsTypedDataDefinition,
1994
+ collectWithMintsParams,
1995
+ collectWithMintsTypedDataDefinition,
1613
1996
  convertCollectionFromApi,
1614
1997
  convertGetPremintApiResponse,
1615
1998
  convertPremintFromApi,
@@ -1619,11 +2002,16 @@ export {
1619
2002
  createPremintClient,
1620
2003
  defaultTokenConfigV1MintArguments,
1621
2004
  defaultTokenConfigV2MintArguments,
2005
+ encodeCollectOnManager,
1622
2006
  encodePostSignatureInput,
1623
2007
  encodePremintForAPI,
2008
+ encodePremintOnManager,
1624
2009
  getApiNetworkConfigForChain,
1625
2010
  getDefaultFixedPriceMinterAddress,
2011
+ getMINTsBalance,
2012
+ getMINTsToCollectWith,
1626
2013
  getMintCosts,
2014
+ getMintsAccountBalanceWithPriceQuery,
1627
2015
  getPremintCollectionAddress,
1628
2016
  getPremintExecutorAddress,
1629
2017
  getPremintMintCosts,
@@ -1636,9 +2024,15 @@ export {
1636
2024
  makeNewPremint,
1637
2025
  markPremintDeleted,
1638
2026
  migratePremintConfigToV2,
2027
+ mintWithEthParams,
2028
+ mintsBalanceOfAccountParams,
2029
+ permitTransferBatchToManagerAndCallParams,
2030
+ permitTypedDataDefinition,
1639
2031
  premintTypedDataDefinition,
1640
2032
  recoverCreatorFromCreatorAttribution,
1641
2033
  recoverPremintSigner,
2034
+ selectMintsToCollectWithFromQueryResult,
2035
+ sumBalances,
1642
2036
  supportedPremintVersions,
1643
2037
  supportsPremintVersion,
1644
2038
  tryRecoverPremintSigner,