@zoralabs/protocol-sdk 0.5.13 → 0.5.15
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 +15 -0
- package/README.md +42 -2
- package/dist/apis/chain-constants.d.ts.map +1 -1
- package/dist/apis/generated/premint-api-types.d.ts +1 -1
- package/dist/apis/generated/premint-api-types.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +1534 -11490
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1493 -11466
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +14 -6
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +3 -2
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mints/mints-contracts.d.ts +124 -26
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/mints/mints-queries.d.ts.map +1 -1
- package/dist/premint/contract-types.d.ts +2 -28
- package/dist/premint/contract-types.d.ts.map +1 -1
- package/dist/premint/conversions.d.ts +15 -35
- package/dist/premint/conversions.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +1 -1
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +2717 -4
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +3 -17
- package/dist/premint/preminter.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/apis/chain-constants.ts +8 -0
- package/src/apis/generated/premint-api-types.ts +1 -0
- package/src/constants.ts +36 -0
- package/src/mint/mint-api-client.ts +107 -45
- package/src/mint/mint-client.test.ts +113 -2
- package/src/mint/mint-client.ts +64 -23
- package/src/mints/mints-contracts.test.ts +3 -5
- package/src/mints/mints-contracts.ts +2 -2
- package/src/mints/mints-queries.ts +1 -2
- package/src/premint/contract-types.ts +4 -54
- package/src/premint/conversions.ts +2 -1
- package/src/premint/premint-api-client.ts +1 -1
- package/src/premint/premint-client.test.ts +17 -6
- package/src/premint/premint-client.ts +28 -23
- package/src/premint/preminter.test.ts +239 -143
- package/src/premint/preminter.ts +12 -55
- package/test-integration/premint-client.test.ts +2 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, zeroAddress } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { zoraSepolia } from "viem/chains";
|
|
3
3
|
import { describe, expect } from "vitest";
|
|
4
4
|
import { parseEther } from "viem";
|
|
5
5
|
import {
|
|
@@ -7,24 +7,22 @@ import {
|
|
|
7
7
|
zoraCreator1155ImplABI,
|
|
8
8
|
zoraCreator1155FactoryImplAddress,
|
|
9
9
|
zoraCreator1155FactoryImplConfig,
|
|
10
|
+
PremintConfigV1,
|
|
11
|
+
TokenCreationConfigV1,
|
|
12
|
+
PremintConfigVersion,
|
|
13
|
+
TokenCreationConfigV2,
|
|
14
|
+
PremintConfigV2,
|
|
15
|
+
PremintMintArguments,
|
|
16
|
+
ContractCreationConfig,
|
|
17
|
+
premintTypedDataDefinition,
|
|
18
|
+
encodePremintConfig,
|
|
10
19
|
} from "@zoralabs/protocol-deployments";
|
|
11
20
|
|
|
12
21
|
import {
|
|
13
|
-
premintTypedDataDefinition,
|
|
14
22
|
isValidSignature,
|
|
15
|
-
recoverCreatorFromCreatorAttribution,
|
|
16
23
|
getPremintExecutorAddress,
|
|
17
24
|
getPremintMintCosts,
|
|
18
25
|
} from "./preminter";
|
|
19
|
-
import {
|
|
20
|
-
ContractCreationConfig,
|
|
21
|
-
PremintConfigV1,
|
|
22
|
-
TokenCreationConfigV1,
|
|
23
|
-
PremintConfigVersion,
|
|
24
|
-
TokenCreationConfigV2,
|
|
25
|
-
PremintConfigV2,
|
|
26
|
-
MintArguments,
|
|
27
|
-
} from "./contract-types";
|
|
28
26
|
import { AnvilViemClientsTest, forkUrls, makeAnvilTest } from "src/anvil";
|
|
29
27
|
|
|
30
28
|
// create token and contract creation config:
|
|
@@ -36,6 +34,7 @@ export const defaultContractConfig = ({
|
|
|
36
34
|
contractAdmin,
|
|
37
35
|
contractURI: "ipfs://asdfasdfasdf",
|
|
38
36
|
contractName: "My fun NFT",
|
|
37
|
+
additionalAdmins: [],
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
const defaultTokenConfigV1 = (
|
|
@@ -109,17 +108,21 @@ export const defaultPremintConfigV2 = ({
|
|
|
109
108
|
|
|
110
109
|
const PREMINTER_ADDRESS = getPremintExecutorAddress();
|
|
111
110
|
|
|
112
|
-
const anvilTest = makeAnvilTest({
|
|
113
|
-
forkUrl: forkUrls.zoraSepolia,
|
|
114
|
-
forkBlockNumber: 1265490,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
111
|
async function setupContracts({
|
|
118
|
-
viemClients: { walletClient, testClient, publicClient },
|
|
112
|
+
viemClients: { walletClient, testClient, publicClient, chain },
|
|
119
113
|
}: AnvilViemClientsTest) {
|
|
120
114
|
// JSON-RPC Account
|
|
121
|
-
const [
|
|
122
|
-
|
|
115
|
+
const [
|
|
116
|
+
deployerAccount,
|
|
117
|
+
creatorAccount,
|
|
118
|
+
collectorAccount,
|
|
119
|
+
collaboratorAccount,
|
|
120
|
+
] = (await walletClient.getAddresses()) as [
|
|
121
|
+
Address,
|
|
122
|
+
Address,
|
|
123
|
+
Address,
|
|
124
|
+
Address,
|
|
125
|
+
];
|
|
123
126
|
|
|
124
127
|
// deploy signature minter contract
|
|
125
128
|
await testClient.setBalance({
|
|
@@ -129,7 +132,10 @@ async function setupContracts({
|
|
|
129
132
|
|
|
130
133
|
const fixedPriceMinterAddress = await publicClient.readContract({
|
|
131
134
|
abi: zoraCreator1155FactoryImplConfig.abi,
|
|
132
|
-
address:
|
|
135
|
+
address:
|
|
136
|
+
zoraCreator1155FactoryImplAddress[
|
|
137
|
+
chain.id as keyof typeof zoraCreator1155FactoryImplAddress
|
|
138
|
+
],
|
|
133
139
|
functionName: "fixedPriceMinter",
|
|
134
140
|
});
|
|
135
141
|
|
|
@@ -138,6 +144,7 @@ async function setupContracts({
|
|
|
138
144
|
deployerAccount,
|
|
139
145
|
creatorAccount,
|
|
140
146
|
collectorAccount,
|
|
147
|
+
collaboratorAccount,
|
|
141
148
|
},
|
|
142
149
|
fixedPriceMinterAddress,
|
|
143
150
|
};
|
|
@@ -145,12 +152,12 @@ async function setupContracts({
|
|
|
145
152
|
|
|
146
153
|
const zoraSepoliaAnvilTest = makeAnvilTest({
|
|
147
154
|
forkUrl: forkUrls.zoraSepolia,
|
|
148
|
-
forkBlockNumber:
|
|
155
|
+
forkBlockNumber: 8948974,
|
|
156
|
+
anvilChainId: zoraSepolia.id,
|
|
149
157
|
});
|
|
150
158
|
|
|
151
159
|
describe("ZoraCreator1155Preminter", () => {
|
|
152
|
-
|
|
153
|
-
anvilTest(
|
|
160
|
+
zoraSepoliaAnvilTest(
|
|
154
161
|
"can sign on the forked premint contract",
|
|
155
162
|
async ({ viemClients }) => {
|
|
156
163
|
const {
|
|
@@ -170,14 +177,14 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
170
177
|
const contractAddress = await viemClients.publicClient.readContract({
|
|
171
178
|
abi: preminterAbi,
|
|
172
179
|
address: preminterAddress,
|
|
173
|
-
functionName: "
|
|
180
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
174
181
|
args: [contractConfig],
|
|
175
182
|
});
|
|
176
183
|
|
|
177
184
|
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
178
185
|
...premintTypedDataDefinition({
|
|
179
186
|
verifyingContract: contractAddress,
|
|
180
|
-
chainId:
|
|
187
|
+
chainId: viemClients.chain.id,
|
|
181
188
|
premintConfig,
|
|
182
189
|
premintConfigVersion: PremintConfigVersion.V1,
|
|
183
190
|
}),
|
|
@@ -213,7 +220,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
213
220
|
const tokenContract = await viemClients.publicClient.readContract({
|
|
214
221
|
abi: preminterAbi,
|
|
215
222
|
address: PREMINTER_ADDRESS,
|
|
216
|
-
functionName: "
|
|
223
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
217
224
|
args: [contractConfig],
|
|
218
225
|
});
|
|
219
226
|
|
|
@@ -222,7 +229,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
222
229
|
...premintTypedDataDefinition({
|
|
223
230
|
verifyingContract: tokenContract,
|
|
224
231
|
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
225
|
-
chainId:
|
|
232
|
+
chainId: viemClients.chain.id,
|
|
226
233
|
premintConfig,
|
|
227
234
|
premintConfigVersion: PremintConfigVersion.V1,
|
|
228
235
|
}),
|
|
@@ -267,7 +274,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
267
274
|
const tokenContract = await viemClients.publicClient.readContract({
|
|
268
275
|
abi: preminterAbi,
|
|
269
276
|
address: PREMINTER_ADDRESS,
|
|
270
|
-
functionName: "
|
|
277
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
271
278
|
args: [contractConfig],
|
|
272
279
|
});
|
|
273
280
|
|
|
@@ -276,7 +283,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
276
283
|
...premintTypedDataDefinition({
|
|
277
284
|
verifyingContract: tokenContract,
|
|
278
285
|
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
279
|
-
chainId:
|
|
286
|
+
chainId: viemClients.chain.id,
|
|
280
287
|
premintConfig,
|
|
281
288
|
premintConfigVersion: PremintConfigVersion.V2,
|
|
282
289
|
}),
|
|
@@ -323,7 +330,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
323
330
|
let contractAddress = await viemClients.publicClient.readContract({
|
|
324
331
|
abi: preminterAbi,
|
|
325
332
|
address: PREMINTER_ADDRESS,
|
|
326
|
-
functionName: "
|
|
333
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
327
334
|
args: [contractConfig],
|
|
328
335
|
});
|
|
329
336
|
|
|
@@ -333,7 +340,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
333
340
|
...premintTypedDataDefinition({
|
|
334
341
|
verifyingContract: contractAddress,
|
|
335
342
|
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
336
|
-
chainId:
|
|
343
|
+
chainId: viemClients.chain.id,
|
|
337
344
|
premintConfig: premintConfig1,
|
|
338
345
|
premintConfigVersion: PremintConfigVersion.V1,
|
|
339
346
|
}),
|
|
@@ -368,12 +375,14 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
368
375
|
expect(contractCreated).toBe(false);
|
|
369
376
|
expect(tokenId).toBe(0n);
|
|
370
377
|
|
|
371
|
-
const mintArguments:
|
|
378
|
+
const mintArguments: PremintMintArguments = {
|
|
372
379
|
mintComment: "",
|
|
373
380
|
mintRecipient: collectorAccount,
|
|
374
381
|
mintRewardsRecipients: [],
|
|
375
382
|
};
|
|
376
383
|
|
|
384
|
+
const firstMinter = collectorAccount;
|
|
385
|
+
|
|
377
386
|
// now have the collector execute the first signed message;
|
|
378
387
|
// it should create the contract, the token,
|
|
379
388
|
// and min the quantity to mint tokens to the collector
|
|
@@ -381,16 +390,22 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
381
390
|
// parameters are required to call this function
|
|
382
391
|
const mintHash = await viemClients.walletClient.writeContract({
|
|
383
392
|
abi: preminterAbi,
|
|
384
|
-
functionName: "
|
|
393
|
+
functionName: "premint",
|
|
385
394
|
account: collectorAccount,
|
|
386
|
-
chain:
|
|
395
|
+
chain: viemClients.chain,
|
|
387
396
|
address: PREMINTER_ADDRESS,
|
|
388
397
|
args: [
|
|
389
398
|
contractConfig,
|
|
390
|
-
|
|
399
|
+
zeroAddress,
|
|
400
|
+
encodePremintConfig({
|
|
401
|
+
premintConfig: premintConfig1,
|
|
402
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
403
|
+
}),
|
|
391
404
|
signedMessage,
|
|
392
405
|
quantityToMint,
|
|
393
406
|
mintArguments,
|
|
407
|
+
firstMinter,
|
|
408
|
+
zeroAddress,
|
|
394
409
|
],
|
|
395
410
|
value: valueToSend,
|
|
396
411
|
});
|
|
@@ -434,7 +449,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
434
449
|
const signedMessage2 = await viemClients.walletClient.signTypedData({
|
|
435
450
|
...premintTypedDataDefinition({
|
|
436
451
|
verifyingContract: contractAddress,
|
|
437
|
-
chainId:
|
|
452
|
+
chainId: viemClients.chain.id,
|
|
438
453
|
premintConfig: premintConfig2,
|
|
439
454
|
premintConfigVersion: PremintConfigVersion.V2,
|
|
440
455
|
}),
|
|
@@ -454,16 +469,22 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
454
469
|
|
|
455
470
|
const simulationResult = await viemClients.publicClient.simulateContract({
|
|
456
471
|
abi: preminterAbi,
|
|
457
|
-
functionName: "
|
|
472
|
+
functionName: "premint",
|
|
458
473
|
account: collectorAccount,
|
|
459
|
-
chain:
|
|
474
|
+
chain: viemClients.chain,
|
|
460
475
|
address: PREMINTER_ADDRESS,
|
|
461
476
|
args: [
|
|
462
477
|
contractConfig,
|
|
463
|
-
|
|
478
|
+
zeroAddress,
|
|
479
|
+
encodePremintConfig({
|
|
480
|
+
premintConfig: premintConfig2,
|
|
481
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
482
|
+
}),
|
|
464
483
|
signedMessage2,
|
|
465
484
|
quantityToMint2,
|
|
466
485
|
mintArguments,
|
|
486
|
+
firstMinter,
|
|
487
|
+
zeroAddress,
|
|
467
488
|
],
|
|
468
489
|
value: valueToSend2,
|
|
469
490
|
});
|
|
@@ -501,119 +522,194 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
501
522
|
|
|
502
523
|
expect(tokenBalance2).toBe(quantityToMint2);
|
|
503
524
|
},
|
|
504
|
-
// 10 second timeout
|
|
505
525
|
40 * 1000,
|
|
506
|
-
)
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const contractConfig = defaultContractConfig({
|
|
520
|
-
contractAdmin: creatorAccount,
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
// lets make it a random number to not break the existing tests that expect fresh data
|
|
524
|
-
premintConfig.uid = Math.round(Math.random() * 1000000);
|
|
525
|
-
|
|
526
|
-
let contractAddress = await viemClients.publicClient.readContract({
|
|
527
|
-
abi: preminterAbi,
|
|
528
|
-
address: PREMINTER_ADDRESS,
|
|
529
|
-
functionName: "getContractAddress",
|
|
530
|
-
args: [contractConfig],
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
const signingChainId = foundry.id;
|
|
534
|
-
|
|
535
|
-
// have creator sign the message to create the contract
|
|
536
|
-
// and the token
|
|
537
|
-
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
538
|
-
...premintTypedDataDefinition({
|
|
539
|
-
verifyingContract: contractAddress,
|
|
540
|
-
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
541
|
-
chainId: signingChainId,
|
|
542
|
-
premintConfig,
|
|
543
|
-
premintConfigVersion: PremintConfigVersion.V2,
|
|
544
|
-
}),
|
|
545
|
-
account: creatorAccount,
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
const quantityToMint = 2n;
|
|
526
|
+
),
|
|
527
|
+
zoraSepoliaAnvilTest(
|
|
528
|
+
"can have collaborators create premints that can be executed on existing contracts",
|
|
529
|
+
async ({ viemClients }) => {
|
|
530
|
+
const {
|
|
531
|
+
fixedPriceMinterAddress,
|
|
532
|
+
accounts: { creatorAccount, collectorAccount, collaboratorAccount },
|
|
533
|
+
} = await setupContracts({ viemClients });
|
|
534
|
+
|
|
535
|
+
await viemClients.testClient.setBalance({
|
|
536
|
+
address: collectorAccount,
|
|
537
|
+
value: parseEther("10"),
|
|
538
|
+
});
|
|
549
539
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
).totalCost;
|
|
540
|
+
// setup contract and token creation parameters
|
|
541
|
+
const premintConfig = defaultPremintConfigV2({
|
|
542
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
543
|
+
creatorAccount,
|
|
544
|
+
});
|
|
545
|
+
// lets make it a random number to not break the existing tests that expect fresh data
|
|
546
|
+
premintConfig.uid = Math.round(Math.random() * 1000000);
|
|
558
547
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
548
|
+
// create a premint config that a collaboratorw ill sign
|
|
549
|
+
const collaboratorPremintConfig = {
|
|
550
|
+
...premintConfig,
|
|
551
|
+
uid: Math.round(Math.random() * 1000000),
|
|
552
|
+
};
|
|
563
553
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
// the signature along with contract + token creation
|
|
568
|
-
// parameters are required to call this function
|
|
569
|
-
const mintHash = await viemClients.walletClient.writeContract({
|
|
570
|
-
abi: preminterAbi,
|
|
571
|
-
functionName: "premintV2",
|
|
572
|
-
account: collectorAccount,
|
|
573
|
-
chain: foundry,
|
|
574
|
-
address: PREMINTER_ADDRESS,
|
|
575
|
-
args: [
|
|
576
|
-
contractConfig,
|
|
577
|
-
premintConfig,
|
|
578
|
-
signedMessage,
|
|
579
|
-
quantityToMint,
|
|
580
|
-
{
|
|
581
|
-
mintComment: "",
|
|
582
|
-
mintRecipient: collectorAccount,
|
|
583
|
-
mintRewardsRecipients: [],
|
|
584
|
-
},
|
|
585
|
-
],
|
|
586
|
-
value: valueToSend,
|
|
587
|
-
});
|
|
554
|
+
const contractConfig = defaultContractConfig({
|
|
555
|
+
contractAdmin: creatorAccount,
|
|
556
|
+
});
|
|
588
557
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
hash: mintHash,
|
|
592
|
-
});
|
|
558
|
+
// modify contract config to have collaborators
|
|
559
|
+
contractConfig.additionalAdmins = [collaboratorAccount];
|
|
593
560
|
|
|
594
|
-
|
|
561
|
+
const contractAddress = await viemClients.publicClient.readContract({
|
|
562
|
+
abi: preminterAbi,
|
|
563
|
+
address: PREMINTER_ADDRESS,
|
|
564
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
565
|
+
args: [contractConfig],
|
|
566
|
+
});
|
|
595
567
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
568
|
+
// have creator sign the message to create the contract
|
|
569
|
+
// and the token
|
|
570
|
+
const creatorSignedMessage =
|
|
571
|
+
await viemClients.walletClient.signTypedData({
|
|
572
|
+
...premintTypedDataDefinition({
|
|
573
|
+
verifyingContract: contractAddress,
|
|
574
|
+
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
575
|
+
chainId: viemClients.chain.id,
|
|
576
|
+
premintConfig: premintConfig,
|
|
577
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
578
|
+
}),
|
|
579
|
+
account: creatorAccount,
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
const collaboratorSignedMessage =
|
|
583
|
+
await viemClients.walletClient.signTypedData({
|
|
584
|
+
...premintTypedDataDefinition({
|
|
585
|
+
verifyingContract: contractAddress,
|
|
586
|
+
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
587
|
+
chainId: viemClients.chain.id,
|
|
588
|
+
premintConfig: collaboratorPremintConfig,
|
|
589
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
590
|
+
}),
|
|
591
|
+
account: collaboratorAccount,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
const quantityToMint = 2n;
|
|
595
|
+
|
|
596
|
+
const valueToSend = (
|
|
597
|
+
await getPremintMintCosts({
|
|
598
|
+
publicClient: viemClients.publicClient,
|
|
599
|
+
quantityToMint,
|
|
600
|
+
tokenContract: contractAddress,
|
|
601
|
+
tokenPrice: premintConfig.tokenConfig.pricePerToken,
|
|
602
|
+
})
|
|
603
|
+
).totalCost;
|
|
604
|
+
|
|
605
|
+
const mintArguments: PremintMintArguments = {
|
|
606
|
+
mintComment: "",
|
|
607
|
+
mintRecipient: collectorAccount,
|
|
608
|
+
mintRewardsRecipients: [],
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const firstMinter = collectorAccount;
|
|
612
|
+
|
|
613
|
+
await viemClients.publicClient.simulateContract({
|
|
614
|
+
abi: preminterAbi,
|
|
615
|
+
functionName: "premint",
|
|
616
|
+
account: collectorAccount,
|
|
617
|
+
chain: viemClients.chain,
|
|
618
|
+
address: PREMINTER_ADDRESS,
|
|
619
|
+
args: [
|
|
620
|
+
contractConfig,
|
|
621
|
+
zeroAddress,
|
|
622
|
+
encodePremintConfig({
|
|
623
|
+
premintConfig: collaboratorPremintConfig,
|
|
624
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
625
|
+
}),
|
|
626
|
+
collaboratorSignedMessage,
|
|
627
|
+
quantityToMint,
|
|
628
|
+
mintArguments,
|
|
629
|
+
firstMinter,
|
|
630
|
+
zeroAddress,
|
|
631
|
+
],
|
|
632
|
+
value: valueToSend,
|
|
633
|
+
});
|
|
602
634
|
|
|
603
|
-
|
|
635
|
+
// now have the collector execute collaborators signed message;
|
|
636
|
+
// it should create the contract, the token, and add the collaborator
|
|
637
|
+
// as an admin to the contract along with the original creator
|
|
638
|
+
let tx = await viemClients.walletClient.writeContract({
|
|
639
|
+
abi: preminterAbi,
|
|
640
|
+
functionName: "premint",
|
|
641
|
+
account: collectorAccount,
|
|
642
|
+
chain: viemClients.chain,
|
|
643
|
+
address: PREMINTER_ADDRESS,
|
|
644
|
+
args: [
|
|
645
|
+
contractConfig,
|
|
646
|
+
zeroAddress,
|
|
647
|
+
encodePremintConfig({
|
|
648
|
+
premintConfig: collaboratorPremintConfig,
|
|
649
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
650
|
+
}),
|
|
651
|
+
collaboratorSignedMessage,
|
|
652
|
+
quantityToMint,
|
|
653
|
+
mintArguments,
|
|
654
|
+
firstMinter,
|
|
655
|
+
zeroAddress,
|
|
656
|
+
],
|
|
657
|
+
value: valueToSend,
|
|
658
|
+
});
|
|
604
659
|
|
|
605
|
-
|
|
660
|
+
// ensure it succeeded
|
|
661
|
+
expect(
|
|
662
|
+
(
|
|
663
|
+
await viemClients.publicClient.waitForTransactionReceipt({
|
|
664
|
+
hash: tx,
|
|
665
|
+
})
|
|
666
|
+
).status,
|
|
667
|
+
).toBe("success");
|
|
606
668
|
|
|
607
|
-
|
|
669
|
+
tx = await viemClients.walletClient.writeContract({
|
|
670
|
+
abi: preminterAbi,
|
|
671
|
+
functionName: "premint",
|
|
672
|
+
account: collectorAccount,
|
|
673
|
+
chain: viemClients.chain,
|
|
674
|
+
address: PREMINTER_ADDRESS,
|
|
675
|
+
args: [
|
|
676
|
+
contractConfig,
|
|
677
|
+
zeroAddress,
|
|
678
|
+
encodePremintConfig({
|
|
679
|
+
premintConfig: premintConfig,
|
|
680
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
681
|
+
}),
|
|
682
|
+
creatorSignedMessage,
|
|
683
|
+
quantityToMint,
|
|
684
|
+
mintArguments,
|
|
685
|
+
firstMinter,
|
|
686
|
+
zeroAddress,
|
|
687
|
+
],
|
|
688
|
+
value: valueToSend,
|
|
689
|
+
});
|
|
608
690
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
691
|
+
expect(
|
|
692
|
+
(
|
|
693
|
+
await viemClients.publicClient.waitForTransactionReceipt({
|
|
694
|
+
hash: tx,
|
|
695
|
+
})
|
|
696
|
+
).status,
|
|
697
|
+
).toBe("success");
|
|
698
|
+
|
|
699
|
+
// get balance of second token
|
|
700
|
+
const tokenBalances = await viemClients.publicClient.readContract({
|
|
701
|
+
abi: zoraCreator1155ImplABI,
|
|
702
|
+
address: contractAddress,
|
|
703
|
+
functionName: "balanceOfBatch",
|
|
704
|
+
args: [
|
|
705
|
+
[collectorAccount, collectorAccount],
|
|
706
|
+
[1n, 2n],
|
|
707
|
+
],
|
|
708
|
+
});
|
|
614
709
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
710
|
+
expect(tokenBalances).toEqual([quantityToMint, quantityToMint]);
|
|
711
|
+
},
|
|
712
|
+
// 10 second timeout
|
|
713
|
+
40 * 1000,
|
|
714
|
+
);
|
|
619
715
|
});
|
package/src/premint/preminter.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
zoraCreator1155PremintExecutorImplABI,
|
|
6
6
|
zoraCreator1155PremintExecutorImplAddress,
|
|
7
7
|
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
8
|
+
premintTypedDataDefinition,
|
|
8
9
|
} from "@zoralabs/protocol-deployments";
|
|
9
10
|
import {
|
|
10
|
-
TypedDataDefinition,
|
|
11
11
|
recoverTypedDataAddress,
|
|
12
12
|
Hex,
|
|
13
13
|
PublicClient,
|
|
@@ -28,50 +28,11 @@ import {
|
|
|
28
28
|
PremintConfigVersion,
|
|
29
29
|
PremintConfigWithVersion,
|
|
30
30
|
TokenCreationConfig,
|
|
31
|
-
} from "./contract-types";
|
|
32
|
-
import {
|
|
33
|
-
premintV1TypedDataDefinition,
|
|
34
|
-
premintV2TypedDataDefinition,
|
|
35
31
|
} from "@zoralabs/protocol-deployments";
|
|
36
32
|
import { MintCosts } from "src/mint/mint-client";
|
|
37
33
|
|
|
38
34
|
export const getPremintExecutorAddress = () =>
|
|
39
|
-
zoraCreator1155PremintExecutorImplAddress[999];
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Creates a typed data definition for a premint config. Works for all versions of the premint config by specifying the premintConfigVersion.
|
|
43
|
-
*
|
|
44
|
-
* @param params.verifyingContract the address of the 1155 contract
|
|
45
|
-
* @param params.chainId the chain id the premint is signed for
|
|
46
|
-
* @param params.premintConfigVersion the version of the premint config
|
|
47
|
-
* @param params.premintConfig the premint config
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
export const premintTypedDataDefinition = <T extends PremintConfigVersion>({
|
|
51
|
-
verifyingContract,
|
|
52
|
-
chainId,
|
|
53
|
-
premintConfigVersion: version,
|
|
54
|
-
premintConfig,
|
|
55
|
-
}: {
|
|
56
|
-
verifyingContract: Address;
|
|
57
|
-
chainId: number;
|
|
58
|
-
} & PremintConfigWithVersion<T>): TypedDataDefinition => {
|
|
59
|
-
if (version === PremintConfigVersion.V1)
|
|
60
|
-
return premintV1TypedDataDefinition({
|
|
61
|
-
chainId,
|
|
62
|
-
creator1155Contract: verifyingContract,
|
|
63
|
-
message: premintConfig as PremintConfigV1,
|
|
64
|
-
});
|
|
65
|
-
if (version === PremintConfigVersion.V2) {
|
|
66
|
-
return premintV2TypedDataDefinition({
|
|
67
|
-
chainId,
|
|
68
|
-
creator1155Contract: verifyingContract,
|
|
69
|
-
message: premintConfig as PremintConfigV2,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
throw new Error(`Invalid version ${version}`);
|
|
74
|
-
};
|
|
35
|
+
zoraCreator1155PremintExecutorImplAddress[999] as Address;
|
|
75
36
|
|
|
76
37
|
export type IsValidSignatureReturn = {
|
|
77
38
|
isAuthorized: boolean;
|
|
@@ -89,12 +50,19 @@ export async function isAuthorizedToCreatePremint({
|
|
|
89
50
|
publicClient: PublicClient;
|
|
90
51
|
signer: Address;
|
|
91
52
|
}) {
|
|
53
|
+
if (collection.additionalAdmins.length > 0)
|
|
54
|
+
throw new Error("additionalAdmins not supported yet.");
|
|
92
55
|
// otherwize, we must assume the newer version of premint executor is deployed, so we call that.
|
|
93
56
|
return await publicClient.readContract({
|
|
94
57
|
abi: preminterAbi,
|
|
95
58
|
address: getPremintExecutorAddress(),
|
|
96
|
-
functionName: "
|
|
97
|
-
args: [
|
|
59
|
+
functionName: "isAuthorizedToCreatePremintWithAdditionalAdmins",
|
|
60
|
+
args: [
|
|
61
|
+
signer,
|
|
62
|
+
collection.contractAdmin,
|
|
63
|
+
collectionAddress,
|
|
64
|
+
collection.additionalAdmins,
|
|
65
|
+
],
|
|
98
66
|
});
|
|
99
67
|
}
|
|
100
68
|
|
|
@@ -106,9 +74,8 @@ export async function recoverPremintSigner<T extends PremintConfigVersion>({
|
|
|
106
74
|
chainId: number;
|
|
107
75
|
verifyingContract: Address;
|
|
108
76
|
} & PremintConfigWithVersion<T>): Promise<Address> {
|
|
109
|
-
const typedData = premintTypedDataDefinition(rest);
|
|
110
77
|
return await recoverTypedDataAddress({
|
|
111
|
-
...
|
|
78
|
+
...premintTypedDataDefinition(rest),
|
|
112
79
|
signature,
|
|
113
80
|
});
|
|
114
81
|
}
|
|
@@ -313,16 +280,6 @@ export async function getPremintCollectionAddress({
|
|
|
313
280
|
});
|
|
314
281
|
}
|
|
315
282
|
|
|
316
|
-
export function markPremintDeleted<T extends PremintConfig>(
|
|
317
|
-
premintConfig: T,
|
|
318
|
-
): T {
|
|
319
|
-
return {
|
|
320
|
-
...premintConfig,
|
|
321
|
-
version: premintConfig.version + 1,
|
|
322
|
-
deleted: true,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
283
|
export function applyUpdateToPremint({
|
|
327
284
|
uid,
|
|
328
285
|
version,
|
|
@@ -54,6 +54,7 @@ tests.forEach(({ anvilTest, chain }) => {
|
|
|
54
54
|
contractName: "Testing Contract Premint V2",
|
|
55
55
|
contractURI:
|
|
56
56
|
"ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3f",
|
|
57
|
+
additionalAdmins: [],
|
|
57
58
|
},
|
|
58
59
|
premintConfigVersion: PremintConfigVersion.V2,
|
|
59
60
|
tokenCreationConfig: {
|
|
@@ -110,6 +111,7 @@ tests.forEach(({ anvilTest, chain }) => {
|
|
|
110
111
|
contractName: `Testing Contract Premint V1 ${publicClient.chain?.name}`,
|
|
111
112
|
contractURI:
|
|
112
113
|
"ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3fg",
|
|
114
|
+
additionalAdmins: [],
|
|
113
115
|
},
|
|
114
116
|
premintConfigVersion: PremintConfigVersion.V1,
|
|
115
117
|
tokenCreationConfig: {
|