@zoralabs/protocol-sdk 0.5.8-DEV.1 → 0.5.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.
@@ -0,0 +1,239 @@
1
+ import { foundry } from "viem/chains";
2
+ import { describe, expect, vi } from "vitest";
3
+
4
+ import { createPremintClient } from "./premint-client";
5
+ import { anvilTest } from "src/anvil";
6
+ import { PremintConfigVersion } from "./contract-types";
7
+ import { getDefaultFixedPriceMinterAddress } from "./preminter";
8
+
9
+ describe("ZoraCreator1155Premint - v1 signatures", () => {
10
+ anvilTest(
11
+ "can sign by default v1 on the forked premint contract",
12
+ async ({ viemClients: { walletClient, publicClient, chain } }) => {
13
+ const [deployerAccount] = await walletClient.getAddresses();
14
+ const premintClient = createPremintClient({
15
+ chain,
16
+ publicClient,
17
+ });
18
+
19
+ premintClient.apiClient.getNextUID = vi
20
+ .fn<any, ReturnType<typeof premintClient.apiClient.getNextUID>>()
21
+ .mockResolvedValue(3);
22
+ premintClient.apiClient.postSignature = vi
23
+ .fn<Parameters<typeof premintClient.apiClient.postSignature>>()
24
+ .mockResolvedValue({ ok: true });
25
+
26
+ await premintClient.createPremint({
27
+ walletClient,
28
+ creatorAccount: deployerAccount!,
29
+ checkSignature: true,
30
+ collection: {
31
+ contractAdmin: deployerAccount!,
32
+ contractName: "Testing Contract",
33
+ contractURI:
34
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
35
+ },
36
+ tokenCreationConfig: {
37
+ tokenURI:
38
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
39
+ },
40
+ });
41
+
42
+ const expectedPostSignatureArgs: Parameters<
43
+ typeof premintClient.apiClient.postSignature
44
+ >[0] = {
45
+ collection: {
46
+ contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
47
+ contractName: "Testing Contract",
48
+ contractURI:
49
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
50
+ },
51
+ premintConfig: {
52
+ deleted: false,
53
+ tokenConfig: {
54
+ fixedPriceMinter: getDefaultFixedPriceMinterAddress(chain.id),
55
+ maxSupply: 18446744073709551615n,
56
+ maxTokensPerAddress: 0n,
57
+ mintDuration: 604800n,
58
+ mintStart: 0n,
59
+ pricePerToken: 0n,
60
+ royaltyBPS: 1000,
61
+ royaltyMintSchedule: 0,
62
+ royaltyRecipient: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
63
+ tokenURI:
64
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
65
+ },
66
+ uid: 3,
67
+ version: 0,
68
+ },
69
+ premintConfigVersion: PremintConfigVersion.V1,
70
+ signature:
71
+ "0x70fc1d6e862c42f2b0e4a062f4eb973cc8692df58a24b71b4fe91ae7baa5a26d2c99b1b8ab61f64ff431bf30b0897877b11b7405542c90b89b041808f1561a6c1c",
72
+ };
73
+
74
+ expect(premintClient.apiClient.postSignature).toHaveBeenCalledWith(
75
+ expectedPostSignatureArgs,
76
+ );
77
+ },
78
+ 20 * 1000,
79
+ );
80
+
81
+ anvilTest(
82
+ "can execute premint on network",
83
+ async ({ viemClients: { walletClient, publicClient, chain } }) => {
84
+ const [deployerAccount] = await walletClient.getAddresses();
85
+ const premintClient = createPremintClient({
86
+ chain: foundry,
87
+ publicClient,
88
+ });
89
+
90
+ premintClient.apiClient.getSignature = vi
91
+ .fn<any, ReturnType<typeof premintClient.apiClient.getSignature>>()
92
+ .mockResolvedValue({
93
+ collection: {
94
+ contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
95
+ contractName: "Testing Contract",
96
+ contractURI:
97
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
98
+ },
99
+ premintConfig: {
100
+ deleted: false,
101
+ tokenConfig: {
102
+ fixedPriceMinter: getDefaultFixedPriceMinterAddress(chain.id),
103
+ maxSupply: 18446744073709551615n,
104
+ maxTokensPerAddress: 0n,
105
+ mintDuration: 604800n,
106
+ mintStart: 0n,
107
+ pricePerToken: 0n,
108
+ royaltyBPS: 1000,
109
+ royaltyMintSchedule: 0,
110
+ royaltyRecipient: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
111
+ tokenURI:
112
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
113
+ },
114
+ uid: 3,
115
+ version: 0,
116
+ },
117
+ premintConfigVersion: PremintConfigVersion.V1,
118
+ signature:
119
+ "0x70fc1d6e862c42f2b0e4a062f4eb973cc8692df58a24b71b4fe91ae7baa5a26d2c99b1b8ab61f64ff431bf30b0897877b11b7405542c90b89b041808f1561a6c1c",
120
+ });
121
+
122
+ premintClient.apiClient.postSignature = vi.fn();
123
+
124
+ const simulateContractParameters = await premintClient.makeMintParameters(
125
+ {
126
+ minterAccount: deployerAccount!,
127
+ tokenContract: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
128
+ uid: 3,
129
+ mintArguments: {
130
+ quantityToMint: 1,
131
+ mintComment: "",
132
+ },
133
+ },
134
+ );
135
+ const { request: simulateRequest } = await publicClient.simulateContract(
136
+ simulateContractParameters,
137
+ );
138
+ const hash = await walletClient.writeContract(simulateRequest);
139
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
140
+ const { premintedLog, urls } =
141
+ premintClient.getDataFromPremintReceipt(receipt);
142
+
143
+ expect(urls).toEqual({
144
+ explorer:
145
+ "https://undefined/token/0xf8dA7f53c283d898818af7FB9d98103F559bDac2/instance/1",
146
+ zoraCollect:
147
+ "https://testnet.zora.co/collect/zgor:0xf8dA7f53c283d898818af7FB9d98103F559bDac2/1",
148
+ zoraManage:
149
+ "https://testnet.zora.co/collect/zgor:0xf8dA7f53c283d898818af7FB9d98103F559bDac2/1",
150
+ });
151
+
152
+ expect(premintedLog).toEqual({
153
+ contractAddress: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
154
+ createdNewContract: expect.any(Boolean),
155
+ minter: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
156
+ quantityMinted: 1n,
157
+ tokenId: 1n,
158
+ uid: 3,
159
+ });
160
+ },
161
+ 20 * 1000,
162
+ );
163
+ });
164
+
165
+ describe("ZoraCreator1155Premint - v2 signatures", () => {
166
+ anvilTest(
167
+ "can sign on the forked premint contract",
168
+ async ({ viemClients: { walletClient, publicClient, chain } }) => {
169
+ const [creatorAccount, createReferralAccount] =
170
+ await walletClient.getAddresses();
171
+ const premintClient = createPremintClient({
172
+ chain,
173
+ publicClient,
174
+ });
175
+
176
+ premintClient.apiClient.getNextUID = vi
177
+ .fn<any, ReturnType<typeof premintClient.apiClient.getNextUID>>()
178
+ .mockResolvedValue(3);
179
+ premintClient.apiClient.postSignature = vi
180
+ .fn<Parameters<typeof premintClient.apiClient.postSignature>>()
181
+ .mockResolvedValue({ ok: true });
182
+
183
+ await premintClient.createPremint({
184
+ walletClient,
185
+ creatorAccount: creatorAccount!,
186
+ checkSignature: true,
187
+ collection: {
188
+ contractAdmin: creatorAccount!,
189
+ contractName: "Testing Contract Premint V2",
190
+ contractURI:
191
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
192
+ },
193
+ premintConfigVersion: PremintConfigVersion.V2,
194
+ tokenCreationConfig: {
195
+ tokenURI:
196
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
197
+ createReferral: createReferralAccount,
198
+ },
199
+ });
200
+
201
+ const expectedPostSignatureArgs: Parameters<
202
+ typeof premintClient.apiClient.postSignature
203
+ >[0] = {
204
+ collection: {
205
+ contractAdmin: creatorAccount!,
206
+ contractName: "Testing Contract Premint V2",
207
+ contractURI:
208
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
209
+ },
210
+ premintConfig: {
211
+ deleted: false,
212
+ tokenConfig: {
213
+ fixedPriceMinter: "0x04E2516A2c207E84a1839755675dfd8eF6302F0a",
214
+ maxSupply: 18446744073709551615n,
215
+ maxTokensPerAddress: 0n,
216
+ mintDuration: 604800n,
217
+ mintStart: 0n,
218
+ pricePerToken: 0n,
219
+ royaltyBPS: 1000,
220
+ payoutRecipient: creatorAccount!,
221
+ createReferral: createReferralAccount!,
222
+ tokenURI:
223
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
224
+ },
225
+ uid: 3,
226
+ version: 0,
227
+ },
228
+ premintConfigVersion: PremintConfigVersion.V2,
229
+ signature:
230
+ "0x8be7932b0b31bdb7fc9269b756e0d0c9514519f083d86576e23b73c033d8ed8440ea363bc8bba0ec5c30eb6bbdf796163a324201bc7520965037102518fb5e991c",
231
+ };
232
+
233
+ expect(premintClient.apiClient.postSignature).toHaveBeenCalledWith(
234
+ expectedPostSignatureArgs,
235
+ );
236
+ },
237
+ 20 * 1000,
238
+ );
239
+ });