@zoralabs/protocol-sdk 0.11.12 → 0.12.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 (88) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +10 -0
  3. package/dist/apis/network-config.d.ts +3 -0
  4. package/dist/apis/network-config.d.ts.map +1 -0
  5. package/dist/create/contract-setup.d.ts +3 -4
  6. package/dist/create/contract-setup.d.ts.map +1 -1
  7. package/dist/create/create-client.d.ts +53 -0
  8. package/dist/create/create-client.d.ts.map +1 -0
  9. package/dist/create/types.d.ts +11 -3
  10. package/dist/create/types.d.ts.map +1 -1
  11. package/dist/fixtures/contract-setup.d.ts +2 -2
  12. package/dist/fixtures/contract-setup.d.ts.map +1 -1
  13. package/dist/fixtures/rewards-query-results.d.ts +0 -1
  14. package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
  15. package/dist/fixtures/secondary.d.ts +3 -6
  16. package/dist/fixtures/secondary.d.ts.map +1 -1
  17. package/dist/index.cjs +1509 -1396
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +12 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1559 -1465
  22. package/dist/index.js.map +1 -1
  23. package/dist/mint/mint-client.d.ts +21 -9
  24. package/dist/mint/mint-client.d.ts.map +1 -1
  25. package/dist/mint/mint-queries.d.ts +24 -22
  26. package/dist/mint/mint-queries.d.ts.map +1 -1
  27. package/dist/mint/strategies-parsing.d.ts +28 -0
  28. package/dist/mint/strategies-parsing.d.ts.map +1 -0
  29. package/dist/mint/subgraph-mint-getter.d.ts +2 -6
  30. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  31. package/dist/mint/types.d.ts +25 -8
  32. package/dist/mint/types.d.ts.map +1 -1
  33. package/dist/premint/premint-api-client.d.ts.map +1 -1
  34. package/dist/premint/premint-client.d.ts.map +1 -1
  35. package/dist/rewards/rewards-client.d.ts +7 -3
  36. package/dist/rewards/rewards-client.d.ts.map +1 -1
  37. package/dist/rewards/rewards-queries.d.ts +14 -11
  38. package/dist/rewards/rewards-queries.d.ts.map +1 -1
  39. package/dist/rewards/subgraph-queries.d.ts +0 -1
  40. package/dist/rewards/subgraph-queries.d.ts.map +1 -1
  41. package/dist/rewards/subgraph-rewards-getter.d.ts +2 -8
  42. package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
  43. package/dist/sdk.d.ts +9 -3
  44. package/dist/sdk.d.ts.map +1 -1
  45. package/dist/secondary/secondary-client.d.ts +7 -8
  46. package/dist/secondary/secondary-client.d.ts.map +1 -1
  47. package/dist/secondary/uniswap/uniswapQuote.d.ts +0 -1
  48. package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -1
  49. package/dist/secondary/utils.d.ts +1 -2
  50. package/dist/secondary/utils.d.ts.map +1 -1
  51. package/dist/types.d.ts +6 -3
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/utils.d.ts +2 -2
  54. package/dist/utils.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/apis/network-config.ts +8 -0
  57. package/src/apis/subgraph-getter.ts +1 -1
  58. package/src/comments/comments.test.ts +11 -22
  59. package/src/create/contract-setup.ts +3 -4
  60. package/src/create/{1155-create-helper.test.ts → create-client.test.ts} +52 -88
  61. package/src/create/{1155-create-helper.ts → create-client.ts} +129 -63
  62. package/src/create/types.ts +13 -3
  63. package/src/fixtures/contract-setup.ts +3 -3
  64. package/src/fixtures/rewards-query-results.ts +2 -9
  65. package/src/fixtures/secondary.ts +16 -10
  66. package/src/index.ts +34 -4
  67. package/src/mint/mint-client.test.ts +37 -64
  68. package/src/mint/mint-client.ts +36 -32
  69. package/src/mint/mint-queries.ts +73 -54
  70. package/src/mint/strategies-parsing.ts +311 -0
  71. package/src/mint/subgraph-mint-getter.ts +4 -304
  72. package/src/mint/types.ts +36 -7
  73. package/src/premint/premint-api-client.ts +1 -1
  74. package/src/premint/premint-client.ts +1 -1
  75. package/src/rewards/rewards-client.test.ts +318 -21
  76. package/src/rewards/rewards-client.ts +15 -16
  77. package/src/rewards/rewards-queries.ts +116 -36
  78. package/src/rewards/subgraph-queries.ts +0 -2
  79. package/src/rewards/subgraph-rewards-getter.ts +3 -13
  80. package/src/sdk.ts +9 -7
  81. package/src/secondary/secondary-client.test.ts +39 -40
  82. package/src/secondary/secondary-client.ts +14 -33
  83. package/src/secondary/uniswap/uniswapQuote.ts +3 -2
  84. package/src/secondary/utils.ts +2 -2
  85. package/src/types.ts +15 -4
  86. package/src/utils.ts +9 -3
  87. package/dist/create/1155-create-helper.d.ts +0 -29
  88. package/dist/create/1155-create-helper.d.ts.map +0 -1
@@ -16,7 +16,6 @@ import {
16
16
  } from "@zoralabs/protocol-deployments";
17
17
  import { forkUrls, makeAnvilTest } from "src/anvil";
18
18
  import { writeContractWithRetries } from "src/test-utils";
19
- import { createCollectorClient, createCreatorClient } from "src/sdk";
20
19
  import { getAllowListEntry } from "src/allow-list/allow-list-client";
21
20
  import { SubgraphMintGetter } from "./subgraph-mint-getter";
22
21
  import { new1155ContractVersion } from "src/create/contract-setup";
@@ -26,6 +25,8 @@ import {
26
25
  } from "src/fixtures/contract-setup";
27
26
  import { ISubgraphQuerier } from "src/apis/subgraph-querier";
28
27
  import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
28
+ import { getToken, getTokensOfContract } from "./mint-queries";
29
+ import { create1155 } from "src/create/create-client";
29
30
 
30
31
  const erc721ABI = parseAbi([
31
32
  "function balanceOf(address owner) public view returns (uint256)",
@@ -47,7 +48,7 @@ const getCommentIdentifierFromReceipt = (
47
48
  return logs[0]!.args.commentIdentifier;
48
49
  };
49
50
 
50
- describe("mint-helper", () => {
51
+ describe("mint-client", () => {
51
52
  makeAnvilTest({
52
53
  forkBlockNumber: 16028124,
53
54
  forkUrl: forkUrls.zoraSepolia,
@@ -55,7 +56,7 @@ describe("mint-helper", () => {
55
56
  })(
56
57
  "mints a new 1155 token with a comment",
57
58
  async ({ viemClients }) => {
58
- const { testClient, walletClient, publicClient, chain } = viemClients;
59
+ const { testClient, walletClient, publicClient } = viemClients;
59
60
  const creatorAccount = (await walletClient.getAddresses())[0]!;
60
61
  await testClient.setBalance({
61
62
  address: creatorAccount,
@@ -64,19 +65,14 @@ describe("mint-helper", () => {
64
65
  const targetContract: Address =
65
66
  "0xD42557F24034b53e7340A40bb5813eF9Ba88F2b4";
66
67
  const targetTokenId = 3n;
67
- const collectorClient = createCollectorClient({
68
- chainId: chain.id,
68
+
69
+ const { prepareMint, primaryMintActive } = await getToken({
70
+ tokenContract: targetContract,
71
+ mintType: "1155",
72
+ tokenId: targetTokenId,
69
73
  publicClient,
70
74
  });
71
75
 
72
- const { prepareMint, primaryMintActive } = await collectorClient.getToken(
73
- {
74
- tokenContract: targetContract,
75
- mintType: "1155",
76
- tokenId: targetTokenId,
77
- },
78
- );
79
-
80
76
  expect(primaryMintActive).toBe(true);
81
77
  expect(prepareMint).toBeDefined();
82
78
 
@@ -143,18 +139,14 @@ describe("mint-helper", () => {
143
139
 
144
140
  const targetContract: Address =
145
141
  "0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839";
146
- const collectorClient = createCollectorClient({
147
- chainId: zora.id,
142
+
143
+ const { prepareMint, primaryMintActive } = await getToken({
144
+ tokenContract: targetContract,
145
+ mintType: "721",
148
146
  publicClient,
147
+ preferredSaleType: "fixedPrice",
149
148
  });
150
149
 
151
- const { prepareMint, primaryMintActive } = await collectorClient.getToken(
152
- {
153
- tokenContract: targetContract,
154
- mintType: "721",
155
- },
156
- );
157
-
158
150
  const quantityToMint = 3n;
159
151
 
160
152
  expect(primaryMintActive).toBe(true);
@@ -165,7 +157,7 @@ describe("mint-helper", () => {
165
157
  quantityToMint,
166
158
  });
167
159
 
168
- expect(costs.totalPurchaseCost).toBe(quantityToMint * parseEther(".08"));
160
+ expect(costs.totalPurchaseCost).toBe(quantityToMint * parseEther("0.08"));
169
161
  expect(costs.totalCostEth).toBe(
170
162
  quantityToMint * (parseEther("0.08") + parseEther("0.000777")),
171
163
  );
@@ -204,23 +196,22 @@ describe("mint-helper", () => {
204
196
  })(
205
197
  "mints an 1155 token with an ERC20 token",
206
198
  async ({ viemClients }) => {
207
- const { testClient, walletClient, publicClient, chain } = viemClients;
199
+ const { testClient, walletClient, publicClient } = viemClients;
208
200
 
209
201
  const targetContract: Address =
210
202
  "0x689bc305456c38656856d12469aed282fbd89fe0";
211
203
  const targetTokenId = 16n;
212
204
 
213
- const minter = createCollectorClient({ chainId: chain.id, publicClient });
214
-
215
205
  const mockCollector = "0xb6b701878a1f80197dF2c209D0BDd292EA73164D";
216
206
  await testClient.impersonateAccount({
217
207
  address: mockCollector,
218
208
  });
219
209
 
220
- const { prepareMint, primaryMintActive } = await minter.getToken({
210
+ const { prepareMint, primaryMintActive } = await getToken({
221
211
  mintType: "1155",
222
212
  tokenContract: targetContract,
223
213
  tokenId: targetTokenId,
214
+ publicClient,
224
215
  });
225
216
 
226
217
  const quantityToMint = 1n;
@@ -303,12 +294,7 @@ describe("mint-helper", () => {
303
294
  forkBlockNumber: 10970943,
304
295
  anvilChainId: zoraSepolia.id,
305
296
  })("can mint allowlist tokens", async ({ viemClients }) => {
306
- const { publicClient, chain, testClient, walletClient } = viemClients;
307
-
308
- const collectorClient = createCollectorClient({
309
- chainId: chain.id,
310
- publicClient,
311
- });
297
+ const { publicClient, testClient, walletClient } = viemClients;
312
298
 
313
299
  const targetContract = "0x440cF6a9f12b2f05Ec4Cee8eE0F317B0eC0c2eCD";
314
300
 
@@ -323,10 +309,11 @@ describe("mint-helper", () => {
323
309
  merkleRoot,
324
310
  });
325
311
 
326
- const { prepareMint, primaryMintActive } = await collectorClient.getToken({
312
+ const { prepareMint, primaryMintActive } = await getToken({
327
313
  mintType: "1155",
328
314
  tokenContract: targetContract,
329
315
  tokenId,
316
+ publicClient,
330
317
  });
331
318
 
332
319
  const minter = (await walletClient.getAddresses())[0]!;
@@ -368,21 +355,16 @@ describe("mint-helper", () => {
368
355
  })(
369
356
  "gets onchain and premint mintables",
370
357
  async ({ viemClients }) => {
371
- const { publicClient, chain } = viemClients;
358
+ const { publicClient } = viemClients;
372
359
 
373
360
  const targetContract: Address =
374
361
  "0xa33e4228843092bb0f2fcbb2eb237bcefc1046b3";
375
362
 
376
- const minter = createCollectorClient({
377
- chainId: chain.id,
363
+ const { tokens: mintables, contract } = await getTokensOfContract({
364
+ tokenContract: targetContract,
378
365
  publicClient,
379
366
  });
380
367
 
381
- const { tokens: mintables, contract } =
382
- await minter.getTokensOfContract({
383
- tokenContract: targetContract,
384
- });
385
-
386
368
  expect(mintables.length).toBe(4);
387
369
  expect(contract).toBeDefined();
388
370
  },
@@ -400,24 +382,19 @@ describe("mint-helper", () => {
400
382
 
401
383
  const creator = (await walletClient.getAddresses())[0]!;
402
384
 
403
- const creatorClient = createCreatorClient({
404
- chainId: chain.id,
385
+ const { parameters, contractAddress, newTokenId } = await create1155({
386
+ account: creator,
387
+ contract: {
388
+ name: "Test Timed Sale",
389
+ uri: demoContractMetadataURI,
390
+ defaultAdmin: creator,
391
+ },
392
+ token: {
393
+ tokenMetadataURI: demoTokenMetadataURI,
394
+ },
405
395
  publicClient,
406
396
  });
407
397
 
408
- const { parameters, contractAddress, newTokenId } =
409
- await creatorClient.create1155({
410
- account: creator,
411
- contract: {
412
- name: "Test Timed Sale",
413
- uri: demoContractMetadataURI,
414
- defaultAdmin: creator,
415
- },
416
- token: {
417
- tokenMetadataURI: demoTokenMetadataURI,
418
- },
419
- });
420
-
421
398
  const { request: createRequest } =
422
399
  await publicClient.simulateContract(parameters);
423
400
  await writeContractWithRetries({
@@ -446,12 +423,6 @@ describe("mint-helper", () => {
446
423
  const mintGetter = new SubgraphMintGetter(chain.id);
447
424
  mintGetter.subgraphQuerier.query = mockQuery;
448
425
 
449
- const collectorClient = createCollectorClient({
450
- chainId: chain.id,
451
- publicClient,
452
- mintGetter,
453
- });
454
-
455
426
  const collector = (await walletClient.getAddresses())[1]!;
456
427
 
457
428
  const {
@@ -459,10 +430,12 @@ describe("mint-helper", () => {
459
430
  primaryMintActive,
460
431
  primaryMintEnd,
461
432
  secondaryMarketActive,
462
- } = await collectorClient.getToken({
433
+ } = await getToken({
463
434
  mintType: "1155",
464
435
  tokenContract: contractAddress,
465
436
  tokenId: newTokenId,
437
+ publicClient,
438
+ mintGetter,
466
439
  });
467
440
 
468
441
  expect(primaryMintActive).toBe(true);
@@ -1,16 +1,20 @@
1
1
  import { Address } from "viem";
2
2
  import { IPublicClient } from "src/types";
3
3
  import {
4
- GetMintParameters,
4
+ GetMintParametersArguments,
5
5
  IOnchainMintGetter,
6
+ MakeMintParameters,
6
7
  MintCosts,
7
8
  PrepareMintReturn,
8
9
  SaleType,
9
10
  } from "./types";
10
- import { MakeMintParametersArguments, GetMintCostsParameters } from "./types";
11
+ import {
12
+ MakeMintParametersArguments,
13
+ GetMintCostsParameterArguments,
14
+ } from "./types";
11
15
  import { IPremintGetter } from "src/premint/premint-api-client";
12
16
 
13
- import { getMint, getMintCosts, getMintsOfContract } from "./mint-queries";
17
+ import { getToken, getMintCosts, getTokensOfContract } from "./mint-queries";
14
18
 
15
19
  class MintError extends Error {}
16
20
  class MintInactiveError extends Error {}
@@ -20,26 +24,28 @@ export const Errors = {
20
24
  MintInactiveError,
21
25
  };
22
26
 
27
+ /**
28
+ * @deprecated Please use functions directly without creating a client.
29
+ * Example: Instead of `new MintClient().mint()`, use `mint()`
30
+ * Import the functions you need directly from their respective modules:
31
+ * import { mint, getToken, getTokensOfContract, getMintCosts } from '@zoralabs/protocol-sdk'
32
+ */
23
33
  export class MintClient {
24
34
  private readonly publicClient: IPublicClient;
25
35
  private readonly mintGetter: IOnchainMintGetter;
26
36
  private readonly premintGetter: IPremintGetter;
27
- private readonly chainId: number;
28
37
  constructor({
29
38
  publicClient,
30
39
  premintGetter,
31
40
  mintGetter,
32
- chainId,
33
41
  }: {
34
42
  publicClient: IPublicClient;
35
43
  premintGetter: IPremintGetter;
36
44
  mintGetter: IOnchainMintGetter;
37
- chainId: number;
38
45
  }) {
39
46
  this.publicClient = publicClient;
40
47
  this.mintGetter = mintGetter;
41
48
  this.premintGetter = premintGetter;
42
- this.chainId = chainId;
43
49
  }
44
50
 
45
51
  /**
@@ -53,27 +59,25 @@ export class MintClient {
53
59
  parameters: MakeMintParametersArguments,
54
60
  ): Promise<PrepareMintReturn> {
55
61
  return mint({
56
- parameters,
62
+ ...parameters,
57
63
  publicClient: this.publicClient,
58
64
  mintGetter: this.mintGetter,
59
65
  premintGetter: this.premintGetter,
60
- chainId: this.chainId,
61
66
  });
62
67
  }
63
68
 
64
69
  /**
65
70
  * Gets an 1155, 721, or premint, and returns both information about it, and a function
66
71
  * that can be used to build a mint transaction for a quantity of items to mint.
67
- * @param parameters - Token to get {@link GetMintParameters}
72
+ * @param parameters - Token to get {@link GetMintParametersArguments}
68
73
  * @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
69
74
  */
70
- async get(parameters: GetMintParameters) {
71
- return getMint({
72
- params: parameters,
75
+ async get(parameters: GetMintParametersArguments) {
76
+ return getToken({
77
+ ...parameters,
73
78
  mintGetter: this.mintGetter,
74
79
  premintGetter: this.premintGetter,
75
80
  publicClient: this.publicClient,
76
- chainId: this.chainId,
77
81
  });
78
82
  }
79
83
 
@@ -87,21 +91,22 @@ export class MintClient {
87
91
  tokenContract: Address;
88
92
  preferredSaleType?: SaleType;
89
93
  }) {
90
- return getMintsOfContract({
91
- params,
94
+ return getTokensOfContract({
95
+ ...params,
92
96
  mintGetter: this.mintGetter,
93
97
  premintGetter: this.premintGetter,
94
98
  publicClient: this.publicClient,
95
- chainId: this.chainId,
96
99
  });
97
100
  }
98
101
 
99
102
  /**
100
103
  * Gets the costs to mint the quantity of tokens specified for a mint.
101
- * @param parameters - Parameters for the mint {@link GetMintCostsParameters}
104
+ * @param parameters - Parameters for the mint {@link GetMintCostsParameterArguments}
102
105
  * @returns Costs to mint the quantity of tokens specified
103
106
  */
104
- async getMintCosts(parameters: GetMintCostsParameters): Promise<MintCosts> {
107
+ async getMintCosts(
108
+ parameters: GetMintCostsParameterArguments,
109
+ ): Promise<MintCosts> {
105
110
  return getMintCosts({
106
111
  params: parameters,
107
112
  mintGetter: this.mintGetter,
@@ -111,25 +116,24 @@ export class MintClient {
111
116
  }
112
117
  }
113
118
 
114
- async function mint({
115
- parameters,
119
+ /**
120
+ * Returns the parameters needed to prepare a transaction mint a token.
121
+ * Works with premint, onchain 1155, and onchain 721.
122
+ *
123
+ * @param parameters - Parameters for collecting the token {@link MakeMintParameters}
124
+ * @returns Parameters for simulating/executing the mint transaction, any necessary erc20 approval, and costs to mint
125
+ */
126
+ export async function mint({
116
127
  publicClient,
117
128
  mintGetter,
118
129
  premintGetter,
119
- chainId,
120
- }: {
121
- parameters: MakeMintParametersArguments;
122
- publicClient: IPublicClient;
123
- mintGetter: IOnchainMintGetter;
124
- premintGetter: IPremintGetter;
125
- chainId: number;
126
- }): Promise<PrepareMintReturn> {
127
- const { prepareMint, primaryMintActive } = await getMint({
128
- params: parameters,
130
+ ...parameters
131
+ }: MakeMintParameters): Promise<PrepareMintReturn> {
132
+ const { prepareMint, primaryMintActive } = await getToken({
133
+ ...parameters,
129
134
  mintGetter,
130
135
  premintGetter,
131
136
  publicClient,
132
- chainId,
133
137
  });
134
138
 
135
139
  if (!primaryMintActive) {
@@ -1,10 +1,12 @@
1
- import { IPremintGetter } from "src/premint/premint-api-client";
1
+ import {
2
+ IPremintGetter,
3
+ PremintAPIClient,
4
+ } from "src/premint/premint-api-client";
2
5
  import {
3
6
  ContractInfo,
4
7
  Erc20Approval,
5
- GetMintCostsParameters,
8
+ GetMintCostsParameterArguments,
6
9
  GetMintParameters,
7
- GetMintsOfContractParameters,
8
10
  IOnchainMintGetter,
9
11
  MintParametersBase,
10
12
  MintableReturn,
@@ -14,6 +16,8 @@ import {
14
16
  is1155Mint,
15
17
  isOnChainMint,
16
18
  GetMintableReturn,
19
+ GetMintsOfContractParameters,
20
+ WithPublicClientAndRequiredGetters,
17
21
  } from "./types";
18
22
  import { Address, zeroAddress } from "viem";
19
23
  import {
@@ -27,45 +31,51 @@ import {
27
31
  } from "src/premint/conversions";
28
32
  import { makeOnchainMintCall, parseMintCosts } from "./mint-transactions";
29
33
  import { buildPremintMintCall } from "src/premint/premint-client";
30
- import { IPublicClient } from "src/types";
31
34
  import { AllowListEntry } from "src/allow-list/types";
32
35
  import { Concrete } from "src/utils";
33
-
34
- export async function getMint({
35
- params,
36
- mintGetter,
37
- premintGetter,
38
- publicClient,
39
- chainId,
40
- }: {
41
- params: GetMintParameters;
42
- mintGetter: IOnchainMintGetter;
43
- premintGetter: IPremintGetter;
44
- publicClient: IPublicClient;
45
- chainId: number;
46
- }): Promise<MintableReturn> {
47
- const { tokenContract } = params;
36
+ import { parseAndFilterTokenQueryResult } from "./strategies-parsing";
37
+ import { SubgraphMintGetter } from "./subgraph-mint-getter";
38
+
39
+ /**
40
+ * Gets an 1155, 721, or premint, and returns both information about it, and a function
41
+ * that can be used to build a mint transaction for a quantity of items to mint.
42
+ * @param parameters - Token to get {@link GetMintParameters}
43
+ * @returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
44
+ */
45
+ export async function getToken(
46
+ params: GetMintParameters,
47
+ ): Promise<MintableReturn> {
48
+ const { premintGetter, publicClient } = params;
49
+ const chainId = publicClient.chain.id;
48
50
  if (isOnChainMint(params)) {
49
51
  const tokenId = is1155Mint(params) ? params.tokenId : undefined;
50
52
  const blockTime = (await publicClient.getBlock()).timestamp;
51
- const result = await mintGetter.getMintable({
53
+ const mintGetterOrDefault =
54
+ params.mintGetter ?? new SubgraphMintGetter(chainId);
55
+ const result = await mintGetterOrDefault.getMintable({
56
+ tokenId,
57
+ tokenAddress: params.tokenContract,
58
+ });
59
+
60
+ const token = parseAndFilterTokenQueryResult({
61
+ token: result,
52
62
  tokenId,
53
- tokenAddress: tokenContract,
54
63
  preferredSaleType: params.preferredSaleType,
55
- blockTime: blockTime,
64
+ blockTime,
56
65
  });
57
66
 
58
- return toMintableReturn(result, chainId);
67
+ return toMintableReturn(token, chainId);
59
68
  }
60
69
 
61
- const premint = await premintGetter.get({
62
- collectionAddress: tokenContract,
70
+ const premintGetterOrDefault = premintGetter ?? new PremintAPIClient(chainId);
71
+ const premint = await premintGetterOrDefault.get({
72
+ collectionAddress: params.tokenContract,
63
73
  uid: params.uid,
64
74
  });
65
75
 
66
76
  const mintFee = await getPremintMintFee({
67
77
  publicClient,
68
- tokenContract: tokenContract,
78
+ tokenContract: params.tokenContract,
69
79
  });
70
80
 
71
81
  return toPremintMintReturn({ premint, mintFee });
@@ -100,28 +110,33 @@ export async function getPremintsOfCollectionWithTokenIds({
100
110
  };
101
111
  }
102
112
 
103
- export async function getMintsOfContract({
104
- params,
113
+ /**
114
+ * Gets onchain and premint tokens of an 1155 contract. For each token returns both information about it, and a function
115
+ * that can be used to build a mint transaction for a quantity of items to mint.
116
+ * @param parameters - Contract address to get tokens for {@link GetMintsOfContractParameters}
117
+ * @returns Array of tokens, each containing information about the token and a function to build a mint transaction.
118
+ */
119
+ export async function getTokensOfContract({
105
120
  mintGetter,
106
121
  premintGetter,
107
122
  publicClient,
108
- chainId,
109
- }: {
110
- params: GetMintsOfContractParameters;
111
- mintGetter: IOnchainMintGetter;
112
- premintGetter: IPremintGetter;
113
- publicClient: IPublicClient;
114
- chainId: number;
115
- }): Promise<{ contract?: ContractInfo; tokens: MintableReturn[] }> {
123
+ ...params
124
+ }: GetMintsOfContractParameters): Promise<{
125
+ contract?: ContractInfo;
126
+ tokens: MintableReturn[];
127
+ }> {
128
+ const chainId = publicClient.chain.id;
129
+ const mintGetterOrDefault: IOnchainMintGetter =
130
+ mintGetter ?? new SubgraphMintGetter(chainId);
116
131
  const onchainMints = (
117
- await mintGetter.getContractMintable({
132
+ await mintGetterOrDefault.getContractMintable({
118
133
  tokenAddress: params.tokenContract,
119
134
  })
120
135
  ).map((result) => toMintableReturn(result, chainId));
121
136
 
122
137
  const offchainMints = await getPremintsOfContractMintable({
123
- mintGetter,
124
- premintGetter,
138
+ mintGetter: mintGetterOrDefault,
139
+ premintGetter: premintGetter ?? new PremintAPIClient(chainId),
125
140
  publicClient,
126
141
  params: {
127
142
  tokenContract: params.tokenContract,
@@ -136,35 +151,42 @@ export async function getMintsOfContract({
136
151
  };
137
152
  }
138
153
 
154
+ /**
155
+ * Gets the costs to mint the quantity of tokens specified for a mint.
156
+ * @param parameters - Parameters for the mint {@link GetMintCostsParameterArguments}
157
+ * @returns Costs to mint the quantity of tokens specified
158
+ */
139
159
  export async function getMintCosts({
140
160
  params,
141
161
  allowListEntry,
142
162
  mintGetter,
143
163
  premintGetter,
144
164
  publicClient,
145
- }: {
146
- params: GetMintCostsParameters;
165
+ }: WithPublicClientAndRequiredGetters<{
166
+ params: GetMintCostsParameterArguments;
147
167
  allowListEntry?: Pick<AllowListEntry, "price">;
148
- mintGetter: IOnchainMintGetter;
149
- premintGetter: IPremintGetter;
150
- publicClient: IPublicClient;
151
- }) {
168
+ }>) {
152
169
  const { quantityMinted: quantityToMint, collection } = params;
153
170
  if (isOnChainMint(params)) {
154
171
  const tokenId = is1155Mint(params) ? params.tokenId : undefined;
155
172
  const blockTime = (await publicClient.getBlock()).timestamp;
156
- const { salesConfigAndTokenInfo } = await mintGetter.getMintable({
173
+ const result = await mintGetter.getMintable({
157
174
  tokenId,
158
175
  tokenAddress: collection,
176
+ });
177
+
178
+ const token = parseAndFilterTokenQueryResult({
179
+ token: result,
180
+ tokenId,
159
181
  blockTime,
160
182
  });
161
183
 
162
- if (!salesConfigAndTokenInfo.salesConfig) {
184
+ if (!token.salesConfigAndTokenInfo.salesConfig) {
163
185
  throw new Error("No valid sales config found for token");
164
186
  }
165
187
 
166
188
  return parseMintCosts({
167
- salesConfig: salesConfigAndTokenInfo.salesConfig,
189
+ salesConfig: token.salesConfigAndTokenInfo.salesConfig,
168
190
  quantityToMint: BigInt(quantityToMint),
169
191
  allowListEntry,
170
192
  });
@@ -184,12 +206,9 @@ async function getPremintsOfContractMintable({
184
206
  premintGetter,
185
207
  publicClient,
186
208
  params,
187
- }: {
188
- mintGetter: IOnchainMintGetter;
189
- premintGetter: IPremintGetter;
190
- publicClient: IPublicClient;
209
+ }: WithPublicClientAndRequiredGetters<{
191
210
  params: { tokenContract: Address };
192
- }): Promise<MintableReturn[]> {
211
+ }>): Promise<MintableReturn[]> {
193
212
  const { premints, collection } = await getPremintsOfCollectionWithTokenIds({
194
213
  mintGetter,
195
214
  premintGetter,
@@ -295,7 +314,7 @@ export const makeOnchainPrepareMint =
295
314
  };
296
315
  };
297
316
 
298
- function toMintableReturn(
317
+ export function toMintableReturn(
299
318
  result: GetMintableReturn,
300
319
  chainId: number,
301
320
  ): MintableReturn {