@zoralabs/protocol-sdk 0.5.10 → 0.5.12

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 (39) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +10 -0
  4. package/dist/create/1155-create-helper.d.ts +2 -2
  5. package/dist/create/1155-create-helper.d.ts.map +1 -1
  6. package/dist/index.cjs +136 -212
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +135 -209
  11. package/dist/index.js.map +1 -1
  12. package/dist/mint/mint-client.d.ts +3 -4
  13. package/dist/mint/mint-client.d.ts.map +1 -1
  14. package/dist/mints/mints-contracts.d.ts +2868 -2027
  15. package/dist/mints/mints-contracts.d.ts.map +1 -1
  16. package/dist/mints/mints-eth-unwrapper-and-caller.d.ts +78 -0
  17. package/dist/mints/mints-eth-unwrapper-and-caller.d.ts.map +1 -0
  18. package/dist/mints/mints-relay-example.d.ts +60 -0
  19. package/dist/mints/mints-relay-example.d.ts.map +1 -0
  20. package/dist/premint/premint-client.d.ts +1 -1
  21. package/dist/premint/premint-client.d.ts.map +1 -1
  22. package/dist/preminter.d.ts +23 -11
  23. package/dist/preminter.d.ts.map +1 -1
  24. package/dist/test-utils.d.ts +11 -0
  25. package/dist/test-utils.d.ts.map +1 -0
  26. package/dist/utils.d.ts +3 -0
  27. package/dist/utils.d.ts.map +1 -0
  28. package/package.json +6 -4
  29. package/src/create/1155-create-helper.ts +14 -11
  30. package/src/index.ts +2 -0
  31. package/src/mint/mint-client.ts +16 -19
  32. package/src/mints/mints-contracts.test.ts +32 -225
  33. package/src/mints/mints-contracts.ts +200 -281
  34. package/src/mints/mints-eth-unwrapper-and-caller.test.ts +467 -0
  35. package/src/mints/mints-eth-unwrapper-and-caller.ts +83 -0
  36. package/src/mints/mints-relay-example.ts +313 -0
  37. package/src/premint/premint-client.ts +15 -11
  38. package/src/test-utils.ts +39 -0
  39. package/src/utils.ts +30 -0
@@ -6,9 +6,6 @@ import {
6
6
  defaultPremintConfigV2,
7
7
  } from "src/premint/preminter.test";
8
8
  import {
9
- mintsEthUnwrapperAndCallerConfig,
10
- zoraCreator1155FactoryImplAddress,
11
- zoraCreator1155FactoryImplConfig,
12
9
  zoraCreator1155ImplABI,
13
10
  zoraMints1155ABI,
14
11
  zoraMints1155Address,
@@ -19,24 +16,18 @@ import {
19
16
  Address,
20
17
  BaseError,
21
18
  ContractFunctionRevertedError,
22
- Hex,
23
19
  PublicClient,
24
20
  WalletClient,
25
- encodeFunctionData,
26
21
  parseEther,
27
22
  } from "viem";
28
23
  import {
29
24
  collectPremintV2WithMintsParams,
30
25
  collectWithMintsParams,
31
26
  mintWithEthParams,
32
- permitTransferBatchToManagerAndCallParams,
33
27
  mintsBalanceOfAccountParams,
34
- collectPremintWithMintsTypedDataDefinition,
35
28
  CollectMintArguments,
36
- fixedPriceMinterMinterArguments,
37
29
  decodeCallFailedError,
38
- safeTransferBatchAndUnwrapTypedDataDefinition,
39
- safeTransferAndUnwrapTypedDataDefinition,
30
+ makePermitToCollectPremintOrNonPremint,
40
31
  } from "./mints-contracts";
41
32
  import { getPremintCollectionAddress } from "src/premint/preminter";
42
33
  import {
@@ -44,27 +35,21 @@ import {
44
35
  PremintConfigVersion,
45
36
  } from "src/premint/contract-types";
46
37
  import { premintTypedDataDefinition } from "src/premint/preminter";
47
- import { zoraSepolia } from "viem/chains";
38
+ import { zora } from "viem/chains";
39
+ import {
40
+ fixedPriceMinterMinterArguments,
41
+ getFixedPricedMinter,
42
+ waitForSuccess,
43
+ } from "src/test-utils";
44
+
45
+ const mintsMainnetDeployedBlock = 12990454;
48
46
 
49
47
  const anvilTest = makeAnvilTest({
50
- forkUrl: forkUrls.zoraSepolia,
51
- forkBlockNumber: 7137785,
52
- anvilChainId: zoraSepolia.id,
48
+ forkUrl: forkUrls.zoraMainnet,
49
+ forkBlockNumber: mintsMainnetDeployedBlock,
50
+ anvilChainId: zora.id,
53
51
  });
54
52
 
55
- const getFixedPricedMinter = async ({
56
- publicClient,
57
- chainId,
58
- }: {
59
- publicClient: PublicClient;
60
- chainId: keyof typeof zoraCreator1155FactoryImplAddress;
61
- }) =>
62
- await publicClient.readContract({
63
- abi: zoraCreator1155FactoryImplConfig.abi,
64
- address: zoraCreator1155FactoryImplAddress[chainId],
65
- functionName: "fixedPriceMinter",
66
- });
67
-
68
53
  const setupContractUsingPremint = async ({
69
54
  walletClient,
70
55
  publicClient,
@@ -117,15 +102,7 @@ const setupContractUsingPremint = async ({
117
102
  };
118
103
  };
119
104
 
120
- const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
121
- const receipt = await publicClient.waitForTransactionReceipt({
122
- hash,
123
- });
124
-
125
- expect(receipt.status).toBe("success");
126
- };
127
-
128
- const collectMINTsWithEth = async ({
105
+ export const collectMINTsWithEth = async ({
129
106
  publicClient,
130
107
  walletClient,
131
108
  chainId,
@@ -144,7 +121,7 @@ const collectMINTsWithEth = async ({
144
121
  functionName: "getEthPrice",
145
122
  });
146
123
 
147
- const simulated = await publicClient.simulateContract(
124
+ const { request } = await publicClient.simulateContract(
148
125
  mintWithEthParams({
149
126
  chainId: chainId,
150
127
  quantity: quantityToMint,
@@ -154,10 +131,7 @@ const collectMINTsWithEth = async ({
154
131
  }),
155
132
  );
156
133
 
157
- await waitForSuccess(
158
- await walletClient.writeContract(simulated.request),
159
- publicClient,
160
- );
134
+ await waitForSuccess(await walletClient.writeContract(request), publicClient);
161
135
  const mintsTokenId = await publicClient.readContract({
162
136
  abi: zoraMintsManagerImplABI,
163
137
  address: zoraMintsManagerImplAddress[chainId],
@@ -193,7 +167,6 @@ describe("MINTs collecting and redeeming.", () => {
193
167
  mintWithEthParams({
194
168
  chainId: chainId,
195
169
  quantity: initialMintsQuantityToMint,
196
- recipient: collectorAccount!,
197
170
  pricePerMint,
198
171
  account: collectorAccount!,
199
172
  }),
@@ -217,7 +190,7 @@ describe("MINTs collecting and redeeming.", () => {
217
190
  20_000,
218
191
  );
219
192
  anvilTest(
220
- "can use MINTSs to collect premint and non-premint",
193
+ "can use MINTs to collect premint and non-premint",
221
194
  async ({
222
195
  viemClients: { walletClient, publicClient, testClient, chain },
223
196
  }) => {
@@ -510,180 +483,32 @@ describe("MINTs collecting and redeeming.", () => {
510
483
  const deadline = blockTime + 10n;
511
484
 
512
485
  // get typed data to sign, as well as permit to collect with
513
- const { typedData, permit } = collectPremintWithMintsTypedDataDefinition({
514
- account: collectorAccount!,
515
- chainId: chainId,
516
- mintArguments,
517
- nonce,
486
+ const { typedData, permit } = makePermitToCollectPremintOrNonPremint({
487
+ mintsOwner: collectorAccount!,
488
+ chainId,
518
489
  deadline,
519
490
  tokenIds: [mintsTokenId],
491
+ // this quantity of MINTs will be used to collect premint
492
+ // and will be burned. This same quantity is the quantity of
493
+ // premint to collect.
520
494
  quantities: [premintQuantityToCollect],
521
- contractCreationConfig: contractConfig,
522
- premintConfig: premintConfig,
523
- premintSignature: premintSignature,
495
+ nonce,
496
+ premint: {
497
+ contractCreationConfig: contractConfig,
498
+ mintArguments,
499
+ premintConfig,
500
+ premintSignature,
501
+ },
524
502
  });
525
503
 
526
504
  const permitSignature = await walletClient.signTypedData(typedData);
527
505
 
528
506
  // now simulate and execute the transaction
529
- const permitSimulated = await publicClient.simulateContract({
530
- ...permitTransferBatchToManagerAndCallParams({
531
- permit,
532
- chainId: chainId,
533
- signature: permitSignature,
534
- }),
535
- account: permitExecutorAccount,
536
- });
537
-
538
- await waitForSuccess(
539
- await walletClient.writeContract(permitSimulated.request),
540
- publicClient,
541
- );
542
-
543
- expect(
544
- await publicClient.readContract(
545
- mintsBalanceOfAccountParams({
546
- account: collectorAccount!,
547
- chainId: chainId,
548
- }),
549
- ),
550
- ).toBe(initialMintsBalance - premintQuantityToCollect);
551
- },
552
- 20_000,
553
- );
554
-
555
- anvilTest(
556
- "can use MINTs to gaslessly collect on legacy 1155 contracts",
557
- async ({ viemClients: { walletClient, publicClient, chain } }) => {
558
- const [collectorAccount, permitExecutorAccount] =
559
- await walletClient.getAddresses();
560
-
561
- const chainId = chain.id as keyof typeof zoraMintsManagerImplAddress;
562
-
563
- // 1. Collect some MINTs
564
- const initialMintsQuantityToMint = 20n;
565
-
566
- const mintsTokenId = await collectMINTsWithEth({
567
- publicClient,
568
- walletClient,
569
- chainId,
570
- collectorAccount: collectorAccount!,
571
- quantityToMint: initialMintsQuantityToMint,
572
- });
573
-
574
- const initialMintsBalance = await publicClient.readContract(
575
- mintsBalanceOfAccountParams({
576
- account: collectorAccount!,
577
- chainId: chainId,
578
- }),
579
- );
580
-
581
- // now sign a message to collect.
582
- let nonce = BigInt(Math.round(Math.random() * 1_000_000));
583
-
584
- const blockTime = (await publicClient.getBlock()).timestamp;
585
-
586
- const quantityToMintOn1155 = 3n;
587
-
588
- // make signature deadline 10 seconds from now
589
- const deadline = blockTime + 10n;
590
-
591
- const fixedPriceMinter = await getFixedPricedMinter({
592
- publicClient,
593
- chainId,
594
- });
595
-
596
- const tokenId = 1n;
597
-
598
- const minterArguments = fixedPriceMinterMinterArguments({
599
- mintRecipient: collectorAccount!,
600
- });
601
-
602
- // this is the external contract that will be called
603
- const legacy1155Address = "0x2988C3b4F3A823488e4E2d70F23bD66366639b81";
604
-
605
- // this is the external contract funciton that will be called
606
- const contractCall = encodeFunctionData({
607
- abi: zoraCreator1155ImplABI,
608
- functionName: "mint",
609
- args: [
610
- fixedPriceMinter,
611
- tokenId,
612
- quantityToMintOn1155,
613
- [],
614
- minterArguments,
615
- ],
616
- });
617
-
618
- // get typed data to sign, as well as permit to collect with
619
- const { typedData: batchTransferTypeData, permit: bathTransferPermit } =
620
- safeTransferBatchAndUnwrapTypedDataDefinition({
621
- from: collectorAccount!,
622
- chainId: chainId,
623
- nonce,
624
- deadline,
625
- // token ids to unwrap and burn - must be eth based token ids
626
- tokenIds: [mintsTokenId],
627
- // quantities to unwrap and burn
628
- quantities: [quantityToMintOn1155],
629
- // external address to call
630
- addressToCall: legacy1155Address,
631
- // external contract call
632
- functionToCall: contractCall,
633
- // value to send to external contract, extra value from mints
634
- // will be refunded
635
- valueToSend: parseEther("0.000777") * quantityToMintOn1155,
636
- });
637
-
638
- const permitBatchSignature = await walletClient.signTypedData(
639
- batchTransferTypeData,
640
- );
641
-
642
- // now simulate and execute the transaction
643
- const permitBatchSimulated = await publicClient.simulateContract({
644
- ...permitTransferBatchToManagerAndCallParams({
645
- permit: bathTransferPermit,
646
- chainId: chainId,
647
- signature: permitBatchSignature,
648
- }),
649
- account: permitExecutorAccount,
650
- });
651
-
652
- await waitForSuccess(
653
- await walletClient.writeContract(permitBatchSimulated.request),
654
- publicClient,
655
- );
656
-
657
- nonce = BigInt(Math.round(Math.random() * 1_000_000));
658
-
659
- // make non-batch permit and signtarue
660
- const { typedData: transferTypeData, permit: transferPermit } =
661
- safeTransferAndUnwrapTypedDataDefinition({
662
- from: collectorAccount!,
663
- chainId: chainId,
664
- nonce,
665
- deadline,
666
- // token ids to unwrap and burn - must be eth based token ids
667
- tokenId: mintsTokenId,
668
- // quantities to unwrap and burn
669
- quantity: quantityToMintOn1155,
670
- // external address to call
671
- addressToCall: legacy1155Address,
672
- // external contract call
673
- functionToCall: contractCall,
674
- // value to send to external contract, extra value from mints
675
- // will be refunded
676
- valueToSend: parseEther("0.000777") * quantityToMintOn1155,
677
- });
678
-
679
- const permitSignature =
680
- await walletClient.signTypedData(transferTypeData);
681
-
682
507
  const permitSimulated = await publicClient.simulateContract({
683
508
  abi: zoraMints1155ABI,
684
509
  address: zoraMints1155Address[chainId],
685
- functionName: "permitSafeTransfer",
686
- args: [transferPermit, permitSignature],
510
+ functionName: "permitSafeTransferBatch",
511
+ args: [permit, permitSignature],
687
512
  account: permitExecutorAccount,
688
513
  });
689
514
 
@@ -699,25 +524,7 @@ describe("MINTs collecting and redeeming.", () => {
699
524
  chainId: chainId,
700
525
  }),
701
526
  ),
702
- ).toBe(initialMintsBalance - quantityToMintOn1155 * 2n);
703
-
704
- expect(
705
- await publicClient.readContract(
706
- mintsBalanceOfAccountParams({
707
- account: mintsEthUnwrapperAndCallerConfig.address[chainId],
708
- chainId: chainId,
709
- }),
710
- ),
711
- ).toBe(0n);
712
-
713
- const tokenBalance = await publicClient.readContract({
714
- abi: zoraCreator1155ImplABI,
715
- address: legacy1155Address,
716
- functionName: "balanceOf",
717
- args: [collectorAccount!, tokenId],
718
- });
719
-
720
- expect(tokenBalance).toBe(quantityToMintOn1155 * 2n);
527
+ ).toBe(initialMintsBalance - premintQuantityToCollect);
721
528
  },
722
529
  20_000,
723
530
  );