@zoralabs/protocol-sdk 0.5.3 → 0.5.4-MINT.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- warning package.json: "dependencies" has dependency "vite" with range "4.5.0" that collides with a dependency in "devDependencies" of the same name with version "^4.5.0"
2
1
  $ tsup
3
2
  CLI Building entry: src/index.ts
4
3
  CLI Using tsconfig: tsconfig.build.json
@@ -8,9 +7,9 @@ $ tsup
8
7
  CLI Cleaning output folder
9
8
  CJS Build start
10
9
  ESM Build start
11
- ESM dist/index.js 46.25 KB
12
- ESM dist/index.js.map 97.16 KB
13
- ESM ⚡️ Build success in 53ms
14
- CJS dist/index.cjs 50.17 KB
15
- CJS dist/index.cjs.map 97.10 KB
16
- CJS ⚡️ Build success in 54ms
10
+ ESM dist/index.js 48.29 KB
11
+ ESM dist/index.js.map 101.92 KB
12
+ ESM ⚡️ Build success in 118ms
13
+ CJS dist/index.cjs 52.47 KB
14
+ CJS dist/index.cjs.map 101.90 KB
15
+ CJS ⚡️ Build success in 119ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @zoralabs/protocol-sdk
2
2
 
3
+ ## 0.5.4-MINT.0
4
+
5
+ ### Patch Changes
6
+
7
+ - b07a4729: Added functionality to be able to query for MINTs to use when collecting from an account
8
+ - Updated dependencies [a4d2d3d2]
9
+ - Updated dependencies [3401be26]
10
+ - @zoralabs/protocol-deployments@0.1.1-MINT.0
11
+
3
12
  ## 0.5.3
4
13
 
5
14
  ### Patch Changes
@@ -9,5 +9,6 @@ export type NetworkConfig = {
9
9
  };
10
10
  export declare const REWARD_PER_TOKEN: bigint;
11
11
  export declare const networkConfigByChain: Record<number, NetworkConfig>;
12
+ export declare const getSubgraphUrl: (chainId: number) => string;
12
13
  export {};
13
14
  //# sourceMappingURL=chain-constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain-constants.d.ts","sourceRoot":"","sources":["../../src/apis/chain-constants.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAIhE,KAAK,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC;AAE3D,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB,EAAE,MAAM,CAAC;IACjC,oBAAoB,EAAE,gBAAgB,CAAC;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAyB,CAAC;AAEvD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAuE9D,CAAC"}
1
+ {"version":3,"file":"chain-constants.d.ts","sourceRoot":"","sources":["../../src/apis/chain-constants.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAIhE,KAAK,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC;AAE3D,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB,EAAE,MAAM,CAAC;IACjC,oBAAoB,EAAE,gBAAgB,CAAC;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAyB,CAAC;AAEvD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAuE9D,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,MAQhD,CAAC"}
package/dist/index.cjs CHANGED
@@ -41,7 +41,9 @@ __export(src_exports, {
41
41
  encodePremintForAPI: () => encodePremintForAPI,
42
42
  getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
43
43
  getDefaultFixedPriceMinterAddress: () => getDefaultFixedPriceMinterAddress,
44
+ getMINTsToCollectWith: () => getMINTsToCollectWith,
44
45
  getMintCosts: () => getMintCosts,
46
+ getMintsAccountBalanceQuery: () => getMintsAccountBalanceQuery,
45
47
  getPremintCollectionAddress: () => getPremintCollectionAddress,
46
48
  getPremintExecutorAddress: () => getPremintExecutorAddress,
47
49
  getPremintMintCosts: () => getPremintMintCosts,
@@ -57,6 +59,7 @@ __export(src_exports, {
57
59
  premintTypedDataDefinition: () => premintTypedDataDefinition,
58
60
  recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
59
61
  recoverPremintSigner: () => recoverPremintSigner,
62
+ selectMintsToCollectWithFromQueryResult: () => selectMintsToCollectWithFromQueryResult,
60
63
  supportedPremintVersions: () => supportedPremintVersions,
61
64
  supportsPremintVersion: () => supportsPremintVersion,
62
65
  tryRecoverPremintSigner: () => tryRecoverPremintSigner,
@@ -545,6 +548,13 @@ var networkConfigByChain = {
545
548
  subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
546
549
  }
547
550
  };
551
+ var getSubgraphUrl = (chainId) => {
552
+ const networkConfig = networkConfigByChain[chainId];
553
+ if (!networkConfig) {
554
+ throw new Error(`Network not configured for chain id ${chainId}`);
555
+ }
556
+ return networkConfig.subgraphUrl;
557
+ };
548
558
 
549
559
  // src/mint/mint-api-client.ts
550
560
  var getApiNetworkConfigForChain = (chainId) => {
@@ -1603,7 +1613,7 @@ function create1155CreatorClient({
1603
1613
  throw new Error("Invariant: contract cannot be missing and an address");
1604
1614
  }
1605
1615
  if (!contractExists && typeof contract !== "string") {
1606
- const request = {
1616
+ const request2 = {
1607
1617
  abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
1608
1618
  functionName: "createContractDeterministic",
1609
1619
  account,
@@ -1622,13 +1632,13 @@ function create1155CreatorClient({
1622
1632
  ]
1623
1633
  };
1624
1634
  return {
1625
- request,
1635
+ request: request2,
1626
1636
  tokenSetupActions,
1627
1637
  contractAddress,
1628
1638
  contractExists
1629
1639
  };
1630
1640
  } else if (contractExists) {
1631
- const request = {
1641
+ const request2 = {
1632
1642
  abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1633
1643
  functionName: "multicall",
1634
1644
  account,
@@ -1636,7 +1646,7 @@ function create1155CreatorClient({
1636
1646
  args: [tokenSetupActions]
1637
1647
  };
1638
1648
  return {
1639
- request,
1649
+ request: request2,
1640
1650
  tokenSetupActions,
1641
1651
  contractAddress,
1642
1652
  contractExists
@@ -1646,6 +1656,75 @@ function create1155CreatorClient({
1646
1656
  }
1647
1657
  return { createNew1155Token };
1648
1658
  }
1659
+
1660
+ // src/mints/mints-queries.ts
1661
+ var import_graphql_request = require("graphql-request");
1662
+ var getMintsAccountBalanceQuery = (account) => {
1663
+ const query = import_graphql_request.gql`
1664
+ query GetMintAccountBalances($account: String!) {
1665
+ mintTokenBalances(where: { account: $account }) {
1666
+ balance
1667
+ mintToken {
1668
+ id
1669
+ pricePerToken
1670
+ }
1671
+ }
1672
+ }
1673
+ `;
1674
+ return {
1675
+ query,
1676
+ variables: { account }
1677
+ };
1678
+ };
1679
+ var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
1680
+ const parsed = mintAccountBalances.map((r) => {
1681
+ return {
1682
+ tokenId: BigInt(r.mintToken.id),
1683
+ quantity: BigInt(r.balance),
1684
+ pricePerToken: BigInt(r.mintToken.pricePerToken)
1685
+ };
1686
+ });
1687
+ const sorted = parsed.sort((a, b) => {
1688
+ if (a.pricePerToken < b.pricePerToken) {
1689
+ return -1;
1690
+ }
1691
+ return 1;
1692
+ });
1693
+ let remainingQuantity = quantityToCollect;
1694
+ const tokenIds = [];
1695
+ const quantities = [];
1696
+ while (remainingQuantity > 0) {
1697
+ const next = sorted.shift();
1698
+ if (!next) {
1699
+ throw new Error("Not enough MINTs to collect with");
1700
+ }
1701
+ const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
1702
+ tokenIds.push(next.tokenId);
1703
+ quantities.push(quantityToUse);
1704
+ remainingQuantity -= quantityToUse;
1705
+ }
1706
+ return {
1707
+ tokenIds,
1708
+ quantities
1709
+ };
1710
+ };
1711
+ var getMINTsToCollectWith = async ({
1712
+ account,
1713
+ chainId,
1714
+ quantityToCollect
1715
+ }) => {
1716
+ const subgraphUrl = getSubgraphUrl(chainId);
1717
+ const { query, variables } = getMintsAccountBalanceQuery(account);
1718
+ const result = await (0, import_graphql_request.request)(
1719
+ subgraphUrl,
1720
+ query,
1721
+ variables
1722
+ );
1723
+ return selectMintsToCollectWithFromQueryResult(
1724
+ result.mintTokenBalances,
1725
+ quantityToCollect
1726
+ );
1727
+ };
1649
1728
  // Annotate the CommonJS export names for ESM import in node:
1650
1729
  0 && (module.exports = {
1651
1730
  DEFAULT_SALE_SETTINGS,
@@ -1669,7 +1748,9 @@ function create1155CreatorClient({
1669
1748
  encodePremintForAPI,
1670
1749
  getApiNetworkConfigForChain,
1671
1750
  getDefaultFixedPriceMinterAddress,
1751
+ getMINTsToCollectWith,
1672
1752
  getMintCosts,
1753
+ getMintsAccountBalanceQuery,
1673
1754
  getPremintCollectionAddress,
1674
1755
  getPremintExecutorAddress,
1675
1756
  getPremintMintCosts,
@@ -1685,6 +1766,7 @@ function create1155CreatorClient({
1685
1766
  premintTypedDataDefinition,
1686
1767
  recoverCreatorFromCreatorAttribution,
1687
1768
  recoverPremintSigner,
1769
+ selectMintsToCollectWithFromQueryResult,
1688
1770
  supportedPremintVersions,
1689
1771
  supportsPremintVersion,
1690
1772
  tryRecoverPremintSigner,