@zoralabs/protocol-sdk 0.11.6-COMMENTS.0 → 0.11.7-BUGFIX.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 (41) hide show
  1. package/.env +1 -0
  2. package/.turbo/turbo-build.log +18 -18
  3. package/CHANGELOG.md +10 -8
  4. package/dist/create/mint-from-create.d.ts +1 -2
  5. package/dist/create/mint-from-create.d.ts.map +1 -1
  6. package/dist/index.cjs +42 -196
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.js +44 -202
  9. package/dist/index.js.map +1 -1
  10. package/dist/mint/mint-client.d.ts +1 -3
  11. package/dist/mint/mint-client.d.ts.map +1 -1
  12. package/dist/mint/mint-queries.d.ts +3 -5
  13. package/dist/mint/mint-queries.d.ts.map +1 -1
  14. package/dist/mint/mint-transactions.d.ts +2 -4
  15. package/dist/mint/mint-transactions.d.ts.map +1 -1
  16. package/dist/premint/premint-client.d.ts +8 -0
  17. package/dist/premint/premint-client.d.ts.map +1 -1
  18. package/dist/sdk.d.ts.map +1 -1
  19. package/dist/secondary/secondary-client.d.ts +1 -2
  20. package/dist/secondary/secondary-client.d.ts.map +1 -1
  21. package/dist/secondary/types.d.ts +0 -1
  22. package/dist/secondary/types.d.ts.map +1 -1
  23. package/dist/test-utils.d.ts +1 -3
  24. package/dist/test-utils.d.ts.map +1 -1
  25. package/package.json +2 -2
  26. package/src/create/1155-create-helper.test.ts +12 -2
  27. package/src/create/1155-create-helper.ts +0 -2
  28. package/src/create/mint-from-create.ts +0 -3
  29. package/src/mint/mint-client.test.ts +30 -67
  30. package/src/mint/mint-client.ts +1 -10
  31. package/src/mint/mint-queries.ts +5 -16
  32. package/src/mint/mint-transactions.ts +16 -80
  33. package/src/rewards/subgraph-queries.ts +1 -1
  34. package/src/sdk.ts +0 -1
  35. package/src/secondary/secondary-client.test.ts +2 -118
  36. package/src/secondary/secondary-client.ts +6 -136
  37. package/src/secondary/types.ts +0 -2
  38. package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -1
  39. package/src/test-utils.ts +0 -12
  40. package/yarn-error.log +8602 -0
  41. package/src/comments/comments.test.ts +0 -342
@@ -1,342 +0,0 @@
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
- keccak256,
22
- toBytes,
23
- zeroAddress,
24
- parseEther,
25
- TransactionReceipt,
26
- parseEventLogs,
27
- hashTypedData,
28
- } from "viem";
29
- import { createCreatorClient } from "src/sdk";
30
- import { randomNewContract, waitForSuccess } from "src/test-utils";
31
- import { permitCommentTypedDataDefinition } from "@zoralabs/protocol-deployments";
32
- import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
33
-
34
- const getCommentIdentifierFromReceipt = (
35
- receipt: TransactionReceipt,
36
- ): CommentIdentifier => {
37
- const logs = parseEventLogs({
38
- abi: commentsABI,
39
- logs: receipt.logs,
40
- eventName: "Commented",
41
- });
42
-
43
- if (logs.length === 0) {
44
- throw new Error("No Commented event found in receipt");
45
- }
46
-
47
- return logs[0]!.args.commentIdentifier;
48
- };
49
- const randomNonce = () => keccak256(toBytes(Math.round(Math.random() * 1000)));
50
- const thirtySecondsFromNow =
51
- BigInt(Math.round(new Date().getTime() / 1000)) + 30n;
52
- // todo: move this to protocol-deployments
53
- describe("comments", () => {
54
- makeAnvilTest({
55
- forkUrl: forkUrls.zoraMainnet,
56
- forkBlockNumber: 21297211,
57
- anvilChainId: zora.id,
58
- })(
59
- "can sign and execute a cross-chain comment, and sign and execute a cross-chain spark comment",
60
- async ({
61
- viemClients: { publicClient, walletClient, chain, testClient },
62
- }) => {
63
- // Get the chain ID and set up addresses for different roles
64
- const chainId = chain.id;
65
- const [
66
- collectorAddress,
67
- creatorAddress,
68
- executorAddress,
69
- sparkerAddress,
70
- ] = (await walletClient.getAddresses()!) as [
71
- Address,
72
- Address,
73
- Address,
74
- Address,
75
- ];
76
-
77
- // Create a creator client for interacting with the protocol
78
- const creatorClient = createCreatorClient({
79
- chainId,
80
- publicClient,
81
- });
82
-
83
- // Step 1: Create a new 1155 contract and token
84
- const { contractAddress, newTokenId, parameters, prepareMint } =
85
- await creatorClient.create1155({
86
- contract: randomNewContract(),
87
- token: {
88
- tokenMetadataURI: demoTokenMetadataURI,
89
- },
90
- account: creatorAddress,
91
- });
92
-
93
- // Deploy the new contract
94
- const { request } = await publicClient.simulateContract(parameters);
95
- await writeContractWithRetries({
96
- request,
97
- walletClient,
98
- publicClient,
99
- });
100
-
101
- // Prepare to mint a token
102
- const { parameters: collectParameters } = await prepareMint({
103
- quantityToMint: 1n,
104
- minterAccount: collectorAddress,
105
- });
106
-
107
- // Step 2: Mint an 1155 token on the new contract
108
- const { request: mintRequest } =
109
- await publicClient.simulateContract(collectParameters);
110
- await writeContractWithRetries({
111
- request: mintRequest,
112
- walletClient,
113
- publicClient,
114
- });
115
-
116
- // Set up cross-chain comment parameters
117
- const sourceChainId = base.id; // The chain ID where the comment originates
118
-
119
- const commentsAddressForChainId =
120
- commentsAddress[chainId as keyof typeof commentsAddress];
121
-
122
- // Step 3: Prepare a cross-chain comment
123
- const permitComment: PermitComment = {
124
- sourceChainId,
125
- contractAddress,
126
- destinationChainId: chainId,
127
- tokenId: newTokenId,
128
- commenter: collectorAddress,
129
- text: "hello world",
130
- deadline: thirtySecondsFromNow,
131
- nonce: randomNonce(),
132
- referrer: zeroAddress,
133
- commenterSmartWallet: zeroAddress,
134
- replyTo: emptyCommentIdentifier(),
135
- };
136
-
137
- // Generate typed data for signing
138
- const typedData = permitCommentTypedDataDefinition(permitComment);
139
-
140
- expect(typedData.domain!.chainId).toEqual(sourceChainId);
141
- expect(typedData.account).toEqual(collectorAddress);
142
- expect(typedData.domain!.verifyingContract).toEqual(
143
- commentsAddressForChainId,
144
- );
145
- expect(typedData.domain!.verifyingContract).toEqual(
146
- commentsAddressForChainId,
147
- );
148
-
149
- const hashed = await publicClient.readContract({
150
- abi: commentsABI,
151
- address: commentsAddressForChainId,
152
- functionName: "hashPermitComment",
153
- args: [permitComment],
154
- });
155
-
156
- expect(hashed).toEqual(hashTypedData(typedData));
157
-
158
- // Ensure the commenter has enough balance for the spark value
159
- await testClient.setBalance({
160
- address: collectorAddress,
161
- value: sparkValue(),
162
- });
163
-
164
- // Step 4: Sign the cross-chain comment
165
- const signature = await walletClient.signTypedData(typedData);
166
-
167
- // Ensure the executor has enough balance to execute the transaction
168
- await testClient.setBalance({
169
- address: executorAddress,
170
- value: parseEther("1"),
171
- });
172
-
173
- // Step 5: Simulate and execute the cross-chain comment
174
- const { request: commentRequest } = await publicClient.simulateContract({
175
- abi: commentsABI,
176
- address: commentsAddressForChainId,
177
- functionName: "permitComment",
178
- args: [permitComment, signature],
179
- account: executorAddress,
180
- value: sparkValue(),
181
- });
182
-
183
- const commentHash = await walletClient.writeContract(commentRequest);
184
- const receipt = await publicClient.waitForTransactionReceipt({
185
- hash: commentHash,
186
- });
187
-
188
- expect(receipt.status).toBe("success");
189
-
190
- // Extract the comment identifier from the transaction receipt
191
- const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
192
-
193
- // Step 6: Prepare a spark (like) for the comment
194
- const sparkComment: PermitSparkComment = {
195
- sparksQuantity: 3n,
196
- sparker: sparkerAddress,
197
- deadline: thirtySecondsFromNow,
198
- nonce: randomNonce(),
199
- referrer: zeroAddress,
200
- sourceChainId,
201
- destinationChainId: chainId,
202
- comment: commentIdentifier,
203
- };
204
-
205
- const sparkTypedData =
206
- permitSparkCommentTypedDataDefinition(sparkComment);
207
-
208
- // Step 7: Sign the spark comment
209
- const sparkSignature = await walletClient.signTypedData(sparkTypedData);
210
-
211
- // Step 8: Simulate and execute the spark comment
212
- const { request: sparkRequest } = await publicClient.simulateContract({
213
- abi: commentsABI,
214
- address: commentsAddressForChainId,
215
- functionName: "permitSparkComment",
216
- args: [sparkComment, sparkSignature],
217
- account: executorAddress,
218
- value: sparkValue() * sparkComment.sparksQuantity,
219
- });
220
-
221
- const sparkHash = await walletClient.writeContract(sparkRequest);
222
-
223
- await waitForSuccess(sparkHash, publicClient);
224
-
225
- // Step 9: Verify the spark count
226
- const sparkCount = await publicClient.readContract({
227
- abi: commentsABI,
228
- address: commentsAddressForChainId,
229
- functionName: "commentSparksQuantity",
230
- args: [commentIdentifier],
231
- });
232
-
233
- expect(sparkCount).toEqual(sparkComment.sparksQuantity);
234
- },
235
- 40_000,
236
- );
237
- makeAnvilTest({
238
- forkUrl: forkUrls.zoraMainnet,
239
- forkBlockNumber: 21297211,
240
- anvilChainId: zora.id,
241
- })(
242
- "can sign and execute a cross-chain timed sale mint and comment",
243
- async ({
244
- viemClients: { publicClient, walletClient, chain, testClient },
245
- }) => {
246
- // Get the chain ID and set up addresses for different roles
247
- const chainId = chain.id;
248
- const [commenterAddress, executorAddress] =
249
- (await walletClient.getAddresses()!) as [Address, Address, Address];
250
-
251
- // Create a creator client for interacting with the protocol
252
- const creatorClient = createCreatorClient({
253
- chainId,
254
- publicClient,
255
- });
256
-
257
- // Step 1: Create a new 1155 contract and token
258
- const { contractAddress, newTokenId, parameters } =
259
- await creatorClient.create1155({
260
- contract: randomNewContract(),
261
- token: {
262
- tokenMetadataURI: demoTokenMetadataURI,
263
- },
264
- account: commenterAddress,
265
- });
266
-
267
- // Deploy the new contract
268
- const { request } = await publicClient.simulateContract(parameters);
269
- await writeContractWithRetries({
270
- request,
271
- walletClient,
272
- publicClient,
273
- });
274
-
275
- // Step 2: Prepare the permit data for timed sale mint and comment
276
- const thirtySecondsFromNow = BigInt(Math.floor(Date.now() / 1000) + 30);
277
- const quantity = 3n;
278
- const mintReferral = zeroAddress;
279
- const comment = "This is a test comment for timed sale mint";
280
-
281
- const permitMintAndComment: PermitMintAndComment = {
282
- commenter: commenterAddress,
283
- quantity,
284
- collection: contractAddress,
285
- tokenId: newTokenId,
286
- mintReferral,
287
- comment,
288
- deadline: thirtySecondsFromNow,
289
- nonce: randomNonce(),
290
- sourceChainId: chainId,
291
- destinationChainId: chainId,
292
- };
293
-
294
- // Step 3: Generate the typed data for signing
295
- const typedData =
296
- permitMintAndCommentTypedDataDefinition(permitMintAndComment);
297
-
298
- // Step 4: Sign the typed data
299
- const signature = await walletClient.signTypedData(typedData);
300
-
301
- await testClient.setBalance({
302
- address: executorAddress,
303
- value: parseEther("1"),
304
- });
305
-
306
- // Step 5: Simulate and execute the permitTimedSaleMintAndComment function
307
- const callerAndCommenterAddress =
308
- callerAndCommenterAddresses[
309
- chainId as keyof typeof callerAndCommenterAddresses
310
- ];
311
- const { request: permitRequest } = await publicClient.simulateContract({
312
- abi: callerAndCommenterABI,
313
- address: callerAndCommenterAddress,
314
- functionName: "permitTimedSaleMintAndComment",
315
- args: [permitMintAndComment, signature],
316
- account: executorAddress,
317
- value: quantity * parseEther("0.000111"),
318
- });
319
-
320
- const receipt = await writeContractWithRetries({
321
- publicClient,
322
- walletClient,
323
- request: permitRequest,
324
- });
325
-
326
- // Step 6: Verify the comment was created
327
- const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
328
- expect(commentIdentifier).toBeDefined();
329
-
330
- // Step 7: Verify the token was minted
331
- const balance = await publicClient.readContract({
332
- abi: zoraCreator1155ImplABI,
333
- address: contractAddress,
334
- functionName: "balanceOf",
335
- args: [commenterAddress, newTokenId],
336
- });
337
-
338
- expect(balance).toEqual(quantity);
339
- },
340
- 40_000, // Increased timeout to 30 seconds
341
- );
342
- });