@zoralabs/protocol-sdk 0.7.2-ALLOWLIST.0 → 0.7.3-SPARKS.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 (54) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/dist/apis/http-api-base.d.ts.map +1 -1
  3. package/dist/constants.d.ts +27 -0
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/create/1155-create-helper.d.ts +0 -1
  6. package/dist/create/1155-create-helper.d.ts.map +1 -1
  7. package/dist/create/token-setup.d.ts +4 -3
  8. package/dist/create/token-setup.d.ts.map +1 -1
  9. package/dist/create/types.d.ts +4 -24
  10. package/dist/create/types.d.ts.map +1 -1
  11. package/dist/index.cjs +128 -238
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +0 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +130 -240
  16. package/dist/index.js.map +1 -1
  17. package/dist/mint/mint-queries.d.ts +1 -3
  18. package/dist/mint/mint-queries.d.ts.map +1 -1
  19. package/dist/mint/mint-transactions.d.ts +3 -5
  20. package/dist/mint/mint-transactions.d.ts.map +1 -1
  21. package/dist/mint/subgraph-mint-getter.d.ts +2 -1
  22. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  23. package/dist/mint/subgraph-queries.d.ts +14 -27
  24. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  25. package/dist/mint/types.d.ts +11 -22
  26. package/dist/mint/types.d.ts.map +1 -1
  27. package/dist/mints/mints-contracts.d.ts +14 -14
  28. package/dist/mints/mints-relay-example.d.ts +4 -4
  29. package/dist/mints/mints-relay-example.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 +2 -3
  33. package/src/apis/http-api-base.ts +0 -12
  34. package/src/constants.ts +36 -0
  35. package/src/create/1155-create-helper.ts +0 -17
  36. package/src/create/token-setup.ts +19 -116
  37. package/src/create/types.ts +4 -32
  38. package/src/index.ts +0 -4
  39. package/src/mint/mint-queries.ts +0 -6
  40. package/src/mint/mint-transactions.ts +8 -74
  41. package/src/mint/subgraph-mint-getter.ts +41 -17
  42. package/src/mint/subgraph-queries.ts +36 -39
  43. package/src/mint/types.ts +12 -38
  44. package/src/mints/mints-eth-unwrapper-and-caller.ts +2 -2
  45. package/src/mints/mints-relay-example.ts +10 -10
  46. package/dist/allow-list/allow-list-client.d.ts +0 -25
  47. package/dist/allow-list/allow-list-client.d.ts.map +0 -1
  48. package/dist/allow-list/types.d.ts +0 -14
  49. package/dist/allow-list/types.d.ts.map +0 -1
  50. package/dist/apis/generated/allow-list-api-types.d.ts +0 -288
  51. package/dist/apis/generated/allow-list-api-types.d.ts.map +0 -1
  52. package/src/allow-list/allow-list-client.ts +0 -102
  53. package/src/allow-list/types.ts +0 -15
  54. package/src/apis/generated/allow-list-api-types.ts +0 -288
@@ -4,17 +4,13 @@ import {
4
4
  zoraCreator1155ImplABI,
5
5
  zoraCreatorFixedPriceSaleStrategyABI,
6
6
  zoraCreatorFixedPriceSaleStrategyAddress,
7
- zoraCreatorMerkleMinterStrategyABI,
8
- zoraCreatorMerkleMinterStrategyAddress,
9
7
  } from "@zoralabs/protocol-deployments";
10
8
  import { Address, encodeFunctionData, zeroAddress, Hex } from "viem";
11
9
  import * as semver from "semver";
12
10
  import {
13
- AllowlistData,
14
11
  ContractProps,
15
12
  CreateNew1155TokenProps,
16
13
  New1155Token,
17
- SalesConfigOrAllowList,
18
14
  SalesConfigParamsType,
19
15
  } from "./types";
20
16
  import { OPEN_EDITION_MINT_SIZE } from "src/constants";
@@ -28,15 +24,16 @@ type SetupMintersProps = {
28
24
  tokenId: bigint;
29
25
  chainId: number;
30
26
  fundsRecipient: Address;
31
- salesConfigOrAllowList: SalesConfigOrAllowList;
27
+ salesConfig: Concrete<SalesConfigParamsType>;
32
28
  };
33
29
 
34
30
  // Sales end forever amount (uint64 max)
35
- const SALE_END_FOREVER = 18446744073709551615n;
36
31
 
37
32
  const saleSettingsOrDefault = (
38
33
  saleSettings?: SalesConfigParamsType,
39
34
  ): Concrete<SalesConfigParamsType> => {
35
+ const SALE_END_FOREVER = 18446744073709551615n;
36
+
40
37
  const DEFAULT_SALE_SETTINGS: Concrete<SalesConfigParamsType> = {
41
38
  currency: zeroAddress,
42
39
  // Free Mint
@@ -54,36 +51,6 @@ const saleSettingsOrDefault = (
54
51
  };
55
52
  };
56
53
 
57
- const allowListWithDefaults = (allowlist: AllowlistData) => {
58
- const defaultAllowListSettings: Concrete<
59
- Omit<AllowlistData, "presaleMerkleRoot">
60
- > = {
61
- // Sale start time – defaults to beginning of unix time
62
- saleStart: 0n,
63
- // This is the end of uint64, plenty of time
64
- saleEnd: SALE_END_FOREVER,
65
- };
66
-
67
- return {
68
- ...defaultAllowListSettings,
69
- ...allowlist,
70
- };
71
- };
72
-
73
- const getSalesConfigOrAllowListWithDefaults = ({
74
- salesConfig,
75
- allowlist,
76
- }: Pick<CreateNew1155TokenProps, "salesConfig" | "allowlist">) => {
77
- if (!allowlist) {
78
- return {
79
- salesConfig: saleSettingsOrDefault(salesConfig),
80
- };
81
- }
82
- return {
83
- allowlist: allowListWithDefaults(allowlist),
84
- };
85
- };
86
-
87
54
  function applyNew1155Defaults(
88
55
  props: CreateNew1155TokenProps,
89
56
  ownerAddress: Address,
@@ -101,11 +68,8 @@ function applyNew1155Defaults(
101
68
  ? OPEN_EDITION_MINT_SIZE
102
69
  : BigInt(props.maxSupply),
103
70
  royaltyBPS: props.royaltyBPS || 1000,
71
+ salesConfig: saleSettingsOrDefault(props.salesConfig),
104
72
  tokenMetadataURI: props.tokenMetadataURI,
105
- salesConfigOrAllowList: getSalesConfigOrAllowListWithDefaults({
106
- salesConfig: props.salesConfig,
107
- allowlist: props.allowlist,
108
- }),
109
73
  };
110
74
  }
111
75
 
@@ -223,84 +187,24 @@ function setupFixedPriceMinter({
223
187
  };
224
188
  }
225
189
 
226
- function setupAllowListMinter({
227
- chainId,
228
- tokenId: nextTokenId,
229
- allowlist,
230
- fundsRecipient,
231
- }: {
232
- chainId: number;
233
- tokenId: bigint;
234
- allowlist: Concrete<AllowlistData>;
235
- fundsRecipient: Address;
236
- }) {
237
- const merkleSaleStrategyAddress =
238
- zoraCreatorMerkleMinterStrategyAddress[
239
- chainId as keyof typeof zoraCreatorMerkleMinterStrategyAddress
240
- ];
241
-
242
- const merkleApproval = encodeFunctionData({
243
- abi: zoraCreator1155ImplABI,
244
- functionName: "addPermission",
245
- args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER],
246
- });
247
-
248
- const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x")
249
- ? allowlist.presaleMerkleRoot
250
- : (`0x${allowlist.presaleMerkleRoot}` as Hex);
251
-
252
- const saleData = encodeFunctionData({
253
- abi: zoraCreatorMerkleMinterStrategyABI,
254
- functionName: "setSale",
255
- args: [
256
- BigInt(nextTokenId),
257
- {
258
- presaleStart: allowlist.saleStart,
259
- presaleEnd: allowlist.saleEnd,
260
- merkleRoot,
261
- fundsRecipient: fundsRecipient,
262
- },
263
- ],
264
- });
265
-
266
- const callSaleMerkle = encodeFunctionData({
267
- abi: zoraCreator1155ImplABI,
268
- functionName: "callSale",
269
- args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData],
270
- });
271
-
272
- return {
273
- minter: merkleSaleStrategyAddress,
274
- setupActions: [merkleApproval, callSaleMerkle],
275
- };
276
- }
277
-
278
- export function setupMinters({
279
- salesConfigOrAllowList: { salesConfig, allowlist },
280
- ...rest
281
- }: SetupMintersProps): {
190
+ export function setupMinters({ salesConfig, ...rest }: SetupMintersProps): {
282
191
  minter: Address;
283
192
  setupActions: Hex[];
284
193
  } {
285
- if (salesConfig) {
286
- const { currency: currencyAddress } = salesConfig;
287
-
288
- if (currencyAddress === zeroAddress) {
289
- return setupFixedPriceMinter({
290
- ...salesConfig,
291
- ...rest,
292
- });
293
- } else {
294
- return setupErc20Minter({
295
- ...salesConfig,
296
- ...rest,
297
- });
298
- }
194
+ if (!salesConfig) throw new Error("No sales config for token");
195
+ const { currency: currencyAddress } = salesConfig;
196
+
197
+ if (currencyAddress === zeroAddress) {
198
+ return setupFixedPriceMinter({
199
+ ...salesConfig,
200
+ ...rest,
201
+ });
202
+ } else {
203
+ return setupErc20Minter({
204
+ ...salesConfig,
205
+ ...rest,
206
+ });
299
207
  }
300
- return setupAllowListMinter({
301
- allowlist: allowlist as Concrete<AllowlistData>,
302
- ...rest,
303
- });
304
208
  }
305
209
 
306
210
  function buildSetupNewToken({
@@ -431,8 +335,7 @@ export function constructCreate1155TokenCalls(
431
335
  tokenId: nextTokenId,
432
336
  chainId,
433
337
  fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
434
- salesConfigOrAllowList:
435
- new1155TokenPropsWithDefaults.salesConfigOrAllowList,
338
+ salesConfig: new1155TokenPropsWithDefaults.salesConfig,
436
339
  });
437
340
 
438
341
  const adminMintCall = makeAdminMintCall({
@@ -32,54 +32,26 @@ export type CreateNew1155Params = {
32
32
  token: CreateNew1155TokenProps;
33
33
  };
34
34
 
35
- export type AllowlistData = {
36
- saleStart?: bigint;
37
- saleEnd?: bigint;
38
- presaleMerkleRoot: `0x${string}`;
39
- };
40
-
41
- export type CreateNew1155TokenProps = {
35
+ export interface CreateNew1155TokenProps {
42
36
  maxSupply?: bigint | number;
43
37
  tokenMetadataURI: string;
44
38
  royaltyBPS?: number;
39
+ salesConfig?: SalesConfigParamsType;
45
40
  createReferral?: Address;
46
41
  mintToCreatorCount?: number;
47
42
  payoutRecipient?: Address;
48
- } & (
49
- | {
50
- salesConfig: SalesConfigParamsType;
51
- allowlist?: undefined;
52
- }
53
- | {
54
- salesConfig?: undefined;
55
- allowlist: AllowlistData;
56
- }
57
- | {
58
- salesConfig?: undefined;
59
- allowlist?: undefined;
60
- }
61
- );
43
+ }
62
44
 
63
45
  export interface ContractProps {
64
46
  nextTokenId: bigint;
65
47
  contractVersion: string;
66
48
  }
67
49
 
68
- export type SalesConfigOrAllowList =
69
- | {
70
- salesConfig: Concrete<SalesConfigParamsType>;
71
- allowlist?: undefined;
72
- }
73
- | {
74
- salesConfig: undefined;
75
- allowlist: Concrete<AllowlistData>;
76
- };
77
-
78
50
  export type New1155Token = {
79
51
  payoutRecipient: Address;
80
52
  createReferral: Address;
81
53
  maxSupply: bigint;
82
54
  royaltyBPS: number;
55
+ salesConfig: Concrete<SalesConfigParamsType>;
83
56
  tokenMetadataURI: string;
84
- salesConfigOrAllowList: SalesConfigOrAllowList;
85
57
  };
package/src/index.ts CHANGED
@@ -31,7 +31,3 @@ export * from "./create/types";
31
31
  export * from "./sdk";
32
32
 
33
33
  export * from "./ipfs";
34
-
35
- export { createAllowList } from "./allow-list/allow-list-client";
36
-
37
- export * from "./allow-list/types";
@@ -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
  }