@zoralabs/protocol-sdk 0.11.8 → 0.11.10

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 (40) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +17 -0
  3. package/dist/create/mint-from-create.d.ts +2 -1
  4. package/dist/create/mint-from-create.d.ts.map +1 -1
  5. package/dist/index.cjs +202 -48
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +208 -50
  8. package/dist/index.js.map +1 -1
  9. package/dist/mint/mint-client.d.ts +3 -1
  10. package/dist/mint/mint-client.d.ts.map +1 -1
  11. package/dist/mint/mint-queries.d.ts +5 -3
  12. package/dist/mint/mint-queries.d.ts.map +1 -1
  13. package/dist/mint/mint-transactions.d.ts +4 -2
  14. package/dist/mint/mint-transactions.d.ts.map +1 -1
  15. package/dist/premint/premint-client.d.ts +27 -27
  16. package/dist/sdk.d.ts.map +1 -1
  17. package/dist/secondary/secondary-client.d.ts +2 -1
  18. package/dist/secondary/secondary-client.d.ts.map +1 -1
  19. package/dist/secondary/types.d.ts +1 -0
  20. package/dist/secondary/types.d.ts.map +1 -1
  21. package/dist/sparks/sparks-contracts.d.ts +1 -1
  22. package/dist/test-utils.d.ts +5 -1
  23. package/dist/test-utils.d.ts.map +1 -1
  24. package/package.json +4 -4
  25. package/src/comments/comments.test.ts +338 -0
  26. package/src/create/1155-create-helper.test.ts +6 -12
  27. package/src/create/1155-create-helper.ts +2 -0
  28. package/src/create/mint-from-create.ts +3 -0
  29. package/src/create/minter-defaults.ts +7 -7
  30. package/src/mint/mint-client.test.ts +67 -30
  31. package/src/mint/mint-client.ts +10 -1
  32. package/src/mint/mint-queries.ts +16 -5
  33. package/src/mint/mint-transactions.ts +80 -16
  34. package/src/sdk.ts +1 -0
  35. package/src/secondary/secondary-client.test.ts +248 -2
  36. package/src/secondary/secondary-client.ts +136 -6
  37. package/src/secondary/types.ts +2 -0
  38. package/src/sparks/sparks-contracts.ts +1 -1
  39. package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -0
  40. package/src/test-utils.ts +19 -0
@@ -0,0 +1,338 @@
1
+ import { describe, expect } from "vitest";
2
+ import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
3
+ import { base, zora } from "viem/chains";
4
+ import {
5
+ commentsABI,
6
+ commentsAddress,
7
+ emptyCommentIdentifier,
8
+ PermitComment,
9
+ PermitSparkComment,
10
+ sparkValue,
11
+ CommentIdentifier,
12
+ permitSparkCommentTypedDataDefinition,
13
+ permitMintAndCommentTypedDataDefinition,
14
+ PermitMintAndComment,
15
+ callerAndCommenterAddress as callerAndCommenterAddresses,
16
+ callerAndCommenterABI,
17
+ zoraCreator1155ImplABI,
18
+ } from "@zoralabs/protocol-deployments";
19
+ import {
20
+ Address,
21
+ zeroAddress,
22
+ parseEther,
23
+ TransactionReceipt,
24
+ parseEventLogs,
25
+ hashTypedData,
26
+ } from "viem";
27
+ import { createCreatorClient } from "src/sdk";
28
+ import { randomNewContract, waitForSuccess } from "src/test-utils";
29
+ import { permitCommentTypedDataDefinition } from "@zoralabs/protocol-deployments";
30
+ import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
31
+ import { randomNonce, thirtySecondsFromNow } from "src/test-utils";
32
+
33
+ const getCommentIdentifierFromReceipt = (
34
+ receipt: TransactionReceipt,
35
+ ): CommentIdentifier => {
36
+ const logs = parseEventLogs({
37
+ abi: commentsABI,
38
+ logs: receipt.logs,
39
+ eventName: "Commented",
40
+ });
41
+
42
+ if (logs.length === 0) {
43
+ throw new Error("No Commented event found in receipt");
44
+ }
45
+
46
+ return logs[0]!.args.commentIdentifier;
47
+ };
48
+
49
+ // todo: move this to protocol-deployments
50
+ describe("comments", () => {
51
+ makeAnvilTest({
52
+ forkUrl: forkUrls.zoraMainnet,
53
+ forkBlockNumber: 21297211,
54
+ anvilChainId: zora.id,
55
+ })(
56
+ "can sign and execute a cross-chain comment, and sign and execute a cross-chain spark comment",
57
+ async ({
58
+ viemClients: { publicClient, walletClient, chain, testClient },
59
+ }) => {
60
+ // Get the chain ID and set up addresses for different roles
61
+ const chainId = chain.id;
62
+ const [
63
+ collectorAddress,
64
+ creatorAddress,
65
+ executorAddress,
66
+ sparkerAddress,
67
+ ] = (await walletClient.getAddresses()!) as [
68
+ Address,
69
+ Address,
70
+ Address,
71
+ Address,
72
+ ];
73
+
74
+ // Create a creator client for interacting with the protocol
75
+ const creatorClient = createCreatorClient({
76
+ chainId,
77
+ publicClient,
78
+ });
79
+
80
+ // Step 1: Create a new 1155 contract and token
81
+ const { contractAddress, newTokenId, parameters, prepareMint } =
82
+ await creatorClient.create1155({
83
+ contract: randomNewContract(),
84
+ token: {
85
+ tokenMetadataURI: demoTokenMetadataURI,
86
+ },
87
+ account: creatorAddress,
88
+ });
89
+
90
+ // Deploy the new contract
91
+ const { request } = await publicClient.simulateContract(parameters);
92
+ await writeContractWithRetries({
93
+ request,
94
+ walletClient,
95
+ publicClient,
96
+ });
97
+
98
+ // Prepare to mint a token
99
+ const { parameters: collectParameters } = await prepareMint({
100
+ quantityToMint: 1n,
101
+ minterAccount: collectorAddress,
102
+ });
103
+
104
+ // Step 2: Mint an 1155 token on the new contract
105
+ const { request: mintRequest } =
106
+ await publicClient.simulateContract(collectParameters);
107
+ await writeContractWithRetries({
108
+ request: mintRequest,
109
+ walletClient,
110
+ publicClient,
111
+ });
112
+
113
+ // Set up cross-chain comment parameters
114
+ const sourceChainId = base.id; // The chain ID where the comment originates
115
+
116
+ const commentsAddressForChainId =
117
+ commentsAddress[chainId as keyof typeof commentsAddress];
118
+
119
+ // Step 3: Prepare a cross-chain comment
120
+ const permitComment: PermitComment = {
121
+ sourceChainId,
122
+ contractAddress,
123
+ destinationChainId: chainId,
124
+ tokenId: newTokenId,
125
+ commenter: collectorAddress,
126
+ text: "hello world",
127
+ deadline: thirtySecondsFromNow(),
128
+ nonce: randomNonce(),
129
+ referrer: zeroAddress,
130
+ commenterSmartWallet: zeroAddress,
131
+ replyTo: emptyCommentIdentifier(),
132
+ };
133
+
134
+ // Generate typed data for signing
135
+ const typedData = permitCommentTypedDataDefinition(permitComment);
136
+
137
+ expect(typedData.domain!.chainId).toEqual(sourceChainId);
138
+ expect(typedData.account).toEqual(collectorAddress);
139
+ expect(typedData.domain!.verifyingContract).toEqual(
140
+ commentsAddressForChainId,
141
+ );
142
+ expect(typedData.domain!.verifyingContract).toEqual(
143
+ commentsAddressForChainId,
144
+ );
145
+
146
+ const hashed = await publicClient.readContract({
147
+ abi: commentsABI,
148
+ address: commentsAddressForChainId,
149
+ functionName: "hashPermitComment",
150
+ args: [permitComment],
151
+ });
152
+
153
+ expect(hashed).toEqual(hashTypedData(typedData));
154
+
155
+ // Ensure the commenter has enough balance for the spark value
156
+ await testClient.setBalance({
157
+ address: collectorAddress,
158
+ value: sparkValue(),
159
+ });
160
+
161
+ // Step 4: Sign the cross-chain comment
162
+ const signature = await walletClient.signTypedData(typedData);
163
+
164
+ // Ensure the executor has enough balance to execute the transaction
165
+ await testClient.setBalance({
166
+ address: executorAddress,
167
+ value: parseEther("1"),
168
+ });
169
+
170
+ // Step 5: Simulate and execute the cross-chain comment
171
+ const { request: commentRequest } = await publicClient.simulateContract({
172
+ abi: commentsABI,
173
+ address: commentsAddressForChainId,
174
+ functionName: "permitComment",
175
+ args: [permitComment, signature],
176
+ account: executorAddress,
177
+ value: sparkValue(),
178
+ });
179
+
180
+ const commentHash = await walletClient.writeContract(commentRequest);
181
+ const receipt = await publicClient.waitForTransactionReceipt({
182
+ hash: commentHash,
183
+ });
184
+
185
+ expect(receipt.status).toBe("success");
186
+
187
+ // Extract the comment identifier from the transaction receipt
188
+ const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
189
+
190
+ // Step 6: Prepare a spark (like) for the comment
191
+ const sparkComment: PermitSparkComment = {
192
+ sparksQuantity: 3n,
193
+ sparker: sparkerAddress,
194
+ deadline: thirtySecondsFromNow(),
195
+ nonce: randomNonce(),
196
+ referrer: zeroAddress,
197
+ sourceChainId,
198
+ destinationChainId: chainId,
199
+ comment: commentIdentifier,
200
+ };
201
+
202
+ const sparkTypedData =
203
+ permitSparkCommentTypedDataDefinition(sparkComment);
204
+
205
+ // Step 7: Sign the spark comment
206
+ const sparkSignature = await walletClient.signTypedData(sparkTypedData);
207
+
208
+ // Step 8: Simulate and execute the spark comment
209
+ const { request: sparkRequest } = await publicClient.simulateContract({
210
+ abi: commentsABI,
211
+ address: commentsAddressForChainId,
212
+ functionName: "permitSparkComment",
213
+ args: [sparkComment, sparkSignature],
214
+ account: executorAddress,
215
+ value: sparkValue() * sparkComment.sparksQuantity,
216
+ });
217
+
218
+ const sparkHash = await walletClient.writeContract(sparkRequest);
219
+
220
+ await waitForSuccess(sparkHash, publicClient);
221
+
222
+ // Step 9: Verify the spark count
223
+ const sparkCount = await publicClient.readContract({
224
+ abi: commentsABI,
225
+ address: commentsAddressForChainId,
226
+ functionName: "commentSparksQuantity",
227
+ args: [commentIdentifier],
228
+ });
229
+
230
+ expect(sparkCount).toEqual(sparkComment.sparksQuantity);
231
+ },
232
+ 40_000,
233
+ );
234
+ makeAnvilTest({
235
+ forkUrl: forkUrls.zoraMainnet,
236
+ forkBlockNumber: 21297211,
237
+ anvilChainId: zora.id,
238
+ })(
239
+ "can sign and execute a cross-chain timed sale mint and comment",
240
+ async ({
241
+ viemClients: { publicClient, walletClient, chain, testClient },
242
+ }) => {
243
+ // Get the chain ID and set up addresses for different roles
244
+ const chainId = chain.id;
245
+ const [commenterAddress, executorAddress] =
246
+ (await walletClient.getAddresses()!) as [Address, Address, Address];
247
+
248
+ // Create a creator client for interacting with the protocol
249
+ const creatorClient = createCreatorClient({
250
+ chainId,
251
+ publicClient,
252
+ });
253
+
254
+ // Step 1: Create a new 1155 contract and token
255
+ const { contractAddress, newTokenId, parameters } =
256
+ await creatorClient.create1155({
257
+ contract: randomNewContract(),
258
+ token: {
259
+ tokenMetadataURI: demoTokenMetadataURI,
260
+ },
261
+ account: commenterAddress,
262
+ });
263
+
264
+ // Deploy the new contract
265
+ const { request } = await publicClient.simulateContract(parameters);
266
+ await writeContractWithRetries({
267
+ request,
268
+ walletClient,
269
+ publicClient,
270
+ });
271
+
272
+ // Step 2: Prepare the permit data for timed sale mint and comment
273
+ const quantity = 3n;
274
+ const mintReferral = zeroAddress;
275
+ const comment = "This is a test comment for timed sale mint";
276
+
277
+ const permitMintAndComment: PermitMintAndComment = {
278
+ commenter: commenterAddress,
279
+ quantity,
280
+ collection: contractAddress,
281
+ tokenId: newTokenId,
282
+ mintReferral,
283
+ comment,
284
+ deadline: thirtySecondsFromNow(),
285
+ nonce: randomNonce(),
286
+ sourceChainId: chainId,
287
+ destinationChainId: chainId,
288
+ };
289
+
290
+ // Step 3: Generate the typed data for signing
291
+ const typedData =
292
+ permitMintAndCommentTypedDataDefinition(permitMintAndComment);
293
+
294
+ // Step 4: Sign the typed data
295
+ const signature = await walletClient.signTypedData(typedData);
296
+
297
+ await testClient.setBalance({
298
+ address: executorAddress,
299
+ value: parseEther("1"),
300
+ });
301
+
302
+ // Step 5: Simulate and execute the permitTimedSaleMintAndComment function
303
+ const callerAndCommenterAddress =
304
+ callerAndCommenterAddresses[
305
+ chainId as keyof typeof callerAndCommenterAddresses
306
+ ];
307
+ const { request: permitRequest } = await publicClient.simulateContract({
308
+ abi: callerAndCommenterABI,
309
+ address: callerAndCommenterAddress,
310
+ functionName: "permitTimedSaleMintAndComment",
311
+ args: [permitMintAndComment, signature],
312
+ account: executorAddress,
313
+ value: quantity * parseEther("0.000111"),
314
+ });
315
+
316
+ const receipt = await writeContractWithRetries({
317
+ publicClient,
318
+ walletClient,
319
+ request: permitRequest,
320
+ });
321
+
322
+ // Step 6: Verify the comment was created
323
+ const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
324
+ expect(commentIdentifier).toBeDefined();
325
+
326
+ // Step 7: Verify the token was minted
327
+ const balance = await publicClient.readContract({
328
+ abi: zoraCreator1155ImplABI,
329
+ address: contractAddress,
330
+ functionName: "balanceOf",
331
+ args: [commenterAddress, newTokenId],
332
+ });
333
+
334
+ expect(balance).toEqual(quantity);
335
+ },
336
+ 40_000, // Increased timeout to 30 seconds
337
+ );
338
+ });
@@ -21,16 +21,13 @@ import {
21
21
  import { zora } from "viem/chains";
22
22
  import { AllowList } from "src/allow-list/types";
23
23
  import { createAllowList } from "src/allow-list/allow-list-client";
24
- import { NewContractParams } from "./types";
25
24
  import { SubgraphContractGetter } from "./contract-getter";
26
25
  import {
27
26
  DEFAULT_MINIMUM_MARKET_ETH,
28
27
  DEFAULT_MARKET_COUNTDOWN,
29
28
  } from "./minter-defaults";
30
- import {
31
- demoContractMetadataURI,
32
- demoTokenMetadataURI,
33
- } from "src/fixtures/contract-setup";
29
+ import { randomNewContract } from "src/test-utils";
30
+ import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
34
31
 
35
32
  const anvilTest = makeAnvilTest({
36
33
  forkUrl: forkUrls.zoraMainnet,
@@ -61,13 +58,6 @@ const minterIsMinterOnToken = async ({
61
58
  });
62
59
  };
63
60
 
64
- function randomNewContract(): NewContractParams {
65
- return {
66
- name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
67
- uri: demoContractMetadataURI,
68
- };
69
- }
70
-
71
61
  describe("create-helper", () => {
72
62
  anvilTest(
73
63
  "when no sales config is provided, it creates a new 1155 contract and token using the timed sale strategy",
@@ -461,6 +451,8 @@ describe("create-helper", () => {
461
451
 
462
452
  const pricePerToken = parseEther("0.01");
463
453
 
454
+ const blockTime = (await publicClient.getBlock()).timestamp;
455
+
464
456
  const {
465
457
  parameters: request,
466
458
  contractAddress: collectionAddress,
@@ -473,6 +465,7 @@ describe("create-helper", () => {
473
465
  tokenMetadataURI: demoTokenMetadataURI,
474
466
  salesConfig: {
475
467
  pricePerToken,
468
+ saleStart: blockTime,
476
469
  },
477
470
  },
478
471
  account: creatorAddress,
@@ -517,6 +510,7 @@ describe("create-helper", () => {
517
510
  },
518
511
  },
519
512
  quantityToMint,
513
+ chainId: chain.id,
520
514
  });
521
515
 
522
516
  const { request: collectSimulation } =
@@ -238,6 +238,7 @@ async function createNew1155ContractAndToken({
238
238
  publicClient,
239
239
  chainId,
240
240
  }),
241
+ chainId,
241
242
  });
242
243
 
243
244
  return {
@@ -294,6 +295,7 @@ async function createNew1155Token({
294
295
  result: newToken.salesConfig,
295
296
  tokenId: nextTokenId,
296
297
  getContractMintFee: async () => mintFee,
298
+ chainId,
297
299
  });
298
300
 
299
301
  return {
@@ -75,6 +75,7 @@ export function makeOnchainPrepareMintFromCreate({
75
75
  minter,
76
76
  getContractMintFee,
77
77
  contractVersion,
78
+ chainId,
78
79
  }: {
79
80
  contractAddress: Address;
80
81
  tokenId: bigint;
@@ -82,6 +83,7 @@ export function makeOnchainPrepareMintFromCreate({
82
83
  minter: Address;
83
84
  getContractMintFee: () => Promise<bigint>;
84
85
  contractVersion: string;
86
+ chainId: number;
85
87
  }): AsyncPrepareMint {
86
88
  return async (params: MintParametersBase): Promise<PrepareMintReturn> => {
87
89
  const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
@@ -98,6 +100,7 @@ export function makeOnchainPrepareMintFromCreate({
98
100
  ...params,
99
101
  tokenContract: contractAddress,
100
102
  tokenId,
103
+ chainId,
101
104
  }),
102
105
  costs: parseMintCosts({
103
106
  allowListEntry: params.allowListEntry,
@@ -18,12 +18,12 @@ export const DEFAULT_MARKET_COUNTDOWN = BigInt(24 * 60 * 60);
18
18
  // Sales end forever amount (uint64 max)
19
19
  export const SALE_END_FOREVER = 18446744073709551615n;
20
20
 
21
- const DEFAULT_SALE_START_AND_END: Concrete<SaleStartAndEnd> = {
22
- // Sale start time – defaults to beginning of unix time
23
- saleStart: 0n,
21
+ const DEFAULT_SALE_START_AND_END = (): Concrete<SaleStartAndEnd> => ({
22
+ // Sale start time – defaults to current time in seconds
23
+ saleStart: BigInt(Math.floor(new Date().getTime() / 1000)),
24
24
  // This is the end of uint64, plenty of time
25
25
  saleEnd: SALE_END_FOREVER,
26
- };
26
+ });
27
27
 
28
28
  const DEFAULT_MAX_TOKENS_PER_ADDRESS: Concrete<MaxTokensPerAddress> = {
29
29
  maxTokensPerAddress: 0n,
@@ -32,7 +32,7 @@ const DEFAULT_MAX_TOKENS_PER_ADDRESS: Concrete<MaxTokensPerAddress> = {
32
32
  const erc20SaleSettingsWithDefaults = (
33
33
  params: Erc20ParamsType,
34
34
  ): Concrete<Erc20ParamsType> => ({
35
- ...DEFAULT_SALE_START_AND_END,
35
+ ...DEFAULT_SALE_START_AND_END(),
36
36
  ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
37
37
  ...params,
38
38
  });
@@ -41,7 +41,7 @@ const allowListWithDefaults = (
41
41
  allowlist: AllowListParamType,
42
42
  ): Concrete<AllowListParamType> => {
43
43
  return {
44
- ...DEFAULT_SALE_START_AND_END,
44
+ ...DEFAULT_SALE_START_AND_END(),
45
45
  ...allowlist,
46
46
  };
47
47
  };
@@ -49,7 +49,7 @@ const allowListWithDefaults = (
49
49
  const fixedPriceSettingsWithDefaults = (
50
50
  params: FixedPriceParamsType,
51
51
  ): Concrete<FixedPriceParamsType> => ({
52
- ...DEFAULT_SALE_START_AND_END,
52
+ ...DEFAULT_SALE_START_AND_END(),
53
53
  ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
54
54
  type: "fixedPrice",
55
55
  ...params,
@@ -1,16 +1,28 @@
1
1
  import { describe, expect, vi } from "vitest";
2
- import { Address, erc20Abi, parseAbi, parseEther } from "viem";
2
+ import {
3
+ Address,
4
+ erc20Abi,
5
+ parseAbi,
6
+ parseEther,
7
+ TransactionReceipt,
8
+ parseEventLogs,
9
+ } from "viem";
3
10
  import { zora, zoraSepolia } from "viem/chains";
4
- import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
11
+ import {
12
+ zoraCreator1155ImplABI,
13
+ CommentIdentifier,
14
+ commentsABI,
15
+ callerAndCommenterABI,
16
+ } from "@zoralabs/protocol-deployments";
5
17
  import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
6
18
  import { createCollectorClient, createCreatorClient } from "src/sdk";
7
19
  import { getAllowListEntry } from "src/allow-list/allow-list-client";
20
+ import { SubgraphMintGetter } from "./subgraph-mint-getter";
21
+ import { new1155ContractVersion } from "src/create/contract-setup";
8
22
  import {
9
23
  demoContractMetadataURI,
10
24
  demoTokenMetadataURI,
11
- } from "src/create/1155-create-helper.test";
12
- import { SubgraphMintGetter } from "./subgraph-mint-getter";
13
- import { new1155ContractVersion } from "src/create/contract-setup";
25
+ } from "src/fixtures/contract-setup";
14
26
  import { ISubgraphQuerier } from "src/apis/subgraph-querier";
15
27
  import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
16
28
 
@@ -18,52 +30,64 @@ const erc721ABI = parseAbi([
18
30
  "function balanceOf(address owner) public view returns (uint256)",
19
31
  ] as const);
20
32
 
33
+ const getCommentIdentifierFromReceipt = (
34
+ receipt: TransactionReceipt,
35
+ ): CommentIdentifier => {
36
+ const logs = parseEventLogs({
37
+ abi: commentsABI,
38
+ logs: receipt.logs,
39
+ eventName: "Commented",
40
+ });
41
+
42
+ if (logs.length === 0) {
43
+ throw new Error("No Commented event found in receipt");
44
+ }
45
+
46
+ return logs[0]!.args.commentIdentifier;
47
+ };
48
+
21
49
  describe("mint-helper", () => {
22
50
  makeAnvilTest({
23
- forkBlockNumber: 16028671,
24
- forkUrl: forkUrls.zoraMainnet,
25
- anvilChainId: zora.id,
51
+ forkBlockNumber: 16028124,
52
+ forkUrl: forkUrls.zoraSepolia,
53
+ anvilChainId: zoraSepolia.id,
26
54
  })(
27
- "mints a new 1155 token",
55
+ "mints a new 1155 token with a comment",
28
56
  async ({ viemClients }) => {
29
- const { testClient, walletClient, publicClient } = viemClients;
57
+ const { testClient, walletClient, publicClient, chain } = viemClients;
30
58
  const creatorAccount = (await walletClient.getAddresses())[0]!;
31
59
  await testClient.setBalance({
32
60
  address: creatorAccount,
33
61
  value: parseEther("2000"),
34
62
  });
35
63
  const targetContract: Address =
36
- "0xa2fea3537915dc6c7c7a97a82d1236041e6feb2e";
37
- const targetTokenId = 1n;
64
+ "0xD42557F24034b53e7340A40bb5813eF9Ba88F2b4";
65
+ const targetTokenId = 3n;
38
66
  const collectorClient = createCollectorClient({
39
- chainId: zora.id,
67
+ chainId: chain.id,
40
68
  publicClient,
41
69
  });
42
70
 
43
- const {
44
- token: mintable,
45
- prepareMint,
46
- primaryMintActive,
47
- } = await collectorClient.getToken({
48
- tokenContract: targetContract,
49
- mintType: "1155",
50
- tokenId: targetTokenId,
51
- });
52
-
53
- mintable.maxSupply;
54
- mintable.totalMinted;
55
- mintable.tokenURI;
56
- mintable;
71
+ const { prepareMint, primaryMintActive } = await collectorClient.getToken(
72
+ {
73
+ tokenContract: targetContract,
74
+ mintType: "1155",
75
+ tokenId: targetTokenId,
76
+ },
77
+ );
57
78
 
58
79
  expect(primaryMintActive).toBe(true);
59
80
  expect(prepareMint).toBeDefined();
60
81
 
82
+ const quantityToMint = 5n;
83
+
61
84
  const { parameters, costs } = prepareMint!({
62
85
  minterAccount: creatorAccount,
63
- quantityToMint: 1,
86
+ quantityToMint,
87
+ mintComment: "This is a fun comment :)",
64
88
  });
65
89
 
66
- expect(costs.totalCostEth).toBe(1n * parseEther("0.000777"));
90
+ expect(costs.totalCostEth).toBe(quantityToMint * parseEther("0.000111"));
67
91
 
68
92
  const oldBalance = await publicClient.readContract({
69
93
  abi: zoraCreator1155ImplABI,
@@ -84,7 +108,20 @@ describe("mint-helper", () => {
84
108
  });
85
109
  expect(receipt).to.not.be.null;
86
110
  expect(oldBalance).to.be.equal(0n);
87
- expect(newBalance).to.be.equal(1n);
111
+ expect(newBalance).to.be.equal(quantityToMint);
112
+
113
+ // search for the Commented event in the logs
114
+ const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
115
+
116
+ expect(commentIdentifier).toBeDefined();
117
+
118
+ const logs = parseEventLogs({
119
+ abi: callerAndCommenterABI,
120
+ logs: receipt.logs,
121
+ eventName: "MintedAndCommented",
122
+ });
123
+
124
+ expect(logs.length).toBe(1);
88
125
  },
89
126
  12 * 1000,
90
127
  );
@@ -24,19 +24,22 @@ export class MintClient {
24
24
  private readonly publicClient: IPublicClient;
25
25
  private readonly mintGetter: IOnchainMintGetter;
26
26
  private readonly premintGetter: IPremintGetter;
27
-
27
+ private readonly chainId: number;
28
28
  constructor({
29
29
  publicClient,
30
30
  premintGetter,
31
31
  mintGetter,
32
+ chainId,
32
33
  }: {
33
34
  publicClient: IPublicClient;
34
35
  premintGetter: IPremintGetter;
35
36
  mintGetter: IOnchainMintGetter;
37
+ chainId: number;
36
38
  }) {
37
39
  this.publicClient = publicClient;
38
40
  this.mintGetter = mintGetter;
39
41
  this.premintGetter = premintGetter;
42
+ this.chainId = chainId;
40
43
  }
41
44
 
42
45
  /**
@@ -54,6 +57,7 @@ export class MintClient {
54
57
  publicClient: this.publicClient,
55
58
  mintGetter: this.mintGetter,
56
59
  premintGetter: this.premintGetter,
60
+ chainId: this.chainId,
57
61
  });
58
62
  }
59
63
 
@@ -69,6 +73,7 @@ export class MintClient {
69
73
  mintGetter: this.mintGetter,
70
74
  premintGetter: this.premintGetter,
71
75
  publicClient: this.publicClient,
76
+ chainId: this.chainId,
72
77
  });
73
78
  }
74
79
 
@@ -87,6 +92,7 @@ export class MintClient {
87
92
  mintGetter: this.mintGetter,
88
93
  premintGetter: this.premintGetter,
89
94
  publicClient: this.publicClient,
95
+ chainId: this.chainId,
90
96
  });
91
97
  }
92
98
 
@@ -110,17 +116,20 @@ async function mint({
110
116
  publicClient,
111
117
  mintGetter,
112
118
  premintGetter,
119
+ chainId,
113
120
  }: {
114
121
  parameters: MakeMintParametersArguments;
115
122
  publicClient: IPublicClient;
116
123
  mintGetter: IOnchainMintGetter;
117
124
  premintGetter: IPremintGetter;
125
+ chainId: number;
118
126
  }): Promise<PrepareMintReturn> {
119
127
  const { prepareMint, primaryMintActive } = await getMint({
120
128
  params: parameters,
121
129
  mintGetter,
122
130
  premintGetter,
123
131
  publicClient,
132
+ chainId,
124
133
  });
125
134
 
126
135
  if (!primaryMintActive) {