@zoralabs/protocol-sdk 0.7.2-ALLOWLIST.0 → 0.7.2

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 (63) hide show
  1. package/.turbo/turbo-build.log +15 -0
  2. package/CHANGELOG.md +2 -2
  3. package/dist/apis/http-api-base.d.ts.map +1 -1
  4. package/dist/constants.d.ts +27 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/create/1155-create-helper.d.ts +0 -1
  7. package/dist/create/1155-create-helper.d.ts.map +1 -1
  8. package/dist/create/token-setup.d.ts +4 -3
  9. package/dist/create/token-setup.d.ts.map +1 -1
  10. package/dist/create/types.d.ts +4 -24
  11. package/dist/create/types.d.ts.map +1 -1
  12. package/dist/index.cjs +127 -237
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +0 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +128 -238
  17. package/dist/index.js.map +1 -1
  18. package/dist/mint/mint-queries.d.ts +1 -3
  19. package/dist/mint/mint-queries.d.ts.map +1 -1
  20. package/dist/mint/mint-transactions.d.ts +3 -5
  21. package/dist/mint/mint-transactions.d.ts.map +1 -1
  22. package/dist/mint/subgraph-mint-getter.d.ts +2 -1
  23. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  24. package/dist/mint/subgraph-queries.d.ts +14 -27
  25. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  26. package/dist/mint/types.d.ts +11 -22
  27. package/dist/mint/types.d.ts.map +1 -1
  28. package/dist/mints/mints-contracts.d.ts +16 -0
  29. package/dist/mints/mints-contracts.d.ts.map +1 -1
  30. package/dist/premint/premint-client.d.ts +8 -0
  31. package/dist/premint/premint-client.d.ts.map +1 -1
  32. package/package.json +1 -2
  33. package/src/apis/http-api-base.ts +0 -12
  34. package/src/constants.ts +36 -0
  35. package/src/create/1155-create-helper.test.ts +325 -0
  36. package/src/create/1155-create-helper.ts +0 -17
  37. package/src/create/token-setup.ts +19 -116
  38. package/src/create/types.ts +4 -32
  39. package/src/index.ts +0 -4
  40. package/src/mint/mint-client.test.ts +263 -0
  41. package/src/mint/mint-queries.ts +0 -6
  42. package/src/mint/mint-transactions.ts +8 -74
  43. package/src/mint/subgraph-mint-getter.ts +41 -17
  44. package/src/mint/subgraph-queries.ts +36 -39
  45. package/src/mint/types.ts +12 -38
  46. package/src/mints/mints-contracts.test.ts +529 -0
  47. package/src/mints/mints-eth-unwrapper-and-caller.test.ts +467 -0
  48. package/src/mints/mints-queries.test.ts +105 -0
  49. package/src/premint/premint-client.test.ts +290 -0
  50. package/src/premint/preminter.test.ts +866 -0
  51. package/test-integration/setup-test-contracts.ts +96 -0
  52. package/tsconfig.build.json +10 -0
  53. package/tsup.config.ts +12 -0
  54. package/dist/allow-list/allow-list-client.d.ts +0 -25
  55. package/dist/allow-list/allow-list-client.d.ts.map +0 -1
  56. package/dist/allow-list/types.d.ts +0 -14
  57. package/dist/allow-list/types.d.ts.map +0 -1
  58. package/dist/apis/generated/allow-list-api-types.d.ts +0 -288
  59. package/dist/apis/generated/allow-list-api-types.d.ts.map +0 -1
  60. package/src/allow-list/allow-list-client.ts +0 -102
  61. package/src/allow-list/types.ts +0 -15
  62. package/src/apis/generated/allow-list-api-types.ts +0 -288
  63. package/yarn-error.log +0 -8602
@@ -0,0 +1,263 @@
1
+ import { describe, expect } from "vitest";
2
+ import { Address, erc20Abi, parseAbi, parseEther } from "viem";
3
+ import { zora, zoraSepolia } from "viem/chains";
4
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
5
+ import { forkUrls, makeAnvilTest } from "src/anvil";
6
+ import { createCollectorClient } from "src/sdk";
7
+
8
+ const erc721ABI = parseAbi([
9
+ "function balanceOf(address owner) public view returns (uint256)",
10
+ ] as const);
11
+
12
+ describe("mint-helper", () => {
13
+ makeAnvilTest({
14
+ forkBlockNumber: 16028671,
15
+ forkUrl: forkUrls.zoraMainnet,
16
+ anvilChainId: zora.id,
17
+ })(
18
+ "mints a new 1155 token",
19
+ async ({ viemClients }) => {
20
+ const { testClient, walletClient, publicClient } = viemClients;
21
+ const creatorAccount = (await walletClient.getAddresses())[0]!;
22
+ await testClient.setBalance({
23
+ address: creatorAccount,
24
+ value: parseEther("2000"),
25
+ });
26
+ const targetContract: Address =
27
+ "0xa2fea3537915dc6c7c7a97a82d1236041e6feb2e";
28
+ const targetTokenId = 1n;
29
+ const collectorClient = createCollectorClient({
30
+ chainId: zora.id,
31
+ publicClient,
32
+ });
33
+
34
+ const { token: mintable, prepareMint } = await collectorClient.getToken({
35
+ tokenContract: targetContract,
36
+ mintType: "1155",
37
+ tokenId: targetTokenId,
38
+ });
39
+
40
+ mintable.maxSupply;
41
+ mintable.totalMinted;
42
+ mintable.tokenURI;
43
+ mintable;
44
+
45
+ const { parameters, costs } = prepareMint({
46
+ minterAccount: creatorAccount,
47
+ quantityToMint: 1,
48
+ });
49
+
50
+ expect(costs.totalCostEth).toBe(1n * parseEther("0.000777"));
51
+
52
+ const oldBalance = await publicClient.readContract({
53
+ abi: zoraCreator1155ImplABI,
54
+ address: targetContract,
55
+ functionName: "balanceOf",
56
+ args: [creatorAccount, targetTokenId],
57
+ });
58
+
59
+ const simulationResult = await publicClient.simulateContract(parameters);
60
+
61
+ const hash = await walletClient.writeContract(simulationResult.request);
62
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
63
+ const newBalance = await publicClient.readContract({
64
+ abi: zoraCreator1155ImplABI,
65
+ address: targetContract,
66
+ functionName: "balanceOf",
67
+ args: [creatorAccount, targetTokenId],
68
+ });
69
+ expect(receipt).to.not.be.null;
70
+ expect(oldBalance).to.be.equal(0n);
71
+ expect(newBalance).to.be.equal(1n);
72
+ },
73
+ 12 * 1000,
74
+ );
75
+
76
+ makeAnvilTest({
77
+ forkUrl: forkUrls.zoraMainnet,
78
+ forkBlockNumber: 6133407,
79
+ anvilChainId: zora.id,
80
+ })(
81
+ "mints a new 721 token",
82
+ async ({ viemClients }) => {
83
+ const { testClient, walletClient, publicClient } = viemClients;
84
+ const creatorAccount = (await walletClient.getAddresses())[0]!;
85
+ await testClient.setBalance({
86
+ address: creatorAccount,
87
+ value: parseEther("2000"),
88
+ });
89
+
90
+ const targetContract: Address =
91
+ "0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839";
92
+ const collectorClient = createCollectorClient({
93
+ chainId: zora.id,
94
+ publicClient,
95
+ });
96
+
97
+ const { prepareMint } = await collectorClient.getToken({
98
+ tokenContract: targetContract,
99
+ mintType: "721",
100
+ });
101
+
102
+ const quantityToMint = 3n;
103
+
104
+ const { parameters, costs } = prepareMint({
105
+ minterAccount: creatorAccount,
106
+ mintRecipient: creatorAccount,
107
+ quantityToMint,
108
+ });
109
+
110
+ expect(costs.totalPurchaseCost).toBe(quantityToMint * parseEther(".08"));
111
+ expect(costs.totalCostEth).toBe(
112
+ quantityToMint * (parseEther("0.08") + parseEther("0.000777")),
113
+ );
114
+
115
+ const oldBalance = await publicClient.readContract({
116
+ abi: erc721ABI,
117
+ address: targetContract,
118
+ functionName: "balanceOf",
119
+ args: [creatorAccount],
120
+ });
121
+
122
+ const simulated = await publicClient.simulateContract(parameters);
123
+
124
+ const hash = await walletClient.writeContract(simulated.request);
125
+
126
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
127
+ expect(receipt).not.to.be.null;
128
+
129
+ const newBalance = await publicClient.readContract({
130
+ abi: erc721ABI,
131
+ address: targetContract,
132
+ functionName: "balanceOf",
133
+ args: [creatorAccount],
134
+ });
135
+
136
+ expect(oldBalance).to.be.equal(0n);
137
+ expect(newBalance).to.be.equal(quantityToMint);
138
+ },
139
+ 12 * 1000,
140
+ );
141
+
142
+ makeAnvilTest({
143
+ forkUrl: forkUrls.zoraMainnet,
144
+ forkBlockNumber: 14484183,
145
+ anvilChainId: zora.id,
146
+ })(
147
+ "mints an 1155 token with an ERC20 token",
148
+ async ({ viemClients }) => {
149
+ const { testClient, walletClient, publicClient, chain } = viemClients;
150
+
151
+ const targetContract: Address =
152
+ "0x689bc305456c38656856d12469aed282fbd89fe0";
153
+ const targetTokenId = 16n;
154
+
155
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
156
+
157
+ const mockCollector = "0xb6b701878a1f80197dF2c209D0BDd292EA73164D";
158
+ await testClient.impersonateAccount({
159
+ address: mockCollector,
160
+ });
161
+
162
+ const { prepareMint } = await minter.getToken({
163
+ mintType: "1155",
164
+ tokenContract: targetContract,
165
+ tokenId: targetTokenId,
166
+ });
167
+
168
+ const quantityToMint = 1n;
169
+
170
+ const { parameters, erc20Approval, costs } = prepareMint({
171
+ minterAccount: mockCollector,
172
+ quantityToMint,
173
+ });
174
+
175
+ expect(erc20Approval).toBeDefined();
176
+ expect(costs.totalCostEth).toBe(0n);
177
+ expect(costs.totalPurchaseCost).toBe(
178
+ quantityToMint * 1000000000000000000n,
179
+ );
180
+ expect(costs.totalPurchaseCostCurrency).toBe(
181
+ "0xa6b280b42cb0b7c4a4f789ec6ccc3a7609a1bc39",
182
+ );
183
+
184
+ const beforeERC20Balance = await publicClient.readContract({
185
+ abi: erc20Abi,
186
+ address: erc20Approval!.erc20,
187
+ functionName: "balanceOf",
188
+ args: [mockCollector],
189
+ });
190
+
191
+ // execute the erc20 approval
192
+ const { request: erc20Request } = await publicClient.simulateContract({
193
+ abi: erc20Abi,
194
+ address: erc20Approval!.erc20,
195
+ functionName: "approve",
196
+ args: [erc20Approval!.approveTo, erc20Approval!.quantity],
197
+ account: mockCollector,
198
+ });
199
+
200
+ const approveHash = await walletClient.writeContract(erc20Request);
201
+ await publicClient.waitForTransactionReceipt({
202
+ hash: approveHash,
203
+ });
204
+
205
+ const beforeCollector1155Balance = await publicClient.readContract({
206
+ abi: zoraCreator1155ImplABI,
207
+ address: targetContract,
208
+ functionName: "balanceOf",
209
+ args: [mockCollector, targetTokenId],
210
+ });
211
+ expect(beforeCollector1155Balance).to.be.equal(0n);
212
+
213
+ // execute the mint
214
+ const simulationResult = await publicClient.simulateContract(parameters);
215
+ const hash = await walletClient.writeContract(simulationResult.request);
216
+ await publicClient.waitForTransactionReceipt({ hash });
217
+
218
+ const afterERC20Balance = await publicClient.readContract({
219
+ abi: erc20Abi,
220
+ address: erc20Approval!.erc20,
221
+ functionName: "balanceOf",
222
+ args: [mockCollector],
223
+ });
224
+
225
+ expect(beforeERC20Balance - afterERC20Balance).to.be.equal(
226
+ erc20Approval!.quantity,
227
+ );
228
+
229
+ const afterCollector1155Balance = await publicClient.readContract({
230
+ abi: zoraCreator1155ImplABI,
231
+ address: targetContract,
232
+ functionName: "balanceOf",
233
+ args: [mockCollector, targetTokenId],
234
+ });
235
+ expect(afterCollector1155Balance).to.be.equal(quantityToMint);
236
+ },
237
+ 12 * 1000,
238
+ );
239
+
240
+ makeAnvilTest({
241
+ forkUrl: forkUrls.zoraSepolia,
242
+ forkBlockNumber: 10294670,
243
+ anvilChainId: zoraSepolia.id,
244
+ })(
245
+ "gets onchain and premint mintables",
246
+ async ({ viemClients }) => {
247
+ const { publicClient, chain } = viemClients;
248
+
249
+ const targetContract: Address =
250
+ "0xa33e4228843092bb0f2fcbb2eb237bcefc1046b3";
251
+
252
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
253
+
254
+ const { tokens: mintables, contract } = await minter.getTokensOfContract({
255
+ tokenContract: targetContract,
256
+ });
257
+
258
+ expect(mintables.length).toBe(4);
259
+ expect(contract).toBeDefined();
260
+ },
261
+ 12 * 1000,
262
+ );
263
+ });
@@ -27,7 +27,6 @@ import {
27
27
  import { makeOnchainMintCall, parseMintCosts } from "./mint-transactions";
28
28
  import { buildPremintMintCall } from "src/premint/premint-client";
29
29
  import { IPublicClient } from "src/types";
30
- import { AllowListEntry } from "src/allow-list/types";
31
30
 
32
31
  export async function getMint({
33
32
  params,
@@ -130,13 +129,11 @@ export async function getMintsOfContract({
130
129
 
131
130
  export async function getMintCosts({
132
131
  params,
133
- allowListEntry,
134
132
  mintGetter,
135
133
  premintGetter,
136
134
  publicClient,
137
135
  }: {
138
136
  params: GetMintCostsParameters;
139
- allowListEntry?: Pick<AllowListEntry, "price">;
140
137
  mintGetter: IOnchainMintGetter;
141
138
  premintGetter: IPremintGetter;
142
139
  publicClient: IPublicClient;
@@ -153,7 +150,6 @@ export async function getMintCosts({
153
150
  mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
154
151
  salesConfig: salesConfigAndTokenInfo.salesConfig,
155
152
  quantityToMint: BigInt(quantityToMint),
156
- allowListEntry,
157
153
  });
158
154
  }
159
155
 
@@ -262,7 +258,6 @@ const makeOnchainPrepareMint =
262
258
  salesConfig: result.salesConfig,
263
259
  quantityToMint: BigInt(params.quantityToMint),
264
260
  mintFeePerQuantity: result.mintFeePerQuantity,
265
- allowListEntry: params.allowListEntry,
266
261
  }),
267
262
  });
268
263
 
@@ -291,7 +286,6 @@ const makePremintPrepareMint =
291
286
  mintFeePerQuantity: mintFee,
292
287
  quantityToMint: BigInt(params.quantityToMint),
293
288
  salesConfig: mintable.salesConfig,
294
- allowListEntry: params.allowListEntry,
295
289
  }),
296
290
  });
297
291
 
@@ -5,13 +5,12 @@ import {
5
5
  zeroAddress,
6
6
  Account,
7
7
  SimulateContractParameters,
8
- Hex,
9
8
  } from "viem";
10
9
  import {
11
10
  erc20MinterABI,
12
11
  zoraCreator1155ImplABI,
13
12
  } from "@zoralabs/protocol-deployments";
14
- import { zora721Abi } from "src/constants";
13
+ import { zora721Abi, zora1155LegacyAbi } from "src/constants";
15
14
  import {
16
15
  GenericTokenIdTypes,
17
16
  SimulateContractParametersWithAccount,
@@ -22,7 +21,6 @@ import { MakeMintParametersArgumentsBase } from "./types";
22
21
 
23
22
  import { contractSupportsNewMintFunction } from "./utils";
24
23
  import { OnchainSalesConfigAndTokenInfo } from "./types";
25
- import { AllowListEntry } from "src/allow-list/types";
26
24
 
27
25
  export function makeOnchainMintCall({
28
26
  token,
@@ -61,7 +59,6 @@ export function makePrepareMint1155TokenParams({
61
59
  mintReferral,
62
60
  mintRecipient,
63
61
  quantityToMint,
64
- allowListEntry,
65
62
  }: {
66
63
  salesConfigAndTokenInfo: MintableParameters;
67
64
  tokenId: GenericTokenIdTypes;
@@ -73,7 +70,6 @@ export function makePrepareMint1155TokenParams({
73
70
  | "mintReferral"
74
71
  | "quantityToMint"
75
72
  | "mintRecipient"
76
- | "allowListEntry"
77
73
  >): SimulateContractParameters<any, any, any, any, any, Address | Account> {
78
74
  const mintQuantity = BigInt(quantityToMint || 1);
79
75
 
@@ -81,7 +77,7 @@ export function makePrepareMint1155TokenParams({
81
77
 
82
78
  const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
83
79
 
84
- if (saleType === "fixedPrice" || saleType === "allowlist") {
80
+ if (saleType === "fixedPrice") {
85
81
  return makeEthMintCall({
86
82
  mintComment,
87
83
  minterAccount,
@@ -91,7 +87,6 @@ export function makePrepareMint1155TokenParams({
91
87
  salesConfigAndTokenInfo,
92
88
  tokenContract,
93
89
  tokenId,
94
- allowListEntry,
95
90
  });
96
91
  }
97
92
 
@@ -142,7 +137,6 @@ function makePrepareMint721TokenParams({
142
137
  mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
143
138
  salesConfig: salesConfigAndTokenInfo.salesConfig,
144
139
  quantityToMint: actualQuantityToMint,
145
- allowListEntry: undefined,
146
140
  }).totalCostEth;
147
141
 
148
142
  return makeContractParameters({
@@ -160,37 +154,6 @@ function makePrepareMint721TokenParams({
160
154
  });
161
155
  }
162
156
 
163
- function makeFixedPriceMinterArguments({
164
- mintTo,
165
- mintComment,
166
- }: {
167
- mintTo: Address;
168
- mintComment?: string;
169
- }) {
170
- return encodeAbiParameters(parseAbiParameters("address, string"), [
171
- mintTo,
172
- mintComment || "",
173
- ]);
174
- }
175
-
176
- function makeAllowListMinterArguments({
177
- mintTo,
178
- allowListEntry,
179
- }: {
180
- mintTo: Address;
181
- allowListEntry: AllowListEntry;
182
- }) {
183
- return encodeAbiParameters(
184
- parseAbiParameters("address, uint256, uint256, bytes32[]"),
185
- [
186
- mintTo,
187
- BigInt(allowListEntry.maxCanMint),
188
- allowListEntry.price,
189
- allowListEntry.proof,
190
- ],
191
- );
192
- }
193
-
194
157
  function makeEthMintCall({
195
158
  tokenContract,
196
159
  tokenId,
@@ -200,7 +163,6 @@ function makeEthMintCall({
200
163
  mintReferral,
201
164
  mintQuantity,
202
165
  mintTo,
203
- allowListEntry,
204
166
  }: {
205
167
  minterAccount: Account | Address;
206
168
  tokenContract: Address;
@@ -210,26 +172,17 @@ function makeEthMintCall({
210
172
  mintQuantity: bigint;
211
173
  mintComment?: string;
212
174
  mintReferral?: Address;
213
- allowListEntry?: AllowListEntry;
214
175
  }): SimulateContractParametersWithAccount {
215
176
  const mintValue = parseMintCosts({
216
177
  mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
217
178
  salesConfig: salesConfigAndTokenInfo.salesConfig,
218
179
  quantityToMint: mintQuantity,
219
- allowListEntry,
220
180
  }).totalCostEth;
221
181
 
222
- const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
223
- let minterArguments: Hex;
224
-
225
- if (saleType === "fixedPrice") {
226
- minterArguments = makeFixedPriceMinterArguments({ mintTo, mintComment });
227
- } else if (saleType === "allowlist") {
228
- if (!allowListEntry) throw new Error("Missing allowListEntry");
229
- minterArguments = makeAllowListMinterArguments({ mintTo, allowListEntry });
230
- } else {
231
- throw new Error("Unsupported sale type");
232
- }
182
+ const minterArguments = encodeAbiParameters(
183
+ parseAbiParameters("address, string"),
184
+ [mintTo, mintComment || ""],
185
+ );
233
186
 
234
187
  // if based on contract version it has the new mint function,
235
188
  // call the new mint function.
@@ -254,7 +207,7 @@ function makeEthMintCall({
254
207
 
255
208
  // otherwise call the deprecated mint function
256
209
  return makeContractParameters({
257
- abi: zoraCreator1155ImplABI,
210
+ abi: zora1155LegacyAbi,
258
211
  functionName: "mintWithRewards",
259
212
  account: minterAccount,
260
213
  value: mintValue,
@@ -270,37 +223,18 @@ function makeEthMintCall({
270
223
  });
271
224
  }
272
225
 
273
- function paidMintCost(
274
- salesConfig: SaleStrategies,
275
- allowListEntry?: Pick<AllowListEntry, "price">,
276
- ) {
277
- if (
278
- salesConfig.saleType === "erc20" ||
279
- salesConfig.saleType === "fixedPrice"
280
- ) {
281
- return salesConfig.pricePerToken;
282
- }
283
-
284
- if (allowListEntry) return allowListEntry.price;
285
-
286
- return 0n;
287
- }
288
-
289
226
  export function parseMintCosts({
290
227
  salesConfig,
291
228
  mintFeePerQuantity,
292
229
  quantityToMint,
293
- allowListEntry,
294
230
  }: {
295
231
  salesConfig: SaleStrategies;
296
232
  mintFeePerQuantity: bigint;
297
233
  quantityToMint: bigint;
298
- allowListEntry: Pick<AllowListEntry, "price"> | undefined;
299
234
  }): MintCosts {
300
235
  const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
301
236
 
302
- const tokenPurchaseCost =
303
- paidMintCost(salesConfig, allowListEntry) * quantityToMint;
237
+ const tokenPurchaseCost = BigInt(salesConfig.pricePerToken) * quantityToMint;
304
238
 
305
239
  const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig)
306
240
  ? salesConfig.currency
@@ -16,12 +16,14 @@ import {
16
16
  import { querySubgraphWithRetries } from "src/utils";
17
17
  import {
18
18
  buildContractTokensQuery,
19
+ buildGetDefaultMintPriceQuery,
19
20
  buildNftTokenSalesQuery,
20
21
  buildPremintsOfContractQuery,
21
22
  ISubgraphQuery,
22
23
  SalesStrategyResult,
23
24
  TokenQueryResult,
24
25
  } from "./subgraph-queries";
26
+ import * as semver from "semver";
25
27
 
26
28
  export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
27
29
  if (!networkConfigByChain[chainId]) {
@@ -53,23 +55,14 @@ function parseSalesConfig(
53
55
  pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
54
56
  };
55
57
  }
56
- if (targetStrategy.type === "PRESALE") {
57
- return {
58
- saleType: "allowlist",
59
- address: targetStrategy.presale.address,
60
- merkleRoot: targetStrategy.presale.merkleRoot,
61
- saleStart: targetStrategy.presale.presaleStart,
62
- saleEnd: targetStrategy.presale.presaleEnd,
63
- };
64
- }
65
58
 
66
59
  throw new Error("Unknown saleType");
67
60
  }
68
61
 
69
62
  function getSaleEnd(a: SalesStrategyResult) {
70
- if (a.type === "FIXED_PRICE") return BigInt(a.fixedPrice.saleEnd);
71
- if (a.type === "ERC_20_MINTER") return BigInt(a.erc20Minter.saleEnd);
72
- return BigInt(a.presale.presaleEnd);
63
+ return BigInt(
64
+ a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd,
65
+ );
73
66
  }
74
67
 
75
68
  function getTargetStrategy({
@@ -115,6 +108,7 @@ function getTargetStrategy({
115
108
 
116
109
  return targetStrategy;
117
110
  }
111
+
118
112
  export class SubgraphMintGetter implements IOnchainMintGetter {
119
113
  httpClient: IHttpClient;
120
114
  networkConfig: NetworkConfig;
@@ -124,6 +118,18 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
124
118
  this.networkConfig = getApiNetworkConfigForChain(chainId);
125
119
  }
126
120
 
121
+ async getContractMintFee(contract: TokenQueryResult["contract"]) {
122
+ const storedMintFee = BigInt(contract.mintFeePerQuantity);
123
+ if (!contractUsesMintCardsForMintFee(contract.contractVersion)) {
124
+ return storedMintFee;
125
+ }
126
+ const defaultMintFee = await this.querySubgraphWithRetries(
127
+ buildGetDefaultMintPriceQuery({}),
128
+ );
129
+
130
+ return defaultMintFee || storedMintFee;
131
+ }
132
+
127
133
  async querySubgraphWithRetries<T>({
128
134
  query,
129
135
  variables,
@@ -155,8 +161,11 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
155
161
  throw new Error("Cannot find token");
156
162
  }
157
163
 
164
+ const defaultMintFee = await this.getContractMintFee(token.contract);
165
+
158
166
  return parseTokenQueryResult({
159
- token,
167
+ token: token,
168
+ defaultMintFee,
160
169
  tokenId,
161
170
  preferredSaleType: saleType,
162
171
  });
@@ -175,7 +184,9 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
175
184
  }),
176
185
  );
177
186
 
178
- if (!tokens) return [];
187
+ if (!tokens || tokens.length === 0) return [];
188
+
189
+ const defaultMintFee = await this.getContractMintFee(tokens[0]!.contract);
179
190
 
180
191
  return tokens
181
192
  .filter((x) => x.tokenId !== "0")
@@ -184,6 +195,7 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
184
195
  token,
185
196
  tokenId: token.tokenId,
186
197
  preferredSaleType,
198
+ defaultMintFee,
187
199
  }),
188
200
  );
189
201
  }
@@ -212,10 +224,12 @@ function parseTokenQueryResult({
212
224
  token,
213
225
  tokenId,
214
226
  preferredSaleType,
227
+ defaultMintFee,
215
228
  }: {
216
229
  token: TokenQueryResult;
217
230
  tokenId?: GenericTokenIdTypes;
218
231
  preferredSaleType?: SaleType;
232
+ defaultMintFee: bigint;
219
233
  }): OnchainSalesConfigAndTokenInfo {
220
234
  const targetStrategy = getTargetStrategy({
221
235
  tokenId,
@@ -223,7 +237,7 @@ function parseTokenQueryResult({
223
237
  token,
224
238
  });
225
239
 
226
- const tokenInfo = parseTokenInfo(token);
240
+ const tokenInfo = parseTokenInfo(token, defaultMintFee);
227
241
 
228
242
  const salesConfig = parseSalesConfig(targetStrategy);
229
243
 
@@ -237,7 +251,17 @@ function parseTokenQueryResult({
237
251
  };
238
252
  }
239
253
 
240
- function parseTokenInfo(token: TokenQueryResult): OnchainMintable {
254
+ const contractUsesMintCardsForMintFee = (contractVersion: string) => {
255
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
256
+ if (!semVerContractVersion) return false;
257
+
258
+ return semver.gte(semVerContractVersion, "2.9.0");
259
+ };
260
+
261
+ function parseTokenInfo(
262
+ token: TokenQueryResult,
263
+ defaultMintFee: bigint,
264
+ ): OnchainMintable {
241
265
  return {
242
266
  contract: {
243
267
  address: token.contract.address,
@@ -250,7 +274,7 @@ function parseTokenInfo(token: TokenQueryResult): OnchainMintable {
250
274
  creator: token.creator,
251
275
  totalMinted: BigInt(token.totalMinted),
252
276
  maxSupply: BigInt(token.maxSupply),
253
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
277
+ mintFeePerQuantity: defaultMintFee,
254
278
  contractVersion: token.contract.contractVersion,
255
279
  };
256
280
  }