@zoralabs/protocol-sdk 0.7.2-ALLOWLIST.0 → 0.7.2

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 (63) hide show
  1. package/.turbo/turbo-build.log +15 -0
  2. package/CHANGELOG.md +2 -2
  3. package/dist/apis/http-api-base.d.ts.map +1 -1
  4. package/dist/constants.d.ts +27 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/create/1155-create-helper.d.ts +0 -1
  7. package/dist/create/1155-create-helper.d.ts.map +1 -1
  8. package/dist/create/token-setup.d.ts +4 -3
  9. package/dist/create/token-setup.d.ts.map +1 -1
  10. package/dist/create/types.d.ts +4 -24
  11. package/dist/create/types.d.ts.map +1 -1
  12. package/dist/index.cjs +127 -237
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +0 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +128 -238
  17. package/dist/index.js.map +1 -1
  18. package/dist/mint/mint-queries.d.ts +1 -3
  19. package/dist/mint/mint-queries.d.ts.map +1 -1
  20. package/dist/mint/mint-transactions.d.ts +3 -5
  21. package/dist/mint/mint-transactions.d.ts.map +1 -1
  22. package/dist/mint/subgraph-mint-getter.d.ts +2 -1
  23. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  24. package/dist/mint/subgraph-queries.d.ts +14 -27
  25. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  26. package/dist/mint/types.d.ts +11 -22
  27. package/dist/mint/types.d.ts.map +1 -1
  28. package/dist/mints/mints-contracts.d.ts +16 -0
  29. package/dist/mints/mints-contracts.d.ts.map +1 -1
  30. package/dist/premint/premint-client.d.ts +8 -0
  31. package/dist/premint/premint-client.d.ts.map +1 -1
  32. package/package.json +1 -2
  33. package/src/apis/http-api-base.ts +0 -12
  34. package/src/constants.ts +36 -0
  35. package/src/create/1155-create-helper.test.ts +325 -0
  36. package/src/create/1155-create-helper.ts +0 -17
  37. package/src/create/token-setup.ts +19 -116
  38. package/src/create/types.ts +4 -32
  39. package/src/index.ts +0 -4
  40. package/src/mint/mint-client.test.ts +263 -0
  41. package/src/mint/mint-queries.ts +0 -6
  42. package/src/mint/mint-transactions.ts +8 -74
  43. package/src/mint/subgraph-mint-getter.ts +41 -17
  44. package/src/mint/subgraph-queries.ts +36 -39
  45. package/src/mint/types.ts +12 -38
  46. package/src/mints/mints-contracts.test.ts +529 -0
  47. package/src/mints/mints-eth-unwrapper-and-caller.test.ts +467 -0
  48. package/src/mints/mints-queries.test.ts +105 -0
  49. package/src/premint/premint-client.test.ts +290 -0
  50. package/src/premint/preminter.test.ts +866 -0
  51. package/test-integration/setup-test-contracts.ts +96 -0
  52. package/tsconfig.build.json +10 -0
  53. package/tsup.config.ts +12 -0
  54. package/dist/allow-list/allow-list-client.d.ts +0 -25
  55. package/dist/allow-list/allow-list-client.d.ts.map +0 -1
  56. package/dist/allow-list/types.d.ts +0 -14
  57. package/dist/allow-list/types.d.ts.map +0 -1
  58. package/dist/apis/generated/allow-list-api-types.d.ts +0 -288
  59. package/dist/apis/generated/allow-list-api-types.d.ts.map +0 -1
  60. package/src/allow-list/allow-list-client.ts +0 -102
  61. package/src/allow-list/types.ts +0 -15
  62. package/src/apis/generated/allow-list-api-types.ts +0 -288
  63. package/yarn-error.log +0 -8602
@@ -0,0 +1,529 @@
1
+ import { describe, expect } from "vitest";
2
+
3
+ import { forkUrls, makeAnvilTest } from "src/anvil";
4
+ import {
5
+ defaultContractConfig,
6
+ defaultPremintConfigV2,
7
+ } from "src/premint/preminter.test";
8
+ import {
9
+ zoraCreator1155ImplABI,
10
+ zoraMints1155ABI,
11
+ zoraMints1155Address,
12
+ zoraMintsManagerImplABI,
13
+ zoraMintsManagerImplAddress,
14
+ PremintMintArguments,
15
+ premintTypedDataDefinition,
16
+ } from "@zoralabs/protocol-deployments";
17
+ import {
18
+ Address,
19
+ BaseError,
20
+ ContractFunctionRevertedError,
21
+ WalletClient,
22
+ parseEther,
23
+ } from "viem";
24
+ import {
25
+ collectPremintV2WithMintsParams,
26
+ collectWithMintsParams,
27
+ mintWithEthParams,
28
+ mintsBalanceOfAccountParams,
29
+ CollectMintArguments,
30
+ decodeCallFailedError,
31
+ makePermitToCollectPremintOrNonPremint,
32
+ } from "./mints-contracts";
33
+ import { getPremintCollectionAddress } from "src/premint/preminter";
34
+ import { PremintConfigVersion } from "src/premint/contract-types";
35
+ import { zora } from "viem/chains";
36
+ import {
37
+ fixedPriceMinterMinterArguments,
38
+ getFixedPricedMinter,
39
+ waitForSuccess,
40
+ } from "src/test-utils";
41
+ import { PublicClient } from "src/utils";
42
+
43
+ const mintsMainnetDeployedBlock = 15372992;
44
+
45
+ const anvilTest = makeAnvilTest({
46
+ forkUrl: forkUrls.zoraMainnet,
47
+ forkBlockNumber: mintsMainnetDeployedBlock,
48
+ anvilChainId: zora.id,
49
+ });
50
+
51
+ const setupContractUsingPremint = async ({
52
+ walletClient,
53
+ publicClient,
54
+ chainId,
55
+ creatorAccount,
56
+ }: {
57
+ walletClient: WalletClient;
58
+ publicClient: PublicClient;
59
+ chainId: keyof typeof zoraMintsManagerImplAddress;
60
+ creatorAccount: Address;
61
+ }) => {
62
+ const fixedPriceMinter = await getFixedPricedMinter({
63
+ publicClient,
64
+ chainId,
65
+ });
66
+
67
+ const premintConfig = defaultPremintConfigV2({
68
+ fixedPriceMinter,
69
+ creatorAccount: creatorAccount!,
70
+ pricePerToken: 0n,
71
+ });
72
+
73
+ const contractConfig = defaultContractConfig({
74
+ contractAdmin: creatorAccount!,
75
+ });
76
+
77
+ contractConfig.contractName = "Testing contract for MINTS";
78
+
79
+ const contractAddress = await getPremintCollectionAddress({
80
+ contract: contractConfig,
81
+ publicClient,
82
+ });
83
+
84
+ const signature = await walletClient.signTypedData({
85
+ ...premintTypedDataDefinition({
86
+ verifyingContract: contractAddress,
87
+ chainId,
88
+ premintConfig,
89
+ premintConfigVersion: PremintConfigVersion.V2,
90
+ }),
91
+ account: creatorAccount!,
92
+ });
93
+
94
+ return {
95
+ premintConfig,
96
+ contractConfig,
97
+ contractAddress,
98
+ signature,
99
+ fixedPriceMinter,
100
+ };
101
+ };
102
+
103
+ export const collectMINTsWithEth = async ({
104
+ publicClient,
105
+ walletClient,
106
+ chainId,
107
+ collectorAccount,
108
+ quantityToMint,
109
+ }: {
110
+ publicClient: PublicClient;
111
+ chainId: keyof typeof zoraMintsManagerImplAddress;
112
+ collectorAccount: Address;
113
+ quantityToMint: bigint;
114
+ walletClient: WalletClient;
115
+ }) => {
116
+ const pricePerMint = await publicClient.readContract({
117
+ abi: zoraMintsManagerImplABI,
118
+ address: zoraMintsManagerImplAddress[chainId],
119
+ functionName: "getEthPrice",
120
+ });
121
+
122
+ const { request } = await publicClient.simulateContract(
123
+ mintWithEthParams({
124
+ chainId: chainId,
125
+ quantity: quantityToMint,
126
+ recipient: collectorAccount!,
127
+ pricePerMint,
128
+ account: collectorAccount!,
129
+ }),
130
+ );
131
+
132
+ await waitForSuccess(await walletClient.writeContract(request), publicClient);
133
+ const mintsTokenId = await publicClient.readContract({
134
+ abi: zoraMintsManagerImplABI,
135
+ address: zoraMintsManagerImplAddress[chainId],
136
+ functionName: "mintableEthToken",
137
+ });
138
+
139
+ return mintsTokenId;
140
+ };
141
+
142
+ describe("MINTs collecting and redeeming.", () => {
143
+ anvilTest(
144
+ "can collect MINTs with ETH",
145
+ async ({
146
+ viemClients: { testClient, walletClient, publicClient, chain },
147
+ }) => {
148
+ const [collectorAccount] = await walletClient.getAddresses();
149
+ const initialMintsQuantityToMint = 20n;
150
+
151
+ await testClient.setBalance({
152
+ address: collectorAccount!,
153
+ value: parseEther("10"),
154
+ });
155
+
156
+ const chainId = chain.id as keyof typeof zoraMintsManagerImplAddress;
157
+
158
+ const pricePerMint = await publicClient.readContract({
159
+ abi: zoraMintsManagerImplABI,
160
+ address: zoraMintsManagerImplAddress[chainId],
161
+ functionName: "getEthPrice",
162
+ });
163
+
164
+ const simulated = await publicClient.simulateContract(
165
+ mintWithEthParams({
166
+ chainId: chainId,
167
+ quantity: initialMintsQuantityToMint,
168
+ pricePerMint,
169
+ account: collectorAccount!,
170
+ }),
171
+ );
172
+
173
+ await waitForSuccess(
174
+ await walletClient.writeContract(simulated.request),
175
+ publicClient,
176
+ );
177
+
178
+ // check that the balance is correct
179
+ const totalMintsBalance = await publicClient.readContract(
180
+ mintsBalanceOfAccountParams({
181
+ account: collectorAccount!,
182
+ chainId: chainId,
183
+ }),
184
+ );
185
+
186
+ expect(totalMintsBalance).toEqual(initialMintsQuantityToMint);
187
+ },
188
+ 20_000,
189
+ );
190
+ anvilTest(
191
+ "can use MINTs to collect premint and non-premint",
192
+ async ({
193
+ viemClients: { walletClient, publicClient, testClient, chain },
194
+ }) => {
195
+ const [collectorAccount, creatorAccount] =
196
+ await walletClient.getAddresses();
197
+
198
+ const chainId = chain.id as keyof typeof zoraMintsManagerImplAddress;
199
+
200
+ // 1. Create a premint and contract creation config
201
+ const {
202
+ premintConfig,
203
+ contractConfig,
204
+ contractAddress,
205
+ signature: premintSignature,
206
+ fixedPriceMinter,
207
+ } = await setupContractUsingPremint({
208
+ walletClient,
209
+ publicClient,
210
+ chainId,
211
+ creatorAccount: creatorAccount!,
212
+ });
213
+
214
+ await testClient.setBalance({
215
+ address: collectorAccount!,
216
+ value: parseEther("10"),
217
+ });
218
+
219
+ const initialMINTsBalance = await publicClient.readContract(
220
+ mintsBalanceOfAccountParams({
221
+ account: collectorAccount!,
222
+ chainId: chainId,
223
+ }),
224
+ );
225
+
226
+ // 2. Collect some MINTs
227
+ const initialMintsQuantityToMint = 20n;
228
+
229
+ const mintsTokenId = await collectMINTsWithEth({
230
+ publicClient,
231
+ walletClient,
232
+ chainId,
233
+ collectorAccount: collectorAccount!,
234
+ quantityToMint: initialMintsQuantityToMint,
235
+ });
236
+
237
+ expect(
238
+ await publicClient.readContract(
239
+ mintsBalanceOfAccountParams({
240
+ account: collectorAccount!,
241
+ chainId: chainId,
242
+ }),
243
+ ),
244
+ ).toEqual(initialMINTsBalance + initialMintsQuantityToMint);
245
+
246
+ // 3. Use MINTS to collect the premint
247
+ const mintArguments: PremintMintArguments = {
248
+ mintComment: "Hi!",
249
+ mintRecipient: collectorAccount!,
250
+ mintRewardsRecipients: [],
251
+ };
252
+
253
+ const firstQuantityToCollect = 4n;
254
+
255
+ // 4. Collect Premint using MINT
256
+
257
+ const collectPremintSimulated = await publicClient.simulateContract(
258
+ collectPremintV2WithMintsParams({
259
+ tokenIds: [mintsTokenId],
260
+ quantities: [firstQuantityToCollect],
261
+ chainId: chainId,
262
+ contractCreationConfig: contractConfig,
263
+ premintConfig: premintConfig,
264
+ mintArguments,
265
+ premintSignature: premintSignature,
266
+ account: collectorAccount!,
267
+ }),
268
+ );
269
+
270
+ await waitForSuccess(
271
+ await walletClient.writeContract(collectPremintSimulated.request),
272
+ publicClient,
273
+ );
274
+
275
+ const erc1155Balance = await publicClient.readContract({
276
+ abi: zoraCreator1155ImplABI,
277
+ address: contractAddress,
278
+ functionName: "balanceOf",
279
+ args: [collectorAccount!, mintsTokenId],
280
+ });
281
+
282
+ expect(erc1155Balance).toBe(firstQuantityToCollect);
283
+
284
+ // 4. Use MINTs to collect from the created contract non-premint.
285
+ const secondQuantityToCollect = 3n;
286
+
287
+ const collectMintArguments: CollectMintArguments = {
288
+ mintComment: "comment!",
289
+ minterArguments: fixedPriceMinterMinterArguments({
290
+ mintRecipient: collectorAccount!,
291
+ }),
292
+ mintRewardsRecipients: [],
293
+ };
294
+
295
+ const collectSimulated = await publicClient.simulateContract(
296
+ collectWithMintsParams({
297
+ tokenIds: [mintsTokenId],
298
+ quantities: [secondQuantityToCollect],
299
+ account: collectorAccount!,
300
+ chainId: chainId,
301
+ minter: fixedPriceMinter,
302
+ mintArguments: collectMintArguments,
303
+ zoraCreator1155Contract: contractAddress,
304
+ zoraCreator1155TokenId: 1n,
305
+ }),
306
+ );
307
+
308
+ await waitForSuccess(
309
+ await walletClient.writeContract(collectSimulated.request),
310
+ publicClient,
311
+ );
312
+
313
+ const erc1155BalanceAfter = await publicClient.readContract({
314
+ abi: zoraCreator1155ImplABI,
315
+ address: contractAddress,
316
+ functionName: "balanceOf",
317
+ args: [collectorAccount!, mintsTokenId],
318
+ });
319
+
320
+ expect(erc1155BalanceAfter).toBe(
321
+ firstQuantityToCollect + secondQuantityToCollect,
322
+ );
323
+
324
+ const totalMintsBalance = await publicClient.readContract(
325
+ mintsBalanceOfAccountParams({
326
+ account: collectorAccount!,
327
+ chainId: chainId,
328
+ }),
329
+ );
330
+
331
+ expect(totalMintsBalance).toBe(
332
+ initialMINTsBalance +
333
+ initialMintsQuantityToMint -
334
+ (firstQuantityToCollect + secondQuantityToCollect),
335
+ );
336
+ },
337
+ 20_000,
338
+ );
339
+ anvilTest(
340
+ "can decode errors from transferBatchToManagerAndCall",
341
+ async ({
342
+ viemClients: { walletClient, publicClient, testClient, chain },
343
+ }) => {
344
+ const [collectorAccount, creatorAccount] =
345
+ await walletClient.getAddresses();
346
+
347
+ const chainId = chain.id as keyof typeof zoraMintsManagerImplAddress;
348
+
349
+ // 1. Create a premint and contract creation config
350
+ const { premintConfig, contractConfig } = await setupContractUsingPremint(
351
+ {
352
+ walletClient,
353
+ publicClient,
354
+ chainId,
355
+ creatorAccount: creatorAccount!,
356
+ },
357
+ );
358
+
359
+ await testClient.setBalance({
360
+ address: collectorAccount!,
361
+ value: parseEther("10"),
362
+ });
363
+
364
+ // 2. Collect some MINTs
365
+ const mintsTokenId = await collectMINTsWithEth({
366
+ publicClient,
367
+ walletClient,
368
+ chainId,
369
+ collectorAccount: collectorAccount!,
370
+ quantityToMint: 10n,
371
+ });
372
+
373
+ // 3. Use MINTS to collect the premint
374
+ const mintArguments: PremintMintArguments = {
375
+ mintComment: "",
376
+ mintRecipient: collectorAccount!,
377
+ mintRewardsRecipients: [],
378
+ };
379
+
380
+ // 4. Collect Premint using a bad signature
381
+ try {
382
+ await publicClient.simulateContract(
383
+ collectPremintV2WithMintsParams({
384
+ tokenIds: [mintsTokenId],
385
+ quantities: [2n],
386
+ chainId: chainId,
387
+ contractCreationConfig: contractConfig,
388
+ premintConfig: premintConfig,
389
+ mintArguments,
390
+ // put in a bad signature
391
+ premintSignature: "0x",
392
+ account: collectorAccount!,
393
+ }),
394
+ );
395
+ } catch (err) {
396
+ if (err instanceof BaseError) {
397
+ const revertError = err.walk(
398
+ (err) => err instanceof ContractFunctionRevertedError,
399
+ );
400
+ if (revertError instanceof ContractFunctionRevertedError) {
401
+ const errorName = revertError.data?.errorName ?? "";
402
+
403
+ if (errorName === "CallFailed") {
404
+ const decodedInternalError = decodeCallFailedError(revertError);
405
+
406
+ expect(decodedInternalError.errorName).toEqual(
407
+ "InvalidSignature",
408
+ );
409
+ }
410
+ }
411
+ } else {
412
+ throw err;
413
+ }
414
+ }
415
+ },
416
+ 20_000,
417
+ );
418
+ anvilTest(
419
+ "can use MINTs to gaslessly collect premint",
420
+ async ({
421
+ viemClients: { walletClient, publicClient, testClient, chain },
422
+ }) => {
423
+ const [collectorAccount, creatorAccount, permitExecutorAccount] =
424
+ await walletClient.getAddresses();
425
+
426
+ const chainId = chain.id as keyof typeof zoraMintsManagerImplAddress;
427
+
428
+ // 1. Create a premint and contract creation config
429
+ const {
430
+ premintConfig,
431
+ contractConfig,
432
+ signature: premintSignature,
433
+ } = await setupContractUsingPremint({
434
+ walletClient,
435
+ publicClient,
436
+ chainId,
437
+ creatorAccount: creatorAccount!,
438
+ });
439
+
440
+ await testClient.setBalance({
441
+ address: collectorAccount!,
442
+ value: parseEther("10"),
443
+ });
444
+
445
+ // 2. Collect some MINTs
446
+ const initialMintsQuantityToMint = 20n;
447
+
448
+ const mintsTokenId = await collectMINTsWithEth({
449
+ publicClient,
450
+ walletClient,
451
+ chainId,
452
+ collectorAccount: collectorAccount!,
453
+ quantityToMint: initialMintsQuantityToMint,
454
+ });
455
+
456
+ const initialMintsBalance = await publicClient.readContract(
457
+ mintsBalanceOfAccountParams({
458
+ account: collectorAccount!,
459
+ chainId: chainId,
460
+ }),
461
+ );
462
+
463
+ // 3. Use MINTS to collect the premint
464
+ const mintArguments: PremintMintArguments = {
465
+ mintComment: "Hi!",
466
+ mintRecipient: collectorAccount!,
467
+ mintRewardsRecipients: [],
468
+ };
469
+
470
+ // 4. Collect Premint using MINT
471
+
472
+ // now sign a message to collect.
473
+ // get random integer:
474
+ const nonce = BigInt(Math.round(Math.random() * 1_000_000));
475
+
476
+ const blockTime = (await publicClient.getBlock()).timestamp;
477
+
478
+ const premintQuantityToCollect = 3n;
479
+
480
+ // make signature deadline 10 seconds from now
481
+ const deadline = blockTime + 10n;
482
+
483
+ // get typed data to sign, as well as permit to collect with
484
+ const { typedData, permit } = makePermitToCollectPremintOrNonPremint({
485
+ mintsOwner: collectorAccount!,
486
+ chainId,
487
+ deadline,
488
+ tokenIds: [mintsTokenId],
489
+ // this quantity of MINTs will be used to collect premint
490
+ // and will be burned. This same quantity is the quantity of
491
+ // premint to collect.
492
+ quantities: [premintQuantityToCollect],
493
+ nonce,
494
+ premint: {
495
+ contractCreationConfig: contractConfig,
496
+ mintArguments,
497
+ premintConfig,
498
+ premintSignature,
499
+ },
500
+ });
501
+
502
+ const permitSignature = await walletClient.signTypedData(typedData);
503
+
504
+ // now simulate and execute the transaction
505
+ const permitSimulated = await publicClient.simulateContract({
506
+ abi: zoraMints1155ABI,
507
+ address: zoraMints1155Address[chainId],
508
+ functionName: "permitSafeTransferBatch",
509
+ args: [permit, permitSignature],
510
+ account: permitExecutorAccount,
511
+ });
512
+
513
+ await waitForSuccess(
514
+ await walletClient.writeContract(permitSimulated.request),
515
+ publicClient,
516
+ );
517
+
518
+ expect(
519
+ await publicClient.readContract(
520
+ mintsBalanceOfAccountParams({
521
+ account: collectorAccount!,
522
+ chainId: chainId,
523
+ }),
524
+ ),
525
+ ).toBe(initialMintsBalance - premintQuantityToCollect);
526
+ },
527
+ 20_000,
528
+ );
529
+ });