@zoralabs/protocol-sdk 0.5.6 → 0.5.7-MINT.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/.turbo/turbo-build.log +6 -7
- package/CHANGELOG.md +14 -0
- package/dist/apis/chain-constants.d.ts +1 -0
- package/dist/apis/chain-constants.d.ts.map +1 -1
- package/dist/index.cjs +108 -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 +103 -4
- package/dist/index.js.map +1 -1
- package/dist/mints/mints-queries.d.ts +59 -0
- package/dist/mints/mints-queries.d.ts.map +1 -0
- 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 +105 -0
- package/src/mints/mints-queries.ts +159 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -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
|
[34mCLI[39m Building entry: src/index.ts
|
|
4
3
|
[34mCLI[39m Using tsconfig: tsconfig.build.json
|
|
@@ -8,9 +7,9 @@ $ tsup
|
|
|
8
7
|
[34mCLI[39m Cleaning output folder
|
|
9
8
|
[34mCJS[39m Build start
|
|
10
9
|
[34mESM[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
10
|
+
[32mESM[39m [1mdist/index.js [22m[32m48.81 KB[39m
|
|
11
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m103.22 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 110ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m53.11 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m103.21 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 113ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @zoralabs/protocol-sdk
|
|
2
2
|
|
|
3
|
+
## 0.5.7-MINT.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @zoralabs/protocol-deployments@0.1.3-MINT.1
|
|
8
|
+
|
|
9
|
+
## 0.5.7-MINT.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 10431de6: Added functionality to be able to query for MINTs to use when collecting from an account
|
|
14
|
+
- Updated dependencies [9f2984f5]
|
|
15
|
+
- @zoralabs/protocol-deployments@0.1.3-MINT.0
|
|
16
|
+
|
|
3
17
|
## 0.5.6
|
|
4
18
|
|
|
5
19
|
### 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,10 @@ __export(src_exports, {
|
|
|
41
41
|
encodePremintForAPI: () => encodePremintForAPI,
|
|
42
42
|
getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
|
|
43
43
|
getDefaultFixedPriceMinterAddress: () => getDefaultFixedPriceMinterAddress,
|
|
44
|
+
getMINTsBalance: () => getMINTsBalance,
|
|
45
|
+
getMINTsToCollectWith: () => getMINTsToCollectWith,
|
|
44
46
|
getMintCosts: () => getMintCosts,
|
|
47
|
+
getMintsAccountBalanceWithPriceQuery: () => getMintsAccountBalanceWithPriceQuery,
|
|
45
48
|
getPremintCollectionAddress: () => getPremintCollectionAddress,
|
|
46
49
|
getPremintExecutorAddress: () => getPremintExecutorAddress,
|
|
47
50
|
getPremintMintCosts: () => getPremintMintCosts,
|
|
@@ -57,6 +60,8 @@ __export(src_exports, {
|
|
|
57
60
|
premintTypedDataDefinition: () => premintTypedDataDefinition,
|
|
58
61
|
recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
|
|
59
62
|
recoverPremintSigner: () => recoverPremintSigner,
|
|
63
|
+
selectMintsToCollectWithFromQueryResult: () => selectMintsToCollectWithFromQueryResult,
|
|
64
|
+
sumBalances: () => sumBalances,
|
|
60
65
|
supportedPremintVersions: () => supportedPremintVersions,
|
|
61
66
|
supportsPremintVersion: () => supportsPremintVersion,
|
|
62
67
|
tryRecoverPremintSigner: () => tryRecoverPremintSigner,
|
|
@@ -545,6 +550,13 @@ var networkConfigByChain = {
|
|
|
545
550
|
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
546
551
|
}
|
|
547
552
|
};
|
|
553
|
+
var getSubgraphUrl = (chainId) => {
|
|
554
|
+
const networkConfig = networkConfigByChain[chainId];
|
|
555
|
+
if (!networkConfig) {
|
|
556
|
+
throw new Error(`Network not configured for chain id ${chainId}`);
|
|
557
|
+
}
|
|
558
|
+
return networkConfig.subgraphUrl;
|
|
559
|
+
};
|
|
548
560
|
|
|
549
561
|
// src/mint/mint-api-client.ts
|
|
550
562
|
var getApiNetworkConfigForChain = (chainId) => {
|
|
@@ -1603,7 +1615,7 @@ function create1155CreatorClient({
|
|
|
1603
1615
|
throw new Error("Invariant: contract cannot be missing and an address");
|
|
1604
1616
|
}
|
|
1605
1617
|
if (!contractExists && typeof contract !== "string") {
|
|
1606
|
-
const
|
|
1618
|
+
const request2 = {
|
|
1607
1619
|
abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
|
|
1608
1620
|
functionName: "createContractDeterministic",
|
|
1609
1621
|
account,
|
|
@@ -1622,13 +1634,13 @@ function create1155CreatorClient({
|
|
|
1622
1634
|
]
|
|
1623
1635
|
};
|
|
1624
1636
|
return {
|
|
1625
|
-
request,
|
|
1637
|
+
request: request2,
|
|
1626
1638
|
tokenSetupActions,
|
|
1627
1639
|
contractAddress,
|
|
1628
1640
|
contractExists
|
|
1629
1641
|
};
|
|
1630
1642
|
} else if (contractExists) {
|
|
1631
|
-
const
|
|
1643
|
+
const request2 = {
|
|
1632
1644
|
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1633
1645
|
functionName: "multicall",
|
|
1634
1646
|
account,
|
|
@@ -1636,7 +1648,7 @@ function create1155CreatorClient({
|
|
|
1636
1648
|
args: [tokenSetupActions]
|
|
1637
1649
|
};
|
|
1638
1650
|
return {
|
|
1639
|
-
request,
|
|
1651
|
+
request: request2,
|
|
1640
1652
|
tokenSetupActions,
|
|
1641
1653
|
contractAddress,
|
|
1642
1654
|
contractExists
|
|
@@ -1646,6 +1658,93 @@ function create1155CreatorClient({
|
|
|
1646
1658
|
}
|
|
1647
1659
|
return { createNew1155Token };
|
|
1648
1660
|
}
|
|
1661
|
+
|
|
1662
|
+
// src/mints/mints-queries.ts
|
|
1663
|
+
var import_graphql_request = require("graphql-request");
|
|
1664
|
+
var getMintsAccountBalanceWithPriceQuery = (account) => {
|
|
1665
|
+
const query = import_graphql_request.gql`
|
|
1666
|
+
query GetMintAccountBalances($account: String!) {
|
|
1667
|
+
mintAccountBalances(where: { account: $account }) {
|
|
1668
|
+
balance
|
|
1669
|
+
mintToken {
|
|
1670
|
+
id
|
|
1671
|
+
pricePerToken
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
`;
|
|
1676
|
+
return {
|
|
1677
|
+
query,
|
|
1678
|
+
variables: { account }
|
|
1679
|
+
};
|
|
1680
|
+
};
|
|
1681
|
+
var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
|
|
1682
|
+
const parsed = mintAccountBalances.map((r) => {
|
|
1683
|
+
return {
|
|
1684
|
+
tokenId: BigInt(r.mintToken.id),
|
|
1685
|
+
quantity: BigInt(r.balance),
|
|
1686
|
+
pricePerToken: BigInt(r.mintToken.pricePerToken)
|
|
1687
|
+
};
|
|
1688
|
+
});
|
|
1689
|
+
const sorted = parsed.sort((a, b) => {
|
|
1690
|
+
if (a.pricePerToken < b.pricePerToken) {
|
|
1691
|
+
return -1;
|
|
1692
|
+
}
|
|
1693
|
+
return 1;
|
|
1694
|
+
});
|
|
1695
|
+
let remainingQuantity = quantityToCollect;
|
|
1696
|
+
const tokenIds = [];
|
|
1697
|
+
const quantities = [];
|
|
1698
|
+
while (remainingQuantity > 0) {
|
|
1699
|
+
const next = sorted.shift();
|
|
1700
|
+
if (!next) {
|
|
1701
|
+
throw new Error("Not enough MINTs to collect with");
|
|
1702
|
+
}
|
|
1703
|
+
const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
|
|
1704
|
+
tokenIds.push(next.tokenId);
|
|
1705
|
+
quantities.push(quantityToUse);
|
|
1706
|
+
remainingQuantity -= quantityToUse;
|
|
1707
|
+
}
|
|
1708
|
+
return {
|
|
1709
|
+
tokenIds,
|
|
1710
|
+
quantities
|
|
1711
|
+
};
|
|
1712
|
+
};
|
|
1713
|
+
var sumBalances = (mintAccountBalances) => {
|
|
1714
|
+
return mintAccountBalances.reduce((acc, curr) => {
|
|
1715
|
+
return acc + BigInt(curr.balance);
|
|
1716
|
+
}, BigInt(0));
|
|
1717
|
+
};
|
|
1718
|
+
var getMINTsToCollectWith = async ({
|
|
1719
|
+
account,
|
|
1720
|
+
chainId,
|
|
1721
|
+
quantityToCollect
|
|
1722
|
+
}) => {
|
|
1723
|
+
const subgraphUrl = getSubgraphUrl(chainId);
|
|
1724
|
+
const { query, variables } = getMintsAccountBalanceWithPriceQuery(account);
|
|
1725
|
+
const result = await (0, import_graphql_request.request)(
|
|
1726
|
+
subgraphUrl,
|
|
1727
|
+
query,
|
|
1728
|
+
variables
|
|
1729
|
+
);
|
|
1730
|
+
return selectMintsToCollectWithFromQueryResult(
|
|
1731
|
+
result.mintTokenBalances,
|
|
1732
|
+
quantityToCollect
|
|
1733
|
+
);
|
|
1734
|
+
};
|
|
1735
|
+
var getMINTsBalance = async ({
|
|
1736
|
+
chainId,
|
|
1737
|
+
account
|
|
1738
|
+
}) => {
|
|
1739
|
+
const subgraphUrl = getSubgraphUrl(chainId);
|
|
1740
|
+
const { query, variables } = getMintsAccountBalanceWithPriceQuery(account);
|
|
1741
|
+
const result = await (0, import_graphql_request.request)(
|
|
1742
|
+
subgraphUrl,
|
|
1743
|
+
query,
|
|
1744
|
+
variables
|
|
1745
|
+
);
|
|
1746
|
+
return sumBalances(result.mintTokenBalances);
|
|
1747
|
+
};
|
|
1649
1748
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1650
1749
|
0 && (module.exports = {
|
|
1651
1750
|
DEFAULT_SALE_SETTINGS,
|
|
@@ -1669,7 +1768,10 @@ function create1155CreatorClient({
|
|
|
1669
1768
|
encodePremintForAPI,
|
|
1670
1769
|
getApiNetworkConfigForChain,
|
|
1671
1770
|
getDefaultFixedPriceMinterAddress,
|
|
1771
|
+
getMINTsBalance,
|
|
1772
|
+
getMINTsToCollectWith,
|
|
1672
1773
|
getMintCosts,
|
|
1774
|
+
getMintsAccountBalanceWithPriceQuery,
|
|
1673
1775
|
getPremintCollectionAddress,
|
|
1674
1776
|
getPremintExecutorAddress,
|
|
1675
1777
|
getPremintMintCosts,
|
|
@@ -1685,6 +1787,8 @@ function create1155CreatorClient({
|
|
|
1685
1787
|
premintTypedDataDefinition,
|
|
1686
1788
|
recoverCreatorFromCreatorAttribution,
|
|
1687
1789
|
recoverPremintSigner,
|
|
1790
|
+
selectMintsToCollectWithFromQueryResult,
|
|
1791
|
+
sumBalances,
|
|
1688
1792
|
supportedPremintVersions,
|
|
1689
1793
|
supportsPremintVersion,
|
|
1690
1794
|
tryRecoverPremintSigner,
|