@zoralabs/protocol-sdk 0.11.7-COMMENTS.0 → 0.11.8

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 (50) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +8 -8
  3. package/dist/anvil.d.ts +1 -0
  4. package/dist/anvil.d.ts.map +1 -1
  5. package/dist/create/mint-from-create.d.ts +1 -2
  6. package/dist/create/mint-from-create.d.ts.map +1 -1
  7. package/dist/fixtures/rewards-query-results.d.ts +4 -1
  8. package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
  9. package/dist/index.cjs +66 -207
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +68 -213
  12. package/dist/index.js.map +1 -1
  13. package/dist/mint/mint-client.d.ts +1 -3
  14. package/dist/mint/mint-client.d.ts.map +1 -1
  15. package/dist/mint/mint-queries.d.ts +3 -5
  16. package/dist/mint/mint-queries.d.ts.map +1 -1
  17. package/dist/mint/mint-transactions.d.ts +2 -4
  18. package/dist/mint/mint-transactions.d.ts.map +1 -1
  19. package/dist/rewards/rewards-queries.d.ts.map +1 -1
  20. package/dist/rewards/subgraph-queries.d.ts +2 -1
  21. package/dist/rewards/subgraph-queries.d.ts.map +1 -1
  22. package/dist/rewards/subgraph-rewards-getter.d.ts +9 -3
  23. package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
  24. package/dist/sdk.d.ts.map +1 -1
  25. package/dist/secondary/secondary-client.d.ts +1 -2
  26. package/dist/secondary/secondary-client.d.ts.map +1 -1
  27. package/dist/secondary/types.d.ts +0 -1
  28. package/dist/secondary/types.d.ts.map +1 -1
  29. package/dist/test-utils.d.ts +1 -5
  30. package/dist/test-utils.d.ts.map +1 -1
  31. package/package.json +4 -4
  32. package/src/create/1155-create-helper.test.ts +12 -2
  33. package/src/create/1155-create-helper.ts +0 -2
  34. package/src/create/mint-from-create.ts +0 -3
  35. package/src/fixtures/rewards-query-results.ts +9 -2
  36. package/src/mint/mint-client.test.ts +30 -67
  37. package/src/mint/mint-client.ts +1 -10
  38. package/src/mint/mint-queries.ts +5 -16
  39. package/src/mint/mint-transactions.ts +16 -80
  40. package/src/rewards/rewards-client.test.ts +41 -9
  41. package/src/rewards/rewards-queries.ts +15 -5
  42. package/src/rewards/subgraph-queries.ts +4 -2
  43. package/src/rewards/subgraph-rewards-getter.ts +24 -10
  44. package/src/sdk.ts +0 -1
  45. package/src/secondary/secondary-client.test.ts +2 -248
  46. package/src/secondary/secondary-client.ts +6 -136
  47. package/src/secondary/types.ts +0 -2
  48. package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -2
  49. package/src/test-utils.ts +0 -19
  50. package/src/comments/comments.test.ts +0 -338
@@ -1,338 +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
- 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
- });