@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.
- package/.turbo/turbo-build.log +6 -7
- package/CHANGELOG.md +9 -0
- package/dist/apis/chain-constants.d.ts +1 -0
- package/dist/apis/chain-constants.d.ts.map +1 -1
- package/dist/index.cjs +86 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -4
- package/dist/index.js.map +1 -1
- package/dist/mints/mints-queries.d.ts +44 -0
- package/dist/mints/mints-queries.d.ts.map +1 -0
- package/dist/preminter.d.ts +1 -1
- package/dist/preminter.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/apis/chain-constants.ts +10 -0
- package/src/index.ts +2 -0
- package/src/mints/mints-queries.test.ts +78 -0
- package/src/mints/mints-queries.ts +121 -0
- package/src/preminter.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -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) => {
|
|
@@ -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
|
|
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
|
|
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,
|