@zoralabs/protocol-sdk 0.5.17 → 0.7.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.
Files changed (84) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +1 -416
  4. package/dist/constants.d.ts +0 -1
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/create/1155-create-helper.d.ts +16 -55
  7. package/dist/create/1155-create-helper.d.ts.map +1 -1
  8. package/dist/create/contract-setup.d.ts +14 -0
  9. package/dist/create/contract-setup.d.ts.map +1 -0
  10. package/dist/create/token-setup.d.ts +27 -0
  11. package/dist/create/token-setup.d.ts.map +1 -0
  12. package/dist/create/types.d.ts +45 -0
  13. package/dist/create/types.d.ts.map +1 -0
  14. package/dist/index.cjs +1745 -891
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1698 -858
  19. package/dist/index.js.map +1 -1
  20. package/dist/mint/mint-client.d.ts +48 -51
  21. package/dist/mint/mint-client.d.ts.map +1 -1
  22. package/dist/mint/mint-queries.d.ts +38 -0
  23. package/dist/mint/mint-queries.d.ts.map +1 -0
  24. package/dist/mint/mint-transactions.d.ts +20 -0
  25. package/dist/mint/mint-transactions.d.ts.map +1 -0
  26. package/dist/mint/subgraph-mint-getter.d.ts +24 -0
  27. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
  28. package/dist/mint/subgraph-queries.d.ts +55 -0
  29. package/dist/mint/subgraph-queries.d.ts.map +1 -0
  30. package/dist/mint/types.d.ts +177 -0
  31. package/dist/mint/types.d.ts.map +1 -0
  32. package/dist/mint/utils.d.ts +2 -0
  33. package/dist/mint/utils.d.ts.map +1 -0
  34. package/dist/mints/mints-contracts.d.ts +27 -4518
  35. package/dist/mints/mints-contracts.d.ts.map +1 -1
  36. package/dist/premint/contract-types.d.ts +4 -4
  37. package/dist/premint/contract-types.d.ts.map +1 -1
  38. package/dist/premint/conversions.d.ts +15 -16
  39. package/dist/premint/conversions.d.ts.map +1 -1
  40. package/dist/premint/premint-api-client.d.ts +32 -16
  41. package/dist/premint/premint-api-client.d.ts.map +1 -1
  42. package/dist/premint/premint-client.d.ts +76 -50
  43. package/dist/premint/premint-client.d.ts.map +1 -1
  44. package/dist/premint/preminter.d.ts +20 -8
  45. package/dist/premint/preminter.d.ts.map +1 -1
  46. package/dist/sdk.d.ts +45 -0
  47. package/dist/sdk.d.ts.map +1 -0
  48. package/dist/types.d.ts +3 -0
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/utils.d.ts +24 -6869
  51. package/dist/utils.d.ts.map +1 -1
  52. package/package.json +3 -2
  53. package/src/constants.ts +0 -36
  54. package/src/create/1155-create-helper.test.ts +236 -55
  55. package/src/create/1155-create-helper.ts +141 -309
  56. package/src/create/contract-setup.ts +88 -0
  57. package/src/create/token-setup.ts +379 -0
  58. package/src/create/types.ts +57 -0
  59. package/src/index.ts +5 -1
  60. package/src/mint/mint-client.test.ts +116 -78
  61. package/src/mint/mint-client.ts +130 -234
  62. package/src/mint/mint-queries.ts +320 -0
  63. package/src/mint/mint-transactions.ts +253 -0
  64. package/src/mint/subgraph-mint-getter.ts +247 -0
  65. package/src/mint/subgraph-queries.ts +170 -0
  66. package/src/mint/types.ts +239 -0
  67. package/src/mint/utils.ts +14 -0
  68. package/src/mints/mints-contracts.test.ts +1 -1
  69. package/src/mints/mints-contracts.ts +4 -4
  70. package/src/premint/contract-types.ts +4 -4
  71. package/src/premint/conversions.ts +38 -4
  72. package/src/premint/premint-api-client.ts +92 -48
  73. package/src/premint/premint-client.test.ts +100 -84
  74. package/src/premint/premint-client.ts +186 -185
  75. package/src/premint/preminter.test.ts +4 -5
  76. package/src/premint/preminter.ts +63 -14
  77. package/src/sdk.ts +101 -0
  78. package/src/types.ts +18 -0
  79. package/src/utils.ts +54 -46
  80. package/test-integration/setup-test-contracts.ts +96 -0
  81. package/dist/mint/mint-api-client.d.ts +0 -35
  82. package/dist/mint/mint-api-client.d.ts.map +0 -1
  83. package/src/mint/mint-api-client.ts +0 -177
  84. package/test-integration/premint-client.test.ts +0 -148
@@ -0,0 +1,247 @@
1
+ import { Address } from "viem";
2
+ import {
3
+ httpClient as defaultHttpClient,
4
+ IHttpClient,
5
+ } from "../apis/http-api-base";
6
+ import { NetworkConfig, networkConfigByChain } from "src/apis/chain-constants";
7
+ import { GenericTokenIdTypes } from "src/types";
8
+ import {
9
+ IOnchainMintGetter,
10
+ SaleType,
11
+ OnchainMintable,
12
+ OnchainSalesConfigAndTokenInfo,
13
+ OnchainSalesStrategies,
14
+ isErc20SaleStrategy,
15
+ } from "./types";
16
+ import { querySubgraphWithRetries } from "src/utils";
17
+ import {
18
+ buildContractTokensQuery,
19
+ buildNftTokenSalesQuery,
20
+ buildPremintsOfContractQuery,
21
+ ISubgraphQuery,
22
+ SalesStrategyResult,
23
+ TokenQueryResult,
24
+ } from "./subgraph-queries";
25
+
26
+ export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
27
+ if (!networkConfigByChain[chainId]) {
28
+ throw new Error(`chain id ${chainId} network not configured `);
29
+ }
30
+ return networkConfigByChain[chainId]!;
31
+ };
32
+
33
+ function parseSalesConfig(
34
+ targetStrategy: SalesStrategyResult,
35
+ ): OnchainSalesStrategies {
36
+ if (targetStrategy.type === "FIXED_PRICE")
37
+ return {
38
+ saleType: "fixedPrice",
39
+ ...targetStrategy.fixedPrice,
40
+ maxTokensPerAddress: BigInt(
41
+ targetStrategy.fixedPrice.maxTokensPerAddress,
42
+ ),
43
+ pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken),
44
+ };
45
+
46
+ if (targetStrategy.type === "ERC_20_MINTER") {
47
+ return {
48
+ saleType: "erc20",
49
+ ...targetStrategy.erc20Minter,
50
+ maxTokensPerAddress: BigInt(
51
+ targetStrategy.erc20Minter.maxTokensPerAddress,
52
+ ),
53
+ pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
54
+ };
55
+ }
56
+
57
+ throw new Error("Unknown saleType");
58
+ }
59
+
60
+ function getSaleEnd(a: SalesStrategyResult) {
61
+ return BigInt(
62
+ a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd,
63
+ );
64
+ }
65
+
66
+ function getTargetStrategy({
67
+ tokenId,
68
+ preferredSaleType,
69
+ token,
70
+ }: {
71
+ tokenId?: GenericTokenIdTypes;
72
+ preferredSaleType?: SaleType;
73
+ token: TokenQueryResult;
74
+ }) {
75
+ const allStrategies =
76
+ (typeof tokenId !== "undefined"
77
+ ? token.salesStrategies
78
+ : token.contract.salesStrategies) || [];
79
+
80
+ const saleStrategies = allStrategies.sort((a, b) =>
81
+ getSaleEnd(a) > getSaleEnd(b) ? 1 : -1,
82
+ );
83
+
84
+ let targetStrategy: SalesStrategyResult | undefined;
85
+
86
+ if (!preferredSaleType) {
87
+ targetStrategy = saleStrategies[0];
88
+ if (!targetStrategy) {
89
+ throw new Error("Cannot find sale strategy");
90
+ }
91
+ } else {
92
+ const mappedSaleType =
93
+ preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
94
+ targetStrategy = saleStrategies.find(
95
+ (strategy: SalesStrategyResult) => strategy.type === mappedSaleType,
96
+ );
97
+ if (!targetStrategy) {
98
+ const targetStrategy = saleStrategies.find(
99
+ (strategy: SalesStrategyResult) =>
100
+ strategy.type === "FIXED_PRICE" || strategy.type === "ERC_20_MINTER",
101
+ );
102
+ if (!targetStrategy) throw new Error("Cannot find valid sale strategy");
103
+ return targetStrategy;
104
+ }
105
+ }
106
+
107
+ return targetStrategy;
108
+ }
109
+ export class SubgraphMintGetter implements IOnchainMintGetter {
110
+ httpClient: IHttpClient;
111
+ networkConfig: NetworkConfig;
112
+
113
+ constructor(chainId: number, httpClient?: IHttpClient) {
114
+ this.httpClient = httpClient || defaultHttpClient;
115
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
116
+ }
117
+
118
+ async querySubgraphWithRetries<T>({
119
+ query,
120
+ variables,
121
+ parseResponseData,
122
+ }: ISubgraphQuery<T>) {
123
+ const responseData = await querySubgraphWithRetries({
124
+ httpClient: this.httpClient,
125
+ subgraphUrl: this.networkConfig.subgraphUrl,
126
+ query,
127
+ variables,
128
+ });
129
+
130
+ return parseResponseData(responseData);
131
+ }
132
+
133
+ getMintable: IOnchainMintGetter["getMintable"] = async ({
134
+ tokenAddress,
135
+ tokenId,
136
+ preferredSaleType: saleType,
137
+ }) => {
138
+ const token = await this.querySubgraphWithRetries(
139
+ buildNftTokenSalesQuery({
140
+ tokenId,
141
+ tokenAddress,
142
+ }),
143
+ );
144
+
145
+ if (!token) {
146
+ throw new Error("Cannot find token");
147
+ }
148
+
149
+ return parseTokenQueryResult({
150
+ token,
151
+ tokenId,
152
+ preferredSaleType: saleType,
153
+ });
154
+ };
155
+
156
+ async getContractMintable({
157
+ tokenAddress,
158
+ preferredSaleType,
159
+ }: {
160
+ tokenAddress: Address;
161
+ preferredSaleType?: SaleType;
162
+ }) {
163
+ const tokens = await this.querySubgraphWithRetries(
164
+ buildContractTokensQuery({
165
+ tokenAddress,
166
+ }),
167
+ );
168
+
169
+ if (!tokens) return [];
170
+
171
+ return tokens
172
+ .filter((x) => x.tokenId !== "0")
173
+ .map((token) =>
174
+ parseTokenQueryResult({
175
+ token,
176
+ tokenId: token.tokenId,
177
+ preferredSaleType,
178
+ }),
179
+ );
180
+ }
181
+
182
+ async getContractPremintTokenIds({
183
+ tokenAddress,
184
+ }: {
185
+ tokenAddress: Address;
186
+ }) {
187
+ const premints = await this.querySubgraphWithRetries(
188
+ buildPremintsOfContractQuery({
189
+ tokenAddress,
190
+ }),
191
+ );
192
+
193
+ return (
194
+ premints?.map((premint) => ({
195
+ tokenId: BigInt(premint.tokenId),
196
+ uid: +premint.uid,
197
+ })) || []
198
+ );
199
+ }
200
+ }
201
+
202
+ function parseTokenQueryResult({
203
+ token,
204
+ tokenId,
205
+ preferredSaleType,
206
+ }: {
207
+ token: TokenQueryResult;
208
+ tokenId?: GenericTokenIdTypes;
209
+ preferredSaleType?: SaleType;
210
+ }): OnchainSalesConfigAndTokenInfo {
211
+ const targetStrategy = getTargetStrategy({
212
+ tokenId,
213
+ preferredSaleType: preferredSaleType,
214
+ token,
215
+ });
216
+
217
+ const tokenInfo = parseTokenInfo(token);
218
+
219
+ const salesConfig = parseSalesConfig(targetStrategy);
220
+
221
+ if (isErc20SaleStrategy(salesConfig)) {
222
+ tokenInfo.mintFeePerQuantity = 0n;
223
+ }
224
+
225
+ return {
226
+ ...tokenInfo,
227
+ salesConfig,
228
+ };
229
+ }
230
+
231
+ function parseTokenInfo(token: TokenQueryResult): OnchainMintable {
232
+ return {
233
+ contract: {
234
+ address: token.contract.address,
235
+ name: token.contract.name,
236
+ URI: token.contract.contractURI,
237
+ },
238
+ tokenURI: token.uri,
239
+ tokenId: token.tokenId ? BigInt(token.tokenId) : undefined,
240
+ mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
241
+ creator: token.creator,
242
+ totalMinted: BigInt(token.totalMinted),
243
+ maxSupply: BigInt(token.maxSupply),
244
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
245
+ contractVersion: token.contract.contractVersion,
246
+ };
247
+ }
@@ -0,0 +1,170 @@
1
+ import { GenericTokenIdTypes } from "src/types";
2
+ import { Address } from "viem";
3
+
4
+ export type FixedPriceSaleStrategyResult = {
5
+ address: Address;
6
+ pricePerToken: string;
7
+ saleEnd: string;
8
+ saleStart: string;
9
+ maxTokensPerAddress: string;
10
+ };
11
+
12
+ export type ERC20SaleStrategyResult = FixedPriceSaleStrategyResult & {
13
+ currency: Address;
14
+ };
15
+
16
+ export type SalesStrategyResult =
17
+ | {
18
+ type: "FIXED_PRICE";
19
+ fixedPrice: FixedPriceSaleStrategyResult;
20
+ }
21
+ | {
22
+ type: "ERC_20_MINTER";
23
+ erc20Minter: ERC20SaleStrategyResult;
24
+ };
25
+
26
+ export type TokenQueryResult = {
27
+ tokenId?: string;
28
+ creator: Address;
29
+ uri: string;
30
+ totalMinted: string;
31
+ maxSupply: string;
32
+ salesStrategies?: SalesStrategyResult[];
33
+ tokenStandard: "ERC1155" | "ERC721";
34
+ contract: {
35
+ mintFeePerQuantity: "string";
36
+ salesStrategies: SalesStrategyResult[];
37
+ address: Address;
38
+ contractVersion: string;
39
+ contractURI: string;
40
+ name: string;
41
+ };
42
+ };
43
+
44
+ const NFT_SALE_STRATEGY_FRAGMENT = `
45
+ fragment SaleStrategy on SalesStrategyConfig {
46
+ type
47
+ fixedPrice {
48
+ address
49
+ pricePerToken
50
+ saleEnd
51
+ saleStart
52
+ maxTokensPerAddress
53
+ }
54
+ erc20Minter {
55
+ address
56
+ pricePerToken
57
+ currency
58
+ saleEnd
59
+ saleStart
60
+ maxTokensPerAddress
61
+ }
62
+ }`;
63
+
64
+ const TOKEN_FRAGMENT = `
65
+ fragment Token on ZoraCreateToken {
66
+ creator
67
+ tokenId
68
+ uri
69
+ totalMinted
70
+ maxSupply
71
+ tokenStandard
72
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
73
+ ...SaleStrategy
74
+ }
75
+ contract {
76
+ address
77
+ mintFeePerQuantity
78
+ contractVersion
79
+ contractURI
80
+ name
81
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
82
+ ...SaleStrategy
83
+ }
84
+ }
85
+ }`;
86
+
87
+ const FRAGMENTS = `
88
+ ${NFT_SALE_STRATEGY_FRAGMENT}
89
+ ${TOKEN_FRAGMENT}
90
+ `;
91
+
92
+ export function buildNftTokenSalesQuery({
93
+ tokenId,
94
+ tokenAddress,
95
+ }: {
96
+ tokenId?: GenericTokenIdTypes;
97
+ tokenAddress: Address;
98
+ }): ISubgraphQuery<TokenQueryResult> {
99
+ return {
100
+ query: `
101
+ ${FRAGMENTS}
102
+ query ($id: ID!) {
103
+ zoraCreateToken(id: $id) {
104
+ ...Token
105
+ }
106
+ }
107
+ `,
108
+ variables: {
109
+ id:
110
+ tokenId !== undefined
111
+ ? // Generic Token ID types all stringify down to the base numeric equivalent.
112
+ `${tokenAddress.toLowerCase()}-${tokenId}`
113
+ : `${tokenAddress.toLowerCase()}-0`,
114
+ },
115
+ parseResponseData: (responseData: any | undefined) =>
116
+ responseData?.zoraCreateToken,
117
+ };
118
+ }
119
+
120
+ export function buildContractTokensQuery({
121
+ tokenAddress,
122
+ }: {
123
+ tokenAddress: Address;
124
+ }): ISubgraphQuery<TokenQueryResult[]> {
125
+ return {
126
+ query: `
127
+ ${FRAGMENTS}
128
+ query ($contract: Bytes!) {
129
+ zoraCreateTokens(
130
+ where: {address: $contract}
131
+ ) {
132
+ ...Token
133
+ }
134
+ }
135
+ `,
136
+ variables: {
137
+ contract: tokenAddress.toLowerCase(),
138
+ },
139
+ parseResponseData: (responseData: any | undefined) =>
140
+ responseData?.zoraCreateTokens,
141
+ };
142
+ }
143
+
144
+ export type ISubgraphQuery<T> = {
145
+ query: string;
146
+ variables: Record<string, any>;
147
+ parseResponseData: (data: any | undefined) => T | undefined;
148
+ };
149
+
150
+ export function buildPremintsOfContractQuery({
151
+ tokenAddress,
152
+ }: {
153
+ tokenAddress: Address;
154
+ }): ISubgraphQuery<{ uid: string; tokenId: string }[]> {
155
+ return {
156
+ query: `
157
+ query ($contractAddress: Bytes!) {
158
+ premints(where:{contractAddress:$contractAddress}) {
159
+ uid
160
+ tokenId
161
+ }
162
+ }
163
+ `,
164
+ variables: {
165
+ contractAddress: tokenAddress.toLowerCase(),
166
+ },
167
+ parseResponseData: (responseData: any | undefined) =>
168
+ responseData?.premints,
169
+ };
170
+ }
@@ -0,0 +1,239 @@
1
+ import { Account, Address } from "viem";
2
+ import {
3
+ GenericTokenIdTypes,
4
+ SimulateContractParametersWithAccount,
5
+ } from "src/types";
6
+
7
+ export type MintParameters<MintType> = {
8
+ /** Type of the collection to be minted. */
9
+ mintType: MintType;
10
+ };
11
+
12
+ export type Erc1155MintParameters = MintParameters<"1155"> & {
13
+ /** Token id to mint */
14
+ tokenId: GenericTokenIdTypes;
15
+ };
16
+
17
+ export type Erc721MintParameters = MintParameters<"721">;
18
+
19
+ export type OnChainMintParameters =
20
+ | Erc1155MintParameters
21
+ | Erc721MintParameters;
22
+
23
+ export type PremintMintParameters = MintParameters<"premint"> & {
24
+ /** uid of the Premint to mint */
25
+ uid: number;
26
+ };
27
+
28
+ export type MintType = "1155" | "721" | "premint";
29
+
30
+ export type MintTypes =
31
+ | Erc1155MintParameters
32
+ | Erc721MintParameters
33
+ | PremintMintParameters;
34
+
35
+ export type GetMintParameters = MintTypes & {
36
+ /** Address of the contract that the item belongs to */
37
+ tokenContract: Address;
38
+ preferredSaleType?: SaleType;
39
+ };
40
+
41
+ export type GetMintsOfContractParameters = {
42
+ /** Address of the contract to get the tokens of */
43
+ tokenContract: Address;
44
+ preferredSaleType?: SaleType;
45
+ };
46
+
47
+ export const isOnChainMint = (mint: MintTypes): mint is OnChainMintParameters =>
48
+ mint.mintType !== "premint";
49
+
50
+ export const is1155Mint = (mint: MintTypes): mint is Erc1155MintParameters =>
51
+ mint.mintType === "1155";
52
+
53
+ export type MintParametersBase = {
54
+ /** Account to execute the mint */
55
+ minterAccount: Account | Address;
56
+ /** Quantity of tokens to mint. Defaults to 1 */
57
+ quantityToMint: number | bigint;
58
+ /** Comment to add to the mint */
59
+ mintComment?: string;
60
+ /** Address to receive the mint referral reward */
61
+ mintReferral?: Address;
62
+ /** Address to receive the minted tokens. Defaults to the minting account */
63
+ mintRecipient?: Address;
64
+ /** If this is a premint, the address to get the first minter reward */
65
+ firstMinter?: Address;
66
+ };
67
+
68
+ export type MakeMintParametersArgumentsBase = MintParametersBase & {
69
+ /** Premint contract address */
70
+ tokenContract: Address;
71
+ };
72
+
73
+ export type Make1155MintArguments = MakeMintParametersArgumentsBase &
74
+ Erc1155MintParameters & {
75
+ preferredSaleType?: SaleType;
76
+ };
77
+
78
+ export type Make721MintArguments = MakeMintParametersArgumentsBase &
79
+ Erc721MintParameters & {
80
+ preferredSaleType?: SaleType;
81
+ };
82
+
83
+ export type MakePremintMintParametersArguments =
84
+ MakeMintParametersArgumentsBase &
85
+ PremintMintParameters & {
86
+ /** Account to receive first minter reward, if this mint brings the premint onchain */
87
+ firstMinter?: Address;
88
+ };
89
+
90
+ export type MakeMintParametersArguments =
91
+ | Make1155MintArguments
92
+ | Make721MintArguments
93
+ | MakePremintMintParametersArguments;
94
+
95
+ export type GetMintCostsParameters = {
96
+ /** Address of token contract/collection to get the mint costs for */
97
+ collection: Address;
98
+ /** Quantity of tokens that will be minted */
99
+ quantityMinted: number | bigint;
100
+ } & MintTypes;
101
+
102
+ export type SaleType = "fixedPrice" | "erc20" | "premint";
103
+
104
+ type SaleStrategy<T extends SaleType> = {
105
+ saleType: T;
106
+ pricePerToken: bigint;
107
+ maxTokensPerAddress: bigint;
108
+ };
109
+
110
+ type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice"> & {
111
+ address: Address;
112
+ saleStart: string;
113
+ saleEnd: string;
114
+ };
115
+
116
+ type ERC20SaleStrategy = SaleStrategy<"erc20"> & {
117
+ address: Address;
118
+ saleStart: string;
119
+ saleEnd: string;
120
+ currency: Address;
121
+ };
122
+
123
+ type PremintSaleStrategy = SaleStrategy<"premint"> & {
124
+ duration: bigint;
125
+ };
126
+
127
+ export type SaleStrategies =
128
+ | FixedPriceSaleStrategy
129
+ | ERC20SaleStrategy
130
+ | PremintSaleStrategy;
131
+
132
+ export type OnchainSalesStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
133
+
134
+ export function isErc20SaleStrategy(
135
+ salesConfig: FixedPriceSaleStrategy | ERC20SaleStrategy | PremintSaleStrategy,
136
+ ): salesConfig is ERC20SaleStrategy {
137
+ return salesConfig.saleType === "erc20";
138
+ }
139
+
140
+ export type ContractInfo = {
141
+ /** Address of the contract */
142
+ address: Address;
143
+ /** Contract metadata uri */
144
+ URI: string;
145
+ /** Contract name */
146
+ name: string;
147
+ };
148
+
149
+ export type MintableBase = {
150
+ /** The contract the mintable belongs to */
151
+ contract: ContractInfo;
152
+ /** Token metadata URI */
153
+ tokenURI: string;
154
+ /** Price in eth to mint 1 item */
155
+ mintFeePerQuantity: bigint;
156
+ /** Creator of the mintable item */
157
+ creator: Address;
158
+ /** Maximum total number of items that can be minted */
159
+ maxSupply: bigint;
160
+ /** Total number of items minted so far */
161
+ totalMinted: bigint;
162
+ };
163
+
164
+ export type OnchainMintable = MintableBase & {
165
+ mintType: "721" | "1155";
166
+ tokenId?: bigint;
167
+ contractVersion: string;
168
+ };
169
+
170
+ export type PremintMintable = MintableBase & {
171
+ mintType: "premint";
172
+ uid: number;
173
+ };
174
+
175
+ export type OnchainSalesConfigAndTokenInfo = {
176
+ salesConfig: FixedPriceSaleStrategy | ERC20SaleStrategy;
177
+ } & OnchainMintable;
178
+
179
+ export type PremintSalesConfigAndTokenInfo = {
180
+ salesConfig: PremintSaleStrategy;
181
+ } & PremintMintable;
182
+
183
+ export type SalesConfigAndTokenInfo =
184
+ | OnchainSalesConfigAndTokenInfo
185
+ | PremintMintable;
186
+
187
+ export interface IOnchainMintGetter {
188
+ getMintable(params: {
189
+ tokenAddress: Address;
190
+ tokenId?: GenericTokenIdTypes;
191
+ preferredSaleType?: SaleType;
192
+ }): Promise<OnchainSalesConfigAndTokenInfo>;
193
+
194
+ getContractMintable(params: {
195
+ tokenAddress: Address;
196
+ }): Promise<OnchainSalesConfigAndTokenInfo[]>;
197
+
198
+ getContractPremintTokenIds(params: {
199
+ tokenAddress: Address;
200
+ }): Promise<{ tokenId: BigInt; uid: number }[]>;
201
+ }
202
+
203
+ export type MintCosts = {
204
+ /** The total of the mint fee, in eth */
205
+ mintFee: bigint;
206
+ /** If it is a paid or erc20 mint, the total price of the paid or erc20 mint in eth or erc20 value correspondingly. */
207
+ totalPurchaseCost: bigint;
208
+ /** If it is an erc20 mint, the erc20 address */
209
+ totalPurchaseCostCurrency?: Address;
210
+ /** The total cost in eth (mint fee + purchase cost) to mint */
211
+ totalCostEth: bigint;
212
+ };
213
+
214
+ export type Erc20Approval = {
215
+ /** ERC20 token address that must be approved */
216
+ erc20: Address;
217
+ /** Quantity of ERC20 that must be approved */
218
+ quantity: bigint;
219
+ /** Address that must be approved to transfer to */
220
+ approveTo: Address;
221
+ };
222
+
223
+ export type PrepareMintReturn = {
224
+ /** Prepared parameters to execute the mint transaction */
225
+ parameters: SimulateContractParametersWithAccount;
226
+ /** If an erc20 approval is necessary, information for the erc20 approval */
227
+ erc20Approval?: Erc20Approval;
228
+ /** Cost breakdown to mint the quantity of tokens */
229
+ costs: MintCosts;
230
+ };
231
+
232
+ export type PrepareMint = (params: MintParametersBase) => PrepareMintReturn;
233
+
234
+ export type MintableReturn = {
235
+ /** Token information */
236
+ token: SalesConfigAndTokenInfo;
237
+ /** Function that takes a quantity of items to mint and returns a prepared transaction and the costs to mint that quantity */
238
+ prepareMint: PrepareMint;
239
+ };
@@ -0,0 +1,14 @@
1
+ import * as semver from "semver";
2
+ export const contractSupportsNewMintFunction = (
3
+ contractVersion?: string | null,
4
+ ) => {
5
+ if (!contractVersion) {
6
+ return false;
7
+ }
8
+
9
+ // Try force-convert version format to semver format
10
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
11
+ if (!semVerContractVersion) return false;
12
+
13
+ return semver.gte(semVerContractVersion, "2.9.0");
14
+ };
@@ -77,7 +77,7 @@ const setupContractUsingPremint = async ({
77
77
  contractConfig.contractName = "Testing contract for MINTS";
78
78
 
79
79
  const contractAddress = await getPremintCollectionAddress({
80
- collection: contractConfig,
80
+ contract: contractConfig,
81
81
  publicClient,
82
82
  });
83
83
 
@@ -12,7 +12,7 @@ import {
12
12
  PremintConfigV2,
13
13
  } from "@zoralabs/protocol-deployments";
14
14
  import { ContractCreationConfig } from "src/preminter";
15
- import { makeSimulateContractParamaters } from "src/utils";
15
+ import { makeContractParameters } from "src/utils";
16
16
  import {
17
17
  Account,
18
18
  Address,
@@ -53,7 +53,7 @@ export const mintWithEthParams = ({
53
53
  pricePerMint: bigint;
54
54
  account: Address | Account;
55
55
  }) =>
56
- makeSimulateContractParamaters({
56
+ makeContractParameters({
57
57
  abi: zoraMintsManagerImplConfig.abi,
58
58
  address: zoraMintsManagerImplConfig.address[chainId],
59
59
  functionName: "mintWithEth",
@@ -152,7 +152,7 @@ export function collectWithMintsParams({
152
152
  mintArguments,
153
153
  });
154
154
 
155
- return makeSimulateContractParamaters({
155
+ return makeContractParameters({
156
156
  abi: zoraMints1155Config.abi,
157
157
  address: zoraMints1155Config.address[chainId],
158
158
  functionName: "transferBatchToManagerAndCall",
@@ -416,7 +416,7 @@ export function collectPremintV2WithMintsParams({
416
416
  ...rest,
417
417
  });
418
418
 
419
- return makeSimulateContractParamaters({
419
+ return makeContractParameters({
420
420
  abi: zoraMints1155Config.abi,
421
421
  address: zoraMints1155Config.address[chainId],
422
422
  functionName: "transferBatchToManagerAndCall",