@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,5 +1,5 @@
1
1
  import { describe, expect, vi } from "vitest";
2
- import { parseEther, Address, parseEventLogs } from "viem";
2
+ import { parseEther, Address } from "viem";
3
3
  import { zoraSepolia } from "viem/chains";
4
4
  import {
5
5
  forkUrls,
@@ -7,22 +7,13 @@ import {
7
7
  simulateAndWriteContractWithRetries,
8
8
  } from "src/anvil";
9
9
  import { createCollectorClient } from "src/sdk";
10
- import {
11
- zoraCreator1155ImplABI,
12
- commentsABI,
13
- callerAndCommenterABI,
14
- PermitBuyOnSecondaryAndComment,
15
- permitBuyOnSecondaryAndCommentTypedDataDefinition,
16
- callerAndCommenterAddress,
17
- sparkValue,
18
- } from "@zoralabs/protocol-deployments";
10
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
19
11
  import { SubgraphMintGetter } from "src/mint/subgraph-mint-getter";
20
12
  import { ERROR_SECONDARY_NOT_STARTED } from "./secondary-client";
21
13
  import { ISubgraphQuerier } from "src/apis/subgraph-querier";
22
14
  import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
23
15
  import { new1155ContractVersion } from "src/create/contract-setup";
24
16
  import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
25
- import { randomNonce } from "src/test-utils";
26
17
 
27
18
  describe("secondary", () => {
28
19
  makeAnvilTest({
@@ -266,241 +257,4 @@ describe("secondary", () => {
266
257
  },
267
258
  30_000,
268
259
  );
269
-
270
- makeAnvilTest({
271
- forkBlockNumber: 16339853,
272
- forkUrl: forkUrls.zoraSepolia,
273
- anvilChainId: zoraSepolia.id,
274
- })(
275
- "it can buy on secondary with a comment",
276
- async ({
277
- viemClients: { publicClient, chain, walletClient, testClient },
278
- }) => {
279
- const collectorAccount = (await walletClient.getAddresses()!)[1]!;
280
- const executorAccount = (await walletClient.getAddresses()!)[3]!;
281
-
282
- const mintGetter = new SubgraphMintGetter(chain.id);
283
- const contractAddress: Address =
284
- "0xd42557f24034b53e7340a40bb5813ef9ba88f2b4";
285
- const newTokenId = 4n;
286
-
287
- await testClient.setBalance({
288
- address: collectorAccount,
289
- value: parseEther("100"),
290
- });
291
-
292
- mintGetter.subgraphQuerier.query = vi
293
- .fn<ISubgraphQuerier["query"]>()
294
- .mockResolvedValue({
295
- zoraCreateToken: mockTimedSaleStrategyTokenQueryResult({
296
- chainId: chain.id,
297
- tokenId: newTokenId,
298
- contractAddress,
299
- contractVersion:
300
- new1155ContractVersion[
301
- chain.id as keyof typeof new1155ContractVersion
302
- ],
303
- }),
304
- });
305
-
306
- const collectorClient = createCollectorClient({
307
- chainId: chain.id,
308
- publicClient,
309
- mintGetter,
310
- });
311
-
312
- const secondaryInfo = await collectorClient.getSecondaryInfo({
313
- contract: contractAddress,
314
- tokenId: newTokenId,
315
- });
316
-
317
- // mint enough to start the countdown
318
- const quantityToMint =
319
- secondaryInfo!.minimumMintsForCountdown! - secondaryInfo!.mintCount;
320
-
321
- const { parameters: collectParameters } = await collectorClient.mint({
322
- minterAccount: collectorAccount,
323
- mintType: "1155",
324
- quantityToMint: quantityToMint,
325
- tokenId: newTokenId,
326
- tokenContract: contractAddress,
327
- });
328
-
329
- await simulateAndWriteContractWithRetries({
330
- parameters: collectParameters,
331
- walletClient,
332
- publicClient,
333
- });
334
-
335
- await advanceToSaleAndAndLaunchMarket({
336
- contractAddress,
337
- tokenId: newTokenId,
338
- testClient,
339
- publicClient,
340
- walletClient,
341
- collectorClient,
342
- chainId: chain.id,
343
- account: collectorAccount,
344
- });
345
-
346
- const buyResult = await collectorClient.buy1155OnSecondary({
347
- account: collectorAccount,
348
- quantity: 5n,
349
- contract: contractAddress,
350
- tokenId: newTokenId,
351
- comment: "test comment",
352
- });
353
-
354
- const receipt = await simulateAndWriteContractWithRetries({
355
- parameters: buyResult.parameters!,
356
- walletClient,
357
- publicClient,
358
- });
359
-
360
- const commentedEvent = parseEventLogs({
361
- abi: commentsABI,
362
- logs: receipt.logs,
363
- eventName: "Commented",
364
- });
365
-
366
- expect(commentedEvent[0]).toBeDefined();
367
- expect(commentedEvent[0]!.args.text).toBe("test comment");
368
-
369
- const boughtAndCommentedEvent = parseEventLogs({
370
- abi: callerAndCommenterABI,
371
- logs: receipt.logs,
372
- eventName: "SwappedOnSecondaryAndCommented",
373
- });
374
-
375
- expect(boughtAndCommentedEvent[0]).toBeDefined();
376
- expect(boughtAndCommentedEvent[0]!.args.comment).toBe("test comment");
377
- expect(boughtAndCommentedEvent[0]!.args.quantity).toBe(5n);
378
- expect(boughtAndCommentedEvent[0]!.args.swapDirection).toBe(0);
379
-
380
- // PERMIT BUY TEST
381
- const buyResultASecondTime = await collectorClient.buy1155OnSecondary({
382
- account: collectorAccount,
383
- quantity: 5n,
384
- contract: contractAddress,
385
- tokenId: newTokenId,
386
- comment: "test comment",
387
- });
388
-
389
- const valueToSend = (buyResultASecondTime.price!.wei.total * 105n) / 100n;
390
-
391
- const { timestamp } = await publicClient.getBlock();
392
-
393
- const permitBuy: PermitBuyOnSecondaryAndComment = {
394
- collection: contractAddress,
395
- tokenId: newTokenId,
396
- quantity: 5n,
397
- commenter: collectorAccount,
398
- comment: "test comment",
399
- maxEthToSpend: valueToSend,
400
- deadline: timestamp + 30n,
401
- sqrtPriceLimitX96: 0n,
402
- nonce: randomNonce(),
403
- sourceChainId: chain.id,
404
- destinationChainId: chain.id,
405
- };
406
-
407
- const permitBuySignature = await walletClient.signTypedData(
408
- permitBuyOnSecondaryAndCommentTypedDataDefinition(permitBuy),
409
- );
410
-
411
- await testClient.setBalance({
412
- address: executorAccount,
413
- value: parseEther("1"),
414
- });
415
-
416
- const { request } = await publicClient.simulateContract({
417
- abi: callerAndCommenterABI,
418
- address:
419
- callerAndCommenterAddress[
420
- chain.id as keyof typeof callerAndCommenterAddress
421
- ],
422
- functionName: "permitBuyOnSecondaryAndComment",
423
- args: [permitBuy, permitBuySignature],
424
- value: valueToSend,
425
- account: executorAccount,
426
- });
427
-
428
- await simulateAndWriteContractWithRetries({
429
- parameters: request,
430
- walletClient,
431
- publicClient,
432
- });
433
-
434
- // now PERMIT SELL ON SECONDARY TEST
435
- const quantityToSell = 3n;
436
-
437
- const sellResult = await collectorClient.sell1155OnSecondary({
438
- account: collectorAccount,
439
- quantity: quantityToSell,
440
- contract: contractAddress,
441
- tokenId: newTokenId,
442
- });
443
-
444
- expect(sellResult.error).toBeUndefined();
445
-
446
- // approve 1155s for callerAndCommenter to transfer, when selling
447
- await simulateAndWriteContractWithRetries({
448
- parameters: {
449
- abi: zoraCreator1155ImplABI,
450
- address: contractAddress,
451
- functionName: "setApprovalForAll",
452
- account: collectorAccount,
453
- args: [
454
- callerAndCommenterAddress[
455
- chain.id as keyof typeof callerAndCommenterAddress
456
- ],
457
- true,
458
- ],
459
- },
460
- walletClient,
461
- publicClient,
462
- });
463
-
464
- // now sell on secondary with comment
465
- // by calling the caller and commenter contract
466
- // if including a comment, must send sparkValue() as value
467
- // function signature:
468
- // function sellOnSecondaryAndComment(
469
- // address commenter,
470
- // uint256 quantity,
471
- // address collection,
472
- // uint256 tokenId,
473
- // address payable recipient,
474
- // uint256 minEthToAcquire,
475
- // uint160 sqrtPriceLimitX96,
476
- // string calldata comment
477
- // )
478
- await simulateAndWriteContractWithRetries({
479
- parameters: {
480
- abi: callerAndCommenterABI,
481
- address:
482
- callerAndCommenterAddress[
483
- chain.id as keyof typeof callerAndCommenterAddress
484
- ],
485
- functionName: "sellOnSecondaryAndComment",
486
- account: collectorAccount,
487
- args: [
488
- collectorAccount,
489
- quantityToSell,
490
- contractAddress,
491
- newTokenId,
492
- collectorAccount,
493
- // sell result with slippage
494
- (sellResult.price!.wei.total * 95n) / 100n,
495
- 0n,
496
- "test comment",
497
- ],
498
- value: sparkValue(),
499
- },
500
- walletClient,
501
- publicClient,
502
- });
503
- },
504
- 20_000,
505
- );
506
260
  });
@@ -4,8 +4,6 @@ import {
4
4
  zoraCreator1155ImplABI,
5
5
  safeTransferSwapAbiParameters,
6
6
  secondarySwapABI,
7
- callerAndCommenterABI,
8
- callerAndCommenterAddress,
9
7
  } from "@zoralabs/protocol-deployments";
10
8
  import { makeContractParameters, PublicClient } from "src/utils";
11
9
  import { getUniswapQuote } from "./uniswap/uniswapQuote";
@@ -29,8 +27,6 @@ const ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
29
27
  const ERROR_SECONDARY_NOT_CONFIGURED =
30
28
  "Secondary not configured for given contract and token";
31
29
  export const ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
32
- export const ERROR_RECIPIENT_MISMATCH =
33
- "Recipient must be the same as the caller if there is a comment";
34
30
 
35
31
  // Helper function to create error objects
36
32
  function makeError(errorMessage: string) {
@@ -50,8 +46,6 @@ type Call =
50
46
  };
51
47
 
52
48
  async function makeBuy({
53
- contract,
54
- tokenId,
55
49
  erc20z,
56
50
  poolBalance,
57
51
  amount,
@@ -61,11 +55,8 @@ async function makeBuy({
61
55
  chainId,
62
56
  slippage,
63
57
  publicClient,
64
- comment,
65
58
  }: {
66
59
  erc20z: Address;
67
- contract: Address;
68
- tokenId: bigint;
69
60
  poolBalance: { erc20z: bigint };
70
61
  amount: bigint;
71
62
  quantity: bigint;
@@ -73,144 +64,27 @@ async function makeBuy({
73
64
  recipient?: Address;
74
65
  chainId: number;
75
66
  slippage: number;
76
- comment: string | undefined;
77
67
  publicClient: PublicClient;
78
68
  }): Promise<Call> {
79
69
  const costWithSlippage = calculateSlippageUp(amount, slippage);
80
- const accountAddress = addressOrAccountAddress(account);
81
-
82
- const validationResult = await validateBuyConditions({
83
- poolBalance,
84
- quantity,
85
- costWithSlippage,
86
- accountAddress,
87
- publicClient,
88
- });
89
-
90
- if (validationResult.error) {
91
- return makeError(validationResult.error);
92
- }
93
70
 
94
- if (comment && comment !== "") {
95
- return handleBuyWithComment({
96
- accountAddress,
97
- recipient,
98
- chainId,
99
- quantity,
100
- contract,
101
- tokenId,
102
- costWithSlippage,
103
- comment,
104
- account,
105
- });
106
- }
71
+ // we cannot buy all the available tokens in a pool (the quote fails if we try doing that)
72
+ const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
107
73
 
108
- return handleBuyWithoutComment({
109
- erc20z,
110
- quantity,
111
- recipient,
112
- accountAddress,
113
- costWithSlippage,
114
- chainId,
115
- account,
116
- });
117
- }
74
+ const accountAddress = addressOrAccountAddress(account);
118
75
 
119
- async function validateBuyConditions({
120
- poolBalance,
121
- quantity,
122
- costWithSlippage,
123
- accountAddress,
124
- publicClient,
125
- }: {
126
- poolBalance: { erc20z: bigint };
127
- quantity: bigint;
128
- costWithSlippage: bigint;
129
- accountAddress: Address;
130
- publicClient: PublicClient;
131
- }): Promise<{ error?: string }> {
132
- const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
133
76
  const availableToSpend = await publicClient.getBalance({
134
77
  address: accountAddress,
135
78
  });
136
79
 
137
80
  if (costWithSlippage > availableToSpend) {
138
- return { error: ERROR_INSUFFICIENT_WALLET_FUNDS };
81
+ return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
139
82
  }
140
83
 
141
84
  if (availableToBuy < BigInt(quantity)) {
142
- return { error: ERROR_INSUFFICIENT_POOL_SUPPLY };
143
- }
144
-
145
- return {};
146
- }
147
-
148
- function handleBuyWithComment({
149
- accountAddress,
150
- recipient,
151
- chainId,
152
- quantity,
153
- contract,
154
- tokenId,
155
- costWithSlippage,
156
- comment,
157
- account,
158
- }: {
159
- accountAddress: Address;
160
- recipient?: Address;
161
- chainId: number;
162
- quantity: bigint;
163
- contract: Address;
164
- tokenId: bigint;
165
- costWithSlippage: bigint;
166
- comment: string;
167
- account: Address | Account;
168
- }): Call {
169
- if (recipient && recipient !== accountAddress) {
170
- return makeError(ERROR_RECIPIENT_MISMATCH);
85
+ return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
171
86
  }
172
87
 
173
- return {
174
- parameters: makeContractParameters({
175
- abi: callerAndCommenterABI,
176
- address:
177
- callerAndCommenterAddress[
178
- chainId as keyof typeof callerAndCommenterAddress
179
- ],
180
- functionName: "buyOnSecondaryAndComment",
181
- args: [
182
- accountAddress,
183
- quantity,
184
- contract,
185
- tokenId,
186
- accountAddress,
187
- costWithSlippage,
188
- 0n,
189
- comment,
190
- ],
191
- account,
192
- value: costWithSlippage,
193
- }),
194
- };
195
- }
196
-
197
- function handleBuyWithoutComment({
198
- erc20z,
199
- quantity,
200
- recipient,
201
- accountAddress,
202
- costWithSlippage,
203
- chainId,
204
- account,
205
- }: {
206
- erc20z: Address;
207
- quantity: bigint;
208
- recipient?: Address;
209
- accountAddress: Address;
210
- costWithSlippage: bigint;
211
- chainId: number;
212
- account: Address | Account;
213
- }): Call {
214
88
  return {
215
89
  parameters: makeContractParameters({
216
90
  abi: secondarySwapABI,
@@ -225,7 +99,7 @@ function handleBuyWithoutComment({
225
99
  costWithSlippage,
226
100
  0n,
227
101
  ],
228
- account,
102
+ account: account,
229
103
  value: costWithSlippage,
230
104
  }),
231
105
  };
@@ -251,7 +125,6 @@ export async function buyWithSlippage({
251
125
  account,
252
126
  slippage = UNISWAP_SLIPPAGE,
253
127
  recipient,
254
- comment,
255
128
  }: BuyWithSlippageInput & {
256
129
  chainId: number;
257
130
  publicClient: PublicClient;
@@ -286,8 +159,6 @@ export async function buyWithSlippage({
286
159
 
287
160
  const call = await makeBuy({
288
161
  erc20z,
289
- contract,
290
- tokenId,
291
162
  poolBalance,
292
163
  amount,
293
164
  quantity,
@@ -295,7 +166,6 @@ export async function buyWithSlippage({
295
166
  recipient,
296
167
  chainId,
297
168
  slippage,
298
- comment,
299
169
  publicClient,
300
170
  });
301
171
 
@@ -47,8 +47,6 @@ export type BuyWithSlippageInput = {
47
47
  slippage?: number;
48
48
  // Optional recipient address (if different from buyer/seller)
49
49
  recipient?: Address;
50
- // Optional comment to add to the swap
51
- comment?: string;
52
50
  };
53
51
 
54
52
  // Same structure as BuyWithSlippageInput
@@ -19,7 +19,7 @@ import { zoraSparksManagerImplABI } from "@zoralabs/protocol-deployments";
19
19
  const anvilTest = makeAnvilTest({
20
20
  forkUrl: forkUrls.zoraMainnet,
21
21
  anvilChainId: zora.id,
22
- forkBlockNumber: 22029945,
22
+ forkBlockNumber: 22160611,
23
23
  });
24
24
  describe("Sponsored Mints Spender with Relay", () => {
25
25
  anvilTest(
@@ -179,6 +179,5 @@ describe("Sponsored Mints Spender with Relay", () => {
179
179
 
180
180
  expect(transferReceipt.status).toBe("success");
181
181
  },
182
- 20_000,
183
182
  );
184
183
  });
package/src/test-utils.ts CHANGED
@@ -7,11 +7,8 @@ import {
7
7
  Hex,
8
8
  PublicClient,
9
9
  encodeAbiParameters,
10
- keccak256,
11
- toBytes,
12
10
  parseAbiParameters,
13
11
  } from "viem";
14
- import { NewContractParams } from "./create/types";
15
12
  import { expect } from "vitest";
16
13
 
17
14
  export const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
@@ -20,8 +17,6 @@ export const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
20
17
  });
21
18
 
22
19
  expect(receipt.status).toBe("success");
23
-
24
- return receipt;
25
20
  };
26
21
 
27
22
  export const getFixedPricedMinter = async ({
@@ -42,17 +37,3 @@ export const fixedPriceMinterMinterArguments = ({
42
37
  }: {
43
38
  mintRecipient: Address;
44
39
  }) => encodeAbiParameters(parseAbiParameters("address"), [mintRecipient]);
45
-
46
- const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
47
-
48
- export function randomNewContract(): NewContractParams {
49
- return {
50
- name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
51
- uri: demoContractMetadataURI,
52
- };
53
- }
54
-
55
- export const randomNonce = () =>
56
- keccak256(toBytes(Math.round(Math.random() * 1000)));
57
- export const thirtySecondsFromNow = () =>
58
- BigInt(Math.round(new Date().getTime() / 1000)) + 30n;