@zoralabs/protocol-sdk 0.5.3-mints.0 → 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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/premint/premint-client.ts
2
2
  import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
3
- import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/1155-deployments";
3
+ import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/protocol-deployments";
4
4
 
5
5
  // src/premint/preminter.ts
6
6
  import {
@@ -8,7 +8,7 @@ import {
8
8
  zoraCreator1155PremintExecutorImplABI,
9
9
  zoraCreator1155PremintExecutorImplAddress,
10
10
  zoraCreatorFixedPriceSaleStrategyAddress
11
- } from "@zoralabs/1155-deployments";
11
+ } from "@zoralabs/protocol-deployments";
12
12
  import {
13
13
  recoverTypedDataAddress,
14
14
  zeroAddress,
@@ -502,6 +502,13 @@ var networkConfigByChain = {
502
502
  subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
503
503
  }
504
504
  };
505
+ var getSubgraphUrl = (chainId) => {
506
+ const networkConfig = networkConfigByChain[chainId];
507
+ if (!networkConfig) {
508
+ throw new Error(`Network not configured for chain id ${chainId}`);
509
+ }
510
+ return networkConfig.subgraphUrl;
511
+ };
505
512
 
506
513
  // src/mint/mint-api-client.ts
507
514
  var getApiNetworkConfigForChain = (chainId) => {
@@ -986,7 +993,7 @@ var PremintClient = class {
986
993
  tokenConfig: makeTokenConfigWithDefaults({
987
994
  premintConfigVersion: actualVersion,
988
995
  tokenCreationConfig,
989
- creatorAccount,
996
+ creatorAccount: typeof creatorAccount === "string" ? creatorAccount : creatorAccount.address,
990
997
  chainId: this.chain.id
991
998
  }),
992
999
  uid: uidToUse
@@ -1233,7 +1240,7 @@ import {
1233
1240
  import {
1234
1241
  zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
1235
1242
  zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
1236
- } from "@zoralabs/1155-deployments";
1243
+ } from "@zoralabs/protocol-deployments";
1237
1244
  var MintError = class extends Error {
1238
1245
  };
1239
1246
  var MintInactiveError = class extends Error {
@@ -1372,7 +1379,7 @@ import {
1372
1379
  zoraCreator1155FactoryImplAddress,
1373
1380
  zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
1374
1381
  zoraCreatorFixedPriceSaleStrategyABI
1375
- } from "@zoralabs/1155-deployments";
1382
+ } from "@zoralabs/protocol-deployments";
1376
1383
  import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
1377
1384
  var SALE_END_FOREVER = 18446744073709551615n;
1378
1385
  var ROYALTY_BPS_DEFAULT = 1e3;
@@ -1574,7 +1581,7 @@ function create1155CreatorClient({
1574
1581
  throw new Error("Invariant: contract cannot be missing and an address");
1575
1582
  }
1576
1583
  if (!contractExists && typeof contract !== "string") {
1577
- const request = {
1584
+ const request2 = {
1578
1585
  abi: zoraCreator1155FactoryImplABI,
1579
1586
  functionName: "createContractDeterministic",
1580
1587
  account,
@@ -1593,13 +1600,13 @@ function create1155CreatorClient({
1593
1600
  ]
1594
1601
  };
1595
1602
  return {
1596
- request,
1603
+ request: request2,
1597
1604
  tokenSetupActions,
1598
1605
  contractAddress,
1599
1606
  contractExists
1600
1607
  };
1601
1608
  } else if (contractExists) {
1602
- const request = {
1609
+ const request2 = {
1603
1610
  abi: zoraCreator1155ImplABI3,
1604
1611
  functionName: "multicall",
1605
1612
  account,
@@ -1607,7 +1614,7 @@ function create1155CreatorClient({
1607
1614
  args: [tokenSetupActions]
1608
1615
  };
1609
1616
  return {
1610
- request,
1617
+ request: request2,
1611
1618
  tokenSetupActions,
1612
1619
  contractAddress,
1613
1620
  contractExists
@@ -1617,6 +1624,75 @@ function create1155CreatorClient({
1617
1624
  }
1618
1625
  return { createNew1155Token };
1619
1626
  }
1627
+
1628
+ // src/mints/mints-queries.ts
1629
+ import { request, gql } from "graphql-request";
1630
+ var getMintsAccountBalanceQuery = (account) => {
1631
+ const query = gql`
1632
+ query GetMintAccountBalances($account: String!) {
1633
+ mintTokenBalances(where: { account: $account }) {
1634
+ balance
1635
+ mintToken {
1636
+ id
1637
+ pricePerToken
1638
+ }
1639
+ }
1640
+ }
1641
+ `;
1642
+ return {
1643
+ query,
1644
+ variables: { account }
1645
+ };
1646
+ };
1647
+ var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
1648
+ const parsed = mintAccountBalances.map((r) => {
1649
+ return {
1650
+ tokenId: BigInt(r.mintToken.id),
1651
+ quantity: BigInt(r.balance),
1652
+ pricePerToken: BigInt(r.mintToken.pricePerToken)
1653
+ };
1654
+ });
1655
+ const sorted = parsed.sort((a, b) => {
1656
+ if (a.pricePerToken < b.pricePerToken) {
1657
+ return -1;
1658
+ }
1659
+ return 1;
1660
+ });
1661
+ let remainingQuantity = quantityToCollect;
1662
+ const tokenIds = [];
1663
+ const quantities = [];
1664
+ while (remainingQuantity > 0) {
1665
+ const next = sorted.shift();
1666
+ if (!next) {
1667
+ throw new Error("Not enough MINTs to collect with");
1668
+ }
1669
+ const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
1670
+ tokenIds.push(next.tokenId);
1671
+ quantities.push(quantityToUse);
1672
+ remainingQuantity -= quantityToUse;
1673
+ }
1674
+ return {
1675
+ tokenIds,
1676
+ quantities
1677
+ };
1678
+ };
1679
+ var getMINTsToCollectWith = async ({
1680
+ account,
1681
+ chainId,
1682
+ quantityToCollect
1683
+ }) => {
1684
+ const subgraphUrl = getSubgraphUrl(chainId);
1685
+ const { query, variables } = getMintsAccountBalanceQuery(account);
1686
+ const result = await request(
1687
+ subgraphUrl,
1688
+ query,
1689
+ variables
1690
+ );
1691
+ return selectMintsToCollectWithFromQueryResult(
1692
+ result.mintTokenBalances,
1693
+ quantityToCollect
1694
+ );
1695
+ };
1620
1696
  export {
1621
1697
  DEFAULT_SALE_SETTINGS,
1622
1698
  Errors,
@@ -1639,7 +1715,9 @@ export {
1639
1715
  encodePremintForAPI,
1640
1716
  getApiNetworkConfigForChain,
1641
1717
  getDefaultFixedPriceMinterAddress,
1718
+ getMINTsToCollectWith,
1642
1719
  getMintCosts,
1720
+ getMintsAccountBalanceQuery,
1643
1721
  getPremintCollectionAddress,
1644
1722
  getPremintExecutorAddress,
1645
1723
  getPremintMintCosts,
@@ -1655,6 +1733,7 @@ export {
1655
1733
  premintTypedDataDefinition,
1656
1734
  recoverCreatorFromCreatorAttribution,
1657
1735
  recoverPremintSigner,
1736
+ selectMintsToCollectWithFromQueryResult,
1658
1737
  supportedPremintVersions,
1659
1738
  supportsPremintVersion,
1660
1739
  tryRecoverPremintSigner,