@zoralabs/protocol-sdk 0.3.4 → 0.4.0
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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +34 -0
- package/README.md +30 -58
- package/dist/anvil.d.ts +4 -2
- package/dist/anvil.d.ts.map +1 -1
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +819 -518
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +788 -493
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +16 -216
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +7 -227
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/contract-types.d.ts +125 -0
- package/dist/premint/contract-types.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +14 -7
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +45 -115
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +102 -21
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/anvil.ts +7 -4
- package/src/constants.ts +7 -0
- package/src/index.ts +2 -0
- package/src/mint/mint-api-client.ts +72 -68
- package/src/mint/mint-client.test.ts +9 -11
- package/src/mint/mint-client.ts +51 -221
- package/src/premint/contract-types.ts +109 -0
- package/src/premint/premint-api-client.ts +162 -22
- package/src/premint/premint-client.test.ts +186 -84
- package/src/premint/premint-client.ts +357 -289
- package/src/premint/preminter.test.ts +209 -130
- package/src/premint/preminter.ts +377 -54
- package/src/types.ts +1 -0
- package/dist/apis/generated/discover-api-types.d.ts +0 -2131
- package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
- package/src/apis/generated/discover-api-types.ts +0 -2180
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
keccak256,
|
|
3
|
-
Hex,
|
|
4
|
-
concat,
|
|
5
|
-
recoverAddress,
|
|
6
|
-
hashDomain,
|
|
7
|
-
Address,
|
|
8
|
-
} from "viem";
|
|
1
|
+
import { Address, zeroAddress } from "viem";
|
|
9
2
|
import { foundry } from "viem/chains";
|
|
10
3
|
import { describe, expect } from "vitest";
|
|
11
4
|
import { parseEther } from "viem";
|
|
12
5
|
import {
|
|
13
6
|
zoraCreator1155PremintExecutorImplABI as preminterAbi,
|
|
14
|
-
zoraCreator1155PremintExecutorImplAddress as zoraCreator1155PremintExecutorAddress,
|
|
15
7
|
zoraCreator1155ImplABI,
|
|
16
8
|
zoraCreator1155FactoryImplAddress,
|
|
17
9
|
zoraCreator1155FactoryImplConfig,
|
|
18
10
|
} from "@zoralabs/protocol-deployments";
|
|
19
11
|
|
|
20
12
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
premintTypedDataDefinition,
|
|
14
|
+
isValidSignature,
|
|
15
|
+
recoverCreatorFromCreatorAttribution,
|
|
16
|
+
getPremintExecutorAddress,
|
|
25
17
|
} from "./preminter";
|
|
26
18
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
ContractCreationConfig,
|
|
20
|
+
PremintConfigV1,
|
|
21
|
+
TokenCreationConfigV1,
|
|
22
|
+
PremintConfigVersion,
|
|
23
|
+
TokenCreationConfigV2,
|
|
24
|
+
PremintConfigV2,
|
|
25
|
+
MintArguments,
|
|
26
|
+
} from "./contract-types";
|
|
27
|
+
import { AnvilViemClientsTest, forkUrls, makeAnvilTest } from "src/anvil";
|
|
32
28
|
|
|
33
29
|
// create token and contract creation config:
|
|
34
30
|
const defaultContractConfig = ({
|
|
@@ -41,10 +37,10 @@ const defaultContractConfig = ({
|
|
|
41
37
|
contractName: "My fun NFT",
|
|
42
38
|
});
|
|
43
39
|
|
|
44
|
-
const
|
|
40
|
+
const defaultTokenConfigV1 = (
|
|
45
41
|
fixedPriceMinterAddress: Address,
|
|
46
42
|
creatorAccount: Address,
|
|
47
|
-
):
|
|
43
|
+
): TokenCreationConfigV1 => ({
|
|
48
44
|
tokenURI: "ipfs://tokenIpfsId0",
|
|
49
45
|
maxSupply: 100n,
|
|
50
46
|
maxTokensPerAddress: 10n,
|
|
@@ -57,19 +53,63 @@ const defaultTokenConfig = (
|
|
|
57
53
|
fixedPriceMinter: fixedPriceMinterAddress,
|
|
58
54
|
});
|
|
59
55
|
|
|
60
|
-
const
|
|
61
|
-
|
|
56
|
+
const defaultTokenConfigV2 = (
|
|
57
|
+
fixedPriceMinterAddress: Address,
|
|
62
58
|
creatorAccount: Address,
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
createReferral: Address,
|
|
60
|
+
): TokenCreationConfigV2 => ({
|
|
61
|
+
tokenURI: "ipfs://tokenIpfsId0",
|
|
62
|
+
maxSupply: 100n,
|
|
63
|
+
maxTokensPerAddress: 10n,
|
|
64
|
+
pricePerToken: 0n,
|
|
65
|
+
mintStart: 0n,
|
|
66
|
+
mintDuration: 100n,
|
|
67
|
+
royaltyBPS: 200,
|
|
68
|
+
payoutRecipient: creatorAccount,
|
|
69
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
70
|
+
createReferral,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const defaultPremintConfigV1 = ({
|
|
74
|
+
fixedPriceMinter,
|
|
75
|
+
creatorAccount,
|
|
76
|
+
}: {
|
|
77
|
+
fixedPriceMinter: Address;
|
|
78
|
+
creatorAccount: Address;
|
|
79
|
+
}): PremintConfigV1 => ({
|
|
80
|
+
tokenConfig: defaultTokenConfigV1(fixedPriceMinter, creatorAccount),
|
|
65
81
|
deleted: false,
|
|
66
82
|
uid: 105,
|
|
67
83
|
version: 0,
|
|
68
84
|
});
|
|
69
85
|
|
|
86
|
+
const defaultPremintConfigV2 = ({
|
|
87
|
+
fixedPriceMinter,
|
|
88
|
+
creatorAccount,
|
|
89
|
+
createReferral = zeroAddress,
|
|
90
|
+
}: {
|
|
91
|
+
fixedPriceMinter: Address;
|
|
92
|
+
creatorAccount: Address;
|
|
93
|
+
createReferral?: Address;
|
|
94
|
+
}): PremintConfigV2 => ({
|
|
95
|
+
tokenConfig: defaultTokenConfigV2(
|
|
96
|
+
fixedPriceMinter,
|
|
97
|
+
creatorAccount,
|
|
98
|
+
createReferral,
|
|
99
|
+
),
|
|
100
|
+
deleted: false,
|
|
101
|
+
uid: 106,
|
|
102
|
+
version: 0,
|
|
103
|
+
});
|
|
104
|
+
|
|
70
105
|
const ZORA_MINT_FEE = parseEther("0.000777");
|
|
71
106
|
|
|
72
|
-
const PREMINTER_ADDRESS =
|
|
107
|
+
const PREMINTER_ADDRESS = getPremintExecutorAddress();
|
|
108
|
+
|
|
109
|
+
const anvilTest = makeAnvilTest({
|
|
110
|
+
forkUrl: forkUrls.zoraSepolia,
|
|
111
|
+
forkBlockNumber: 1265490,
|
|
112
|
+
});
|
|
73
113
|
|
|
74
114
|
async function setupContracts({
|
|
75
115
|
viemClients: { walletClient, testClient, publicClient },
|
|
@@ -109,15 +149,15 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
109
149
|
fixedPriceMinterAddress,
|
|
110
150
|
accounts: { creatorAccount },
|
|
111
151
|
} = await setupContracts({ viemClients });
|
|
112
|
-
const premintConfig =
|
|
113
|
-
fixedPriceMinterAddress,
|
|
152
|
+
const premintConfig = defaultPremintConfigV1({
|
|
153
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
114
154
|
creatorAccount,
|
|
115
|
-
);
|
|
155
|
+
});
|
|
116
156
|
const contractConfig = defaultContractConfig({
|
|
117
157
|
contractAdmin: creatorAccount,
|
|
118
158
|
});
|
|
119
159
|
|
|
120
|
-
const preminterAddress =
|
|
160
|
+
const preminterAddress = getPremintExecutorAddress();
|
|
121
161
|
|
|
122
162
|
const contractAddress = await viemClients.publicClient.readContract({
|
|
123
163
|
abi: preminterAbi,
|
|
@@ -127,10 +167,11 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
127
167
|
});
|
|
128
168
|
|
|
129
169
|
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
130
|
-
...
|
|
170
|
+
...premintTypedDataDefinition({
|
|
131
171
|
verifyingContract: contractAddress,
|
|
132
172
|
chainId: 999,
|
|
133
173
|
premintConfig,
|
|
174
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
134
175
|
}),
|
|
135
176
|
account: creatorAccount,
|
|
136
177
|
});
|
|
@@ -145,26 +186,80 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
145
186
|
},
|
|
146
187
|
20 * 1000,
|
|
147
188
|
);
|
|
189
|
+
anvilTest(
|
|
190
|
+
"can sign and recover a v1 premint config signature",
|
|
191
|
+
async ({ viemClients }) => {
|
|
192
|
+
const {
|
|
193
|
+
fixedPriceMinterAddress,
|
|
194
|
+
accounts: { creatorAccount },
|
|
195
|
+
} = await setupContracts({ viemClients });
|
|
196
|
+
|
|
197
|
+
const premintConfig = defaultPremintConfigV1({
|
|
198
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
199
|
+
creatorAccount,
|
|
200
|
+
});
|
|
201
|
+
const contractConfig = defaultContractConfig({
|
|
202
|
+
contractAdmin: creatorAccount,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const tokenContract = await viemClients.publicClient.readContract({
|
|
206
|
+
abi: preminterAbi,
|
|
207
|
+
address: PREMINTER_ADDRESS,
|
|
208
|
+
functionName: "getContractAddress",
|
|
209
|
+
args: [contractConfig],
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// sign message containing contract and token creation config and uid
|
|
213
|
+
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
214
|
+
...premintTypedDataDefinition({
|
|
215
|
+
verifyingContract: tokenContract,
|
|
216
|
+
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
217
|
+
chainId: foundry.id,
|
|
218
|
+
premintConfig,
|
|
219
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
220
|
+
}),
|
|
221
|
+
account: creatorAccount,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// recover and verify address is correct
|
|
225
|
+
const { recoveredAddress, isAuthorized } = await isValidSignature({
|
|
226
|
+
collection: contractConfig,
|
|
227
|
+
chainId: viemClients.publicClient.chain!.id,
|
|
228
|
+
premintConfig,
|
|
229
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
230
|
+
publicClient: viemClients.publicClient,
|
|
231
|
+
signature: signedMessage,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
expect(recoveredAddress).to.equal(creatorAccount);
|
|
235
|
+
expect(isAuthorized).toBe(true);
|
|
236
|
+
|
|
237
|
+
expect(recoveredAddress).to.equal(creatorAccount);
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
20 * 1000,
|
|
241
|
+
);
|
|
148
242
|
makeAnvilTest({
|
|
149
|
-
forkUrl: forkUrls.
|
|
150
|
-
forkBlockNumber:
|
|
243
|
+
forkUrl: forkUrls.zoraSepolia,
|
|
244
|
+
forkBlockNumber: 1262991,
|
|
151
245
|
})(
|
|
152
|
-
"can sign and recover a signature",
|
|
246
|
+
"can sign and recover a v2 premint config signature",
|
|
153
247
|
async ({ viemClients }) => {
|
|
154
248
|
const {
|
|
155
249
|
fixedPriceMinterAddress,
|
|
156
250
|
accounts: { creatorAccount },
|
|
157
251
|
} = await setupContracts({ viemClients });
|
|
158
252
|
|
|
159
|
-
const premintConfig =
|
|
160
|
-
fixedPriceMinterAddress,
|
|
253
|
+
const premintConfig = defaultPremintConfigV2({
|
|
161
254
|
creatorAccount,
|
|
162
|
-
|
|
255
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
256
|
+
createReferral: creatorAccount,
|
|
257
|
+
});
|
|
163
258
|
const contractConfig = defaultContractConfig({
|
|
164
259
|
contractAdmin: creatorAccount,
|
|
165
260
|
});
|
|
166
261
|
|
|
167
|
-
const
|
|
262
|
+
const tokenContract = await viemClients.publicClient.readContract({
|
|
168
263
|
abi: preminterAbi,
|
|
169
264
|
address: PREMINTER_ADDRESS,
|
|
170
265
|
functionName: "getContractAddress",
|
|
@@ -173,24 +268,28 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
173
268
|
|
|
174
269
|
// sign message containing contract and token creation config and uid
|
|
175
270
|
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
176
|
-
...
|
|
177
|
-
verifyingContract:
|
|
271
|
+
...premintTypedDataDefinition({
|
|
272
|
+
verifyingContract: tokenContract,
|
|
178
273
|
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
179
274
|
chainId: foundry.id,
|
|
180
275
|
premintConfig,
|
|
276
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
181
277
|
}),
|
|
182
278
|
account: creatorAccount,
|
|
183
279
|
});
|
|
184
280
|
|
|
185
|
-
const preminterAddress = zoraCreator1155PremintExecutorAddress[999];
|
|
186
281
|
// recover and verify address is correct
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
282
|
+
const { recoveredAddress, isAuthorized } = await isValidSignature({
|
|
283
|
+
collection: contractConfig,
|
|
284
|
+
chainId: viemClients.publicClient.chain!.id,
|
|
285
|
+
premintConfig,
|
|
286
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
287
|
+
publicClient: viemClients.publicClient,
|
|
288
|
+
signature: signedMessage,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
expect(recoveredAddress).to.equal(creatorAccount);
|
|
292
|
+
expect(isAuthorized).toBe(true);
|
|
194
293
|
|
|
195
294
|
expect(recoveredAddress).to.equal(creatorAccount);
|
|
196
295
|
},
|
|
@@ -205,16 +304,16 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
205
304
|
accounts: { creatorAccount, collectorAccount },
|
|
206
305
|
} = await setupContracts({ viemClients });
|
|
207
306
|
// setup contract and token creation parameters
|
|
208
|
-
const
|
|
209
|
-
fixedPriceMinterAddress,
|
|
307
|
+
const premintConfig1 = defaultPremintConfigV1({
|
|
308
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
210
309
|
creatorAccount,
|
|
211
|
-
);
|
|
310
|
+
});
|
|
212
311
|
const contractConfig = defaultContractConfig({
|
|
213
312
|
contractAdmin: creatorAccount,
|
|
214
313
|
});
|
|
215
314
|
|
|
216
315
|
// lets make it a random number to not break the existing tests that expect fresh data
|
|
217
|
-
|
|
316
|
+
premintConfig1.uid = Math.round(Math.random() * 1000000);
|
|
218
317
|
|
|
219
318
|
let contractAddress = await viemClients.publicClient.readContract({
|
|
220
319
|
abi: preminterAbi,
|
|
@@ -226,11 +325,12 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
226
325
|
// have creator sign the message to create the contract
|
|
227
326
|
// and the token
|
|
228
327
|
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
229
|
-
...
|
|
328
|
+
...premintTypedDataDefinition({
|
|
230
329
|
verifyingContract: contractAddress,
|
|
231
330
|
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
232
331
|
chainId: foundry.id,
|
|
233
|
-
premintConfig,
|
|
332
|
+
premintConfig: premintConfig1,
|
|
333
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
234
334
|
}),
|
|
235
335
|
account: creatorAccount,
|
|
236
336
|
});
|
|
@@ -238,11 +338,9 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
238
338
|
const quantityToMint = 2n;
|
|
239
339
|
|
|
240
340
|
const valueToSend =
|
|
241
|
-
(ZORA_MINT_FEE +
|
|
341
|
+
(ZORA_MINT_FEE + premintConfig1.tokenConfig.pricePerToken) *
|
|
242
342
|
quantityToMint;
|
|
243
343
|
|
|
244
|
-
const comment = "I love this!";
|
|
245
|
-
|
|
246
344
|
await viemClients.testClient.setBalance({
|
|
247
345
|
address: collectorAccount,
|
|
248
346
|
value: parseEther("10"),
|
|
@@ -254,12 +352,18 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
254
352
|
abi: preminterAbi,
|
|
255
353
|
address: PREMINTER_ADDRESS,
|
|
256
354
|
functionName: "premintStatus",
|
|
257
|
-
args: [contractAddress,
|
|
355
|
+
args: [contractAddress, premintConfig1.uid],
|
|
258
356
|
});
|
|
259
357
|
|
|
260
358
|
expect(contractCreated).toBe(false);
|
|
261
359
|
expect(tokenId).toBe(0n);
|
|
262
360
|
|
|
361
|
+
const mintArguments: MintArguments = {
|
|
362
|
+
mintComment: "",
|
|
363
|
+
mintRecipient: collectorAccount,
|
|
364
|
+
mintReferral: collectorAccount,
|
|
365
|
+
};
|
|
366
|
+
|
|
263
367
|
// now have the collector execute the first signed message;
|
|
264
368
|
// it should create the contract, the token,
|
|
265
369
|
// and min the quantity to mint tokens to the collector
|
|
@@ -267,16 +371,16 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
267
371
|
// parameters are required to call this function
|
|
268
372
|
const mintHash = await viemClients.walletClient.writeContract({
|
|
269
373
|
abi: preminterAbi,
|
|
270
|
-
functionName: "
|
|
374
|
+
functionName: "premintV1",
|
|
271
375
|
account: collectorAccount,
|
|
272
376
|
chain: foundry,
|
|
273
377
|
address: PREMINTER_ADDRESS,
|
|
274
378
|
args: [
|
|
275
379
|
contractConfig,
|
|
276
|
-
|
|
380
|
+
premintConfig1,
|
|
277
381
|
signedMessage,
|
|
278
382
|
quantityToMint,
|
|
279
|
-
|
|
383
|
+
mintArguments,
|
|
280
384
|
],
|
|
281
385
|
value: valueToSend,
|
|
282
386
|
});
|
|
@@ -293,7 +397,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
293
397
|
abi: preminterAbi,
|
|
294
398
|
address: PREMINTER_ADDRESS,
|
|
295
399
|
functionName: "premintStatus",
|
|
296
|
-
args: [contractAddress,
|
|
400
|
+
args: [contractAddress, premintConfig1.uid],
|
|
297
401
|
});
|
|
298
402
|
|
|
299
403
|
expect(contractCreated).toBe(true);
|
|
@@ -310,22 +414,19 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
310
414
|
// get token balance - should be amount that was created
|
|
311
415
|
expect(tokenBalance).toBe(quantityToMint);
|
|
312
416
|
|
|
313
|
-
const premintConfig2 = {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
tokenURI: "ipfs://tokenIpfsId2",
|
|
319
|
-
pricePerToken: parseEther("0.05"),
|
|
320
|
-
},
|
|
321
|
-
};
|
|
417
|
+
const premintConfig2 = defaultPremintConfigV2({
|
|
418
|
+
creatorAccount,
|
|
419
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
420
|
+
createReferral: creatorAccount,
|
|
421
|
+
});
|
|
322
422
|
|
|
323
423
|
// sign the message to create the second token
|
|
324
424
|
const signedMessage2 = await viemClients.walletClient.signTypedData({
|
|
325
|
-
...
|
|
425
|
+
...premintTypedDataDefinition({
|
|
326
426
|
verifyingContract: contractAddress,
|
|
327
427
|
chainId: foundry.id,
|
|
328
428
|
premintConfig: premintConfig2,
|
|
429
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
329
430
|
}),
|
|
330
431
|
account: creatorAccount,
|
|
331
432
|
});
|
|
@@ -336,11 +437,9 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
336
437
|
(ZORA_MINT_FEE + premintConfig2.tokenConfig.pricePerToken) *
|
|
337
438
|
quantityToMint2;
|
|
338
439
|
|
|
339
|
-
|
|
340
|
-
// it should create a new token against the existing contract
|
|
341
|
-
const mintHash2 = await viemClients.walletClient.writeContract({
|
|
440
|
+
const simulationResult = await viemClients.publicClient.simulateContract({
|
|
342
441
|
abi: preminterAbi,
|
|
343
|
-
functionName: "
|
|
442
|
+
functionName: "premintV2",
|
|
344
443
|
account: collectorAccount,
|
|
345
444
|
chain: foundry,
|
|
346
445
|
address: PREMINTER_ADDRESS,
|
|
@@ -349,18 +448,23 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
349
448
|
premintConfig2,
|
|
350
449
|
signedMessage2,
|
|
351
450
|
quantityToMint2,
|
|
352
|
-
|
|
451
|
+
mintArguments,
|
|
353
452
|
],
|
|
354
453
|
value: valueToSend2,
|
|
355
454
|
});
|
|
356
455
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
456
|
+
// now have the collector execute the second signed message.
|
|
457
|
+
// it should create a new token against the existing contract
|
|
458
|
+
const mintHash2 = await viemClients.walletClient.writeContract(
|
|
459
|
+
simulationResult.request,
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
const premintV2Receipt =
|
|
463
|
+
await viemClients.publicClient.waitForTransactionReceipt({
|
|
464
|
+
hash: mintHash2,
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
expect(premintV2Receipt.status).toBe("success");
|
|
364
468
|
|
|
365
469
|
// now premint status for the second mint, it should be minted
|
|
366
470
|
[, tokenId] = await viemClients.publicClient.readContract({
|
|
@@ -393,10 +497,10 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
393
497
|
fixedPriceMinterAddress,
|
|
394
498
|
accounts: { creatorAccount, collectorAccount },
|
|
395
499
|
} = await setupContracts({ viemClients });
|
|
396
|
-
const premintConfig =
|
|
397
|
-
fixedPriceMinterAddress,
|
|
500
|
+
const premintConfig = defaultPremintConfigV2({
|
|
501
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
398
502
|
creatorAccount,
|
|
399
|
-
);
|
|
503
|
+
});
|
|
400
504
|
const contractConfig = defaultContractConfig({
|
|
401
505
|
contractAdmin: creatorAccount,
|
|
402
506
|
});
|
|
@@ -411,14 +515,17 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
411
515
|
args: [contractConfig],
|
|
412
516
|
});
|
|
413
517
|
|
|
518
|
+
const signingChainId = foundry.id;
|
|
519
|
+
|
|
414
520
|
// have creator sign the message to create the contract
|
|
415
521
|
// and the token
|
|
416
522
|
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
417
|
-
...
|
|
523
|
+
...premintTypedDataDefinition({
|
|
418
524
|
verifyingContract: contractAddress,
|
|
419
525
|
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
420
|
-
chainId:
|
|
526
|
+
chainId: signingChainId,
|
|
421
527
|
premintConfig,
|
|
528
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
422
529
|
}),
|
|
423
530
|
account: creatorAccount,
|
|
424
531
|
});
|
|
@@ -429,8 +536,6 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
429
536
|
(ZORA_MINT_FEE + premintConfig.tokenConfig.pricePerToken) *
|
|
430
537
|
quantityToMint;
|
|
431
538
|
|
|
432
|
-
const comment = "I love this!";
|
|
433
|
-
|
|
434
539
|
await viemClients.testClient.setBalance({
|
|
435
540
|
address: collectorAccount,
|
|
436
541
|
value: parseEther("10"),
|
|
@@ -443,7 +548,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
443
548
|
// parameters are required to call this function
|
|
444
549
|
const mintHash = await viemClients.walletClient.writeContract({
|
|
445
550
|
abi: preminterAbi,
|
|
446
|
-
functionName: "
|
|
551
|
+
functionName: "premintV2",
|
|
447
552
|
account: collectorAccount,
|
|
448
553
|
chain: foundry,
|
|
449
554
|
address: PREMINTER_ADDRESS,
|
|
@@ -452,7 +557,11 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
452
557
|
premintConfig,
|
|
453
558
|
signedMessage,
|
|
454
559
|
quantityToMint,
|
|
455
|
-
|
|
560
|
+
{
|
|
561
|
+
mintComment: "",
|
|
562
|
+
mintRecipient: collectorAccount,
|
|
563
|
+
mintReferral: zeroAddress,
|
|
564
|
+
},
|
|
456
565
|
],
|
|
457
566
|
value: valueToSend,
|
|
458
567
|
});
|
|
@@ -475,46 +584,16 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
475
584
|
|
|
476
585
|
const creatorAttributionEvent = topics[0]!;
|
|
477
586
|
|
|
478
|
-
const { creator
|
|
479
|
-
creatorAttributionEvent.args;
|
|
587
|
+
const { creator: creatorFromEvent } = creatorAttributionEvent.args;
|
|
480
588
|
|
|
481
|
-
const
|
|
589
|
+
const recoveredSigner = await recoverCreatorFromCreatorAttribution({
|
|
590
|
+
creatorAttribution: creatorAttributionEvent.args,
|
|
591
|
+
chainId: signingChainId,
|
|
592
|
+
tokenContract: contractAddress,
|
|
593
|
+
});
|
|
482
594
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
domain: {
|
|
486
|
-
chainId,
|
|
487
|
-
name: domainName,
|
|
488
|
-
verifyingContract: contractAddress,
|
|
489
|
-
version,
|
|
490
|
-
},
|
|
491
|
-
types: {
|
|
492
|
-
EIP712Domain: [
|
|
493
|
-
{ name: "name", type: "string" },
|
|
494
|
-
{ name: "version", type: "string" },
|
|
495
|
-
{
|
|
496
|
-
name: "chainId",
|
|
497
|
-
type: "uint256",
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
name: "verifyingContract",
|
|
501
|
-
type: "address",
|
|
502
|
-
},
|
|
503
|
-
],
|
|
504
|
-
},
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
// re-build the eip-712 typed data hash, consisting of the hashed domain and the structHash emitted from the event:
|
|
508
|
-
const parts: Hex[] = ["0x1901", hashedDomain, structHash!];
|
|
509
|
-
|
|
510
|
-
const hashedTypedData = keccak256(concat(parts));
|
|
511
|
-
|
|
512
|
-
const recoveredSigner = await recoverAddress({
|
|
513
|
-
hash: hashedTypedData,
|
|
514
|
-
signature: signature!,
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
expect(recoveredSigner).toBe(creator);
|
|
595
|
+
expect(creatorFromEvent).toBe(creatorAccount);
|
|
596
|
+
expect(recoveredSigner).toBe(creatorFromEvent);
|
|
518
597
|
},
|
|
519
598
|
);
|
|
520
599
|
});
|