@zoralabs/comments-contracts 0.0.1 → 0.0.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 (110) hide show
  1. package/.turbo/turbo-build.log +49 -31
  2. package/README.md +10 -39
  3. package/abis/AddDelegateCommenterRole.json +9 -0
  4. package/abis/CallerAndCommenter.json +62 -0
  5. package/abis/CallerAndCommenterImpl.json +1218 -0
  6. package/abis/CallerAndCommenterMintAndCommentTest.json +771 -0
  7. package/abis/CallerAndCommenterSwapAndCommentTest.json +844 -0
  8. package/abis/CallerAndCommenterTestBase.json +577 -0
  9. package/abis/CommentsImpl.json +189 -59
  10. package/abis/CommentsImplConstants.json +106 -0
  11. package/abis/CommentsPermitTest.json +26 -6
  12. package/abis/CommentsTest.json +58 -10
  13. package/abis/Comments_mintAndCommentTest.json +11 -4
  14. package/abis/Comments_smartWallet.json +711 -0
  15. package/abis/DeployCallerAndCommenterImpl.json +9 -0
  16. package/abis/DeployImpl.json +0 -13
  17. package/abis/DeployNonDeterministic.json +0 -13
  18. package/abis/DeployScript.json +0 -13
  19. package/abis/EIP712Upgradeable.json +74 -0
  20. package/abis/EIP712UpgradeableWithChainId.json +49 -0
  21. package/abis/ERC20.json +310 -0
  22. package/abis/GenerateDeterministicParams.json +0 -13
  23. package/abis/ICallerAndCommenter.json +797 -0
  24. package/abis/IComments.json +629 -9
  25. package/abis/IERC20.json +39 -42
  26. package/abis/IERC20Metadata.json +224 -0
  27. package/abis/{CommentsDeployerBase.json → IMultiOwnable.json} +8 -2
  28. package/abis/IProtocolRewards.json +19 -0
  29. package/abis/ISecondarySwap.json +45 -0
  30. package/abis/IZoraCreator1155.json +51 -0
  31. package/abis/IZoraTimedSaleStrategy.json +91 -0
  32. package/abis/Mock1155.json +75 -1
  33. package/abis/Mock1155NoCreatorRewardRecipient.json +605 -0
  34. package/abis/Mock1155NoOwner.json +566 -0
  35. package/abis/{MockMinter.json → MockDelegateCommenter.json} +12 -2
  36. package/abis/MockERC20z.json +315 -0
  37. package/abis/MockMultiOwnable.json +212 -0
  38. package/abis/MockSecondarySwap.json +95 -0
  39. package/abis/MockZoraTimedSale.json +139 -0
  40. package/abis/Ownable2StepUpgradeable.json +138 -0
  41. package/abis/UnorderedNoncesUpgradeable.json +4 -4
  42. package/addresses/1.json +9 -0
  43. package/addresses/10.json +9 -0
  44. package/addresses/11155111.json +9 -0
  45. package/addresses/11155420.json +9 -0
  46. package/addresses/42161.json +9 -0
  47. package/addresses/7777777.json +9 -0
  48. package/addresses/81457.json +9 -0
  49. package/addresses/8453.json +9 -0
  50. package/addresses/84532.json +9 -0
  51. package/addresses/999999999.json +7 -2
  52. package/deterministicConfig/callerAndCommenter.json +8 -0
  53. package/deterministicConfig/comments.json +2 -2
  54. package/dist/index.cjs +724 -35
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.js +723 -35
  57. package/dist/index.js.map +1 -1
  58. package/dist/types.d.ts +1 -1
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/wagmiGenerated.d.ts +1102 -57
  61. package/dist/wagmiGenerated.d.ts.map +1 -1
  62. package/package/types.ts +4 -1
  63. package/package/wagmiGenerated.ts +728 -32
  64. package/package.json +12 -11
  65. package/script/AddDelegateCommenterRole.s.sol +24 -0
  66. package/script/CommentsDeployerBase.sol +102 -19
  67. package/script/Deploy.s.sol +2 -44
  68. package/script/DeployCallerAndCommenterImpl.s.sol +29 -0
  69. package/script/DeployImpl.s.sol +1 -0
  70. package/script/DeployNonDeterministic.s.sol +22 -13
  71. package/script/GenerateDeterministicParams.s.sol +32 -4
  72. package/scripts/generateCommentsTestData.ts +170 -79
  73. package/src/CommentsImpl.sol +267 -134
  74. package/src/CommentsImplConstants.sol +44 -0
  75. package/src/interfaces/ICallerAndCommenter.sol +215 -0
  76. package/src/interfaces/IComments.sol +189 -42
  77. package/src/interfaces/IMultiOwnable.sol +10 -0
  78. package/src/interfaces/ISecondarySwap.sol +40 -0
  79. package/src/interfaces/IZoraCreator1155.sol +6 -1
  80. package/src/interfaces/IZoraCreator1155TypesV1.sol +46 -0
  81. package/src/interfaces/IZoraTimedSaleStrategy.sol +25 -0
  82. package/src/proxy/CallerAndCommenter.sol +43 -0
  83. package/src/utils/CallerAndCommenterImpl.sol +376 -0
  84. package/src/utils/EIP712UpgradeableWithChainId.sol +12 -23
  85. package/src/version/ContractVersionBase.sol +1 -1
  86. package/test/CallerAndCommenterTestBase.sol +77 -0
  87. package/test/CallerAndCommenter_mintAndComment.t copy.sol +214 -0
  88. package/test/CallerAndCommenter_swapAndComment.t.sol +523 -0
  89. package/test/Comments.t.sol +166 -29
  90. package/test/CommentsTestBase.sol +12 -20
  91. package/test/Comments_delegateComment.t.sol +129 -0
  92. package/test/Comments_permit.t.sol +131 -44
  93. package/test/Comments_smartWallet.t.sol +152 -0
  94. package/test/mocks/Mock1155.sol +12 -1
  95. package/test/mocks/Mock1155NoCreatorRewardRecipient.sol +65 -0
  96. package/test/mocks/Mock1155NoOwner.sol +53 -0
  97. package/test/mocks/MockDelegateCommenter.sol +36 -0
  98. package/test/mocks/MockIZoraCreator1155.sol +16 -0
  99. package/test/mocks/MockSecondarySwap.sol +30 -0
  100. package/test/mocks/MockZoraTimedSale.sol +38 -0
  101. package/wagmi.config.ts +3 -1
  102. package/abis/ProxyDeployerScript.json +0 -15
  103. package/scripts/backfillComments.ts +0 -176
  104. package/scripts/queries.ts +0 -73
  105. package/scripts/queryAndSaveComments.ts +0 -48
  106. package/scripts/queryQuantityOfComments.ts +0 -53
  107. package/scripts/writeComments.ts +0 -198
  108. package/src/deployments/CommentsDeployment.sol +0 -14
  109. package/test/Comments_mintAndComment.t.sol +0 -101
  110. package/test/mocks/MockMinter.sol +0 -29
@@ -0,0 +1,214 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IComments} from "../src/interfaces/IComments.sol";
5
+ import {ICallerAndCommenter} from "../src/interfaces/ICallerAndCommenter.sol";
6
+ import {CallerAndCommenterTestBase} from "./CallerAndCommenterTestBase.sol";
7
+
8
+ contract CallerAndCommenterMintAndCommentTest is CallerAndCommenterTestBase {
9
+ function testCanTimedSaleMintAndComment() public {
10
+ uint256 quantityToMint = 1;
11
+ uint256 mintFee = 0.000111 ether;
12
+
13
+ address contractAddress = address(mock1155);
14
+ uint256 tokenId = tokenId1;
15
+
16
+ IComments.CommentIdentifier memory expectedCommentIdentifier = _expectedCommentIdentifier(commenter, contractAddress, tokenId);
17
+
18
+ bytes32 expectedCommentId = comments.hashCommentIdentifier(expectedCommentIdentifier);
19
+ bytes32 expectedReplyToId = bytes32(0);
20
+
21
+ uint64 sparksQuantity = 0;
22
+
23
+ address mintReferral = address(0);
24
+
25
+ vm.deal(commenter, mintFee * quantityToMint);
26
+ vm.expectEmit(true, true, true, true);
27
+ emit IComments.Commented(
28
+ expectedCommentId,
29
+ expectedCommentIdentifier,
30
+ expectedReplyToId,
31
+ emptyCommentIdentifier,
32
+ sparksQuantity,
33
+ "test",
34
+ block.timestamp,
35
+ address(0)
36
+ );
37
+ vm.expectEmit(true, true, true, true);
38
+ emit ICallerAndCommenter.MintedAndCommented(expectedCommentId, expectedCommentIdentifier, quantityToMint, "test");
39
+ vm.prank(commenter);
40
+ callerAndCommenter.timedSaleMintAndComment{value: mintFee * quantityToMint}(
41
+ commenter,
42
+ quantityToMint,
43
+ address(mock1155),
44
+ tokenId1,
45
+ mintReferral,
46
+ "test"
47
+ );
48
+
49
+ // validate that the comment was created
50
+ (, bool exists) = comments.hashAndCheckCommentExists(expectedCommentIdentifier);
51
+ assertEq(exists, true);
52
+ // make sure mock 1155 got the full mint fee
53
+ assertEq(address(mock1155).balance, mintFee * quantityToMint);
54
+ }
55
+
56
+ function testWhenNoCommentDoesNotComment() public {
57
+ uint256 quantityToMint = 1;
58
+ uint256 mintFee = 0.000111 ether;
59
+
60
+ vm.deal(commenter, mintFee * quantityToMint);
61
+ vm.prank(commenter);
62
+ IComments.CommentIdentifier memory result = callerAndCommenter.timedSaleMintAndComment{value: mintFee * quantityToMint}(
63
+ commenter,
64
+ quantityToMint,
65
+ address(mock1155),
66
+ tokenId1,
67
+ address(0),
68
+ ""
69
+ );
70
+
71
+ assertEq(result.commenter, address(0));
72
+ assertEq(result.contractAddress, address(0));
73
+ assertEq(result.tokenId, 0);
74
+ assertEq(result.nonce, bytes32(0));
75
+ }
76
+
77
+ function testPermitTimedSaleMintAndComment() public {
78
+ uint256 quantityToMint = 1;
79
+ uint256 mintFee = 0.000111 ether;
80
+
81
+ address contractAddress = address(mock1155);
82
+ uint256 tokenId = tokenId1;
83
+
84
+ string memory comment = "test comment";
85
+
86
+ ICallerAndCommenter.PermitTimedSaleMintAndComment memory permit = _createPermit(
87
+ commenter,
88
+ quantityToMint,
89
+ contractAddress,
90
+ tokenId,
91
+ address(0),
92
+ comment,
93
+ block.timestamp + 1 hours
94
+ );
95
+
96
+ bytes memory signature = _signPermit(permit, commenterPrivateKey);
97
+
98
+ IComments.CommentIdentifier memory expectedCommentIdentifier = _expectedCommentIdentifier(commenter, contractAddress, tokenId);
99
+
100
+ bytes32 expectedCommentId = comments.hashCommentIdentifier(expectedCommentIdentifier);
101
+
102
+ vm.deal(commenter, mintFee * quantityToMint);
103
+ vm.expectEmit(true, true, true, true);
104
+ emit IComments.Commented(expectedCommentId, expectedCommentIdentifier, bytes32(0), emptyCommentIdentifier, 0, comment, block.timestamp, address(0));
105
+ vm.expectEmit(true, true, true, true);
106
+ emit ICallerAndCommenter.MintedAndCommented(expectedCommentId, expectedCommentIdentifier, quantityToMint, comment);
107
+ IComments.CommentIdentifier memory result = callerAndCommenter.permitTimedSaleMintAndComment{value: mintFee * quantityToMint}(permit, signature);
108
+
109
+ assertEq(result.commenter, commenter);
110
+ assertEq(result.contractAddress, contractAddress);
111
+ assertEq(result.tokenId, tokenId);
112
+ assertEq(result.nonce, bytes32(0));
113
+
114
+ // validate that the comment was created
115
+ (, bool exists) = comments.hashAndCheckCommentExists(expectedCommentIdentifier);
116
+ assertEq(exists, true);
117
+ // make sure mock 1155 got the full mint fee
118
+ assertEq(address(mock1155).balance, mintFee * quantityToMint);
119
+ }
120
+
121
+ function testPermitTimedSaleMintAndComment_ExpiredDeadline() public {
122
+ uint256 quantityToMint = 1;
123
+ uint256 mintFee = 0.000111 ether;
124
+
125
+ ICallerAndCommenter.PermitTimedSaleMintAndComment memory permit = _createPermit(
126
+ commenter,
127
+ quantityToMint,
128
+ address(mock1155),
129
+ tokenId1,
130
+ address(0),
131
+ "test comment",
132
+ block.timestamp - 1 // Expired deadline
133
+ );
134
+
135
+ bytes memory signature = _signPermit(permit, commenterPrivateKey);
136
+
137
+ vm.deal(commenter, mintFee * quantityToMint);
138
+ vm.expectRevert(abi.encodeWithSelector(IComments.ERC2612ExpiredSignature.selector, permit.deadline));
139
+ callerAndCommenter.permitTimedSaleMintAndComment{value: mintFee * quantityToMint}(permit, signature);
140
+ }
141
+
142
+ function testPermitTimedSaleMintAndComment_InvalidSignature() public {
143
+ uint256 quantityToMint = 1;
144
+ uint256 mintFee = 0.000111 ether;
145
+
146
+ ICallerAndCommenter.PermitTimedSaleMintAndComment memory permit = _createPermit(
147
+ commenter,
148
+ quantityToMint,
149
+ address(mock1155),
150
+ tokenId1,
151
+ address(0),
152
+ "test comment",
153
+ block.timestamp + 1 hours
154
+ );
155
+
156
+ bytes memory signature = _signPermit(permit, 5); // Wrong signer
157
+
158
+ vm.deal(commenter, mintFee * quantityToMint);
159
+ vm.expectRevert(IComments.InvalidSignature.selector);
160
+ callerAndCommenter.permitTimedSaleMintAndComment{value: mintFee * quantityToMint}(permit, signature);
161
+ }
162
+
163
+ function testPermitTimedSaleMintAndComment_IncorrectDestinationChain() public {
164
+ uint256 quantityToMint = 1;
165
+ uint256 mintFee = 0.000111 ether;
166
+
167
+ ICallerAndCommenter.PermitTimedSaleMintAndComment memory permit = _createPermit(
168
+ commenter,
169
+ quantityToMint,
170
+ address(mock1155),
171
+ tokenId1,
172
+ address(0),
173
+ "test comment",
174
+ block.timestamp + 1 hours
175
+ );
176
+ permit.destinationChainId = uint32(block.chainid) + 1; // Incorrect destination chain
177
+
178
+ bytes memory signature = _signPermit(permit, commenterPrivateKey);
179
+
180
+ vm.deal(commenter, mintFee * quantityToMint);
181
+ vm.expectRevert(abi.encodeWithSelector(ICallerAndCommenter.IncorrectDestinationChain.selector, permit.destinationChainId));
182
+ callerAndCommenter.permitTimedSaleMintAndComment{value: mintFee * quantityToMint}(permit, signature);
183
+ }
184
+
185
+ function _createPermit(
186
+ address _commenter,
187
+ uint256 _quantity,
188
+ address _collection,
189
+ uint256 _tokenId,
190
+ address _mintReferral,
191
+ string memory _comment,
192
+ uint256 _deadline
193
+ ) internal view returns (ICallerAndCommenter.PermitTimedSaleMintAndComment memory) {
194
+ return
195
+ ICallerAndCommenter.PermitTimedSaleMintAndComment({
196
+ commenter: _commenter,
197
+ quantity: _quantity,
198
+ collection: _collection,
199
+ tokenId: _tokenId,
200
+ mintReferral: _mintReferral,
201
+ comment: _comment,
202
+ deadline: _deadline,
203
+ nonce: bytes32(0),
204
+ sourceChainId: uint32(block.chainid),
205
+ destinationChainId: uint32(block.chainid)
206
+ });
207
+ }
208
+
209
+ function _signPermit(ICallerAndCommenter.PermitTimedSaleMintAndComment memory _permit, uint256 _privateKey) internal view returns (bytes memory) {
210
+ bytes32 digest = callerAndCommenter.hashPermitTimedSaleMintAndComment(_permit);
211
+ (uint8 v, bytes32 r, bytes32 s) = vm.sign(_privateKey, digest);
212
+ return abi.encodePacked(r, s, v);
213
+ }
214
+ }