@zoralabs/protocol-sdk 0.5.12 → 0.5.14

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 (40) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +16 -0
  3. package/dist/apis/chain-constants.d.ts.map +1 -1
  4. package/dist/apis/generated/premint-api-types.d.ts +1 -1
  5. package/dist/apis/generated/premint-api-types.d.ts.map +1 -1
  6. package/dist/index.cjs +1482 -11683
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.js +1468 -11678
  9. package/dist/index.js.map +1 -1
  10. package/dist/mints/mints-contracts.d.ts +127 -154
  11. package/dist/mints/mints-contracts.d.ts.map +1 -1
  12. package/dist/mints/mints-eth-unwrapper-and-caller.d.ts +1 -24
  13. package/dist/mints/mints-eth-unwrapper-and-caller.d.ts.map +1 -1
  14. package/dist/mints/mints-queries.d.ts.map +1 -1
  15. package/dist/premint/contract-types.d.ts +2 -121
  16. package/dist/premint/contract-types.d.ts.map +1 -1
  17. package/dist/premint/conversions.d.ts +15 -35
  18. package/dist/premint/conversions.d.ts.map +1 -1
  19. package/dist/premint/premint-api-client.d.ts +1 -1
  20. package/dist/premint/premint-api-client.d.ts.map +1 -1
  21. package/dist/premint/premint-client.d.ts +2717 -4
  22. package/dist/premint/premint-client.d.ts.map +1 -1
  23. package/dist/premint/preminter.d.ts +3 -17
  24. package/dist/premint/preminter.d.ts.map +1 -1
  25. package/dist/preminter.d.ts +1 -1
  26. package/package.json +2 -3
  27. package/src/apis/chain-constants.ts +8 -0
  28. package/src/apis/generated/premint-api-types.ts +1 -0
  29. package/src/mint/mint-api-client.ts +3 -3
  30. package/src/mints/mints-contracts.test.ts +3 -5
  31. package/src/mints/mints-contracts.ts +16 -128
  32. package/src/mints/mints-queries.ts +1 -2
  33. package/src/premint/contract-types.ts +4 -106
  34. package/src/premint/conversions.ts +2 -1
  35. package/src/premint/premint-api-client.ts +1 -1
  36. package/src/premint/premint-client.test.ts +17 -6
  37. package/src/premint/premint-client.ts +28 -23
  38. package/src/premint/preminter.test.ts +239 -143
  39. package/src/premint/preminter.ts +11 -64
  40. package/test-integration/premint-client.test.ts +2 -0
@@ -5,19 +5,16 @@ import type {
5
5
  Chain,
6
6
  Hex,
7
7
  PublicClient,
8
- SimulateContractParameters,
9
8
  TransactionReceipt,
10
9
  WalletClient,
11
10
  } from "viem";
12
11
  import { zoraCreator1155PremintExecutorImplABI } from "@zoralabs/protocol-deployments";
13
12
  import {
14
13
  getPremintCollectionAddress,
15
- premintTypedDataDefinition,
16
14
  isValidSignature,
17
15
  isAuthorizedToCreatePremint,
18
16
  getPremintExecutorAddress,
19
17
  applyUpdateToPremint,
20
- markPremintDeleted,
21
18
  makeNewPremint,
22
19
  supportsPremintVersion,
23
20
  getPremintMintCosts,
@@ -28,13 +25,14 @@ import {
28
25
  PremintConfigVersion,
29
26
  ContractCreationConfig,
30
27
  TokenConfigForVersion,
31
- PremintConfigWithVersion,
32
28
  TokenCreationConfigV1,
33
29
  TokenCreationConfigV2,
34
30
  TokenCreationConfig,
35
31
  PremintConfigForVersion,
36
- MintArguments,
37
- } from "./contract-types";
32
+ PremintConfigWithVersion,
33
+ PremintMintArguments,
34
+ premintTypedDataDefinition,
35
+ } from "@zoralabs/protocol-deployments";
38
36
  import { PremintAPIClient } from "./premint-api-client";
39
37
  import type { DecodeEventLogReturnType } from "viem";
40
38
  import { OPEN_EDITION_MINT_SIZE } from "../constants";
@@ -92,21 +90,28 @@ const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
92
90
  creatorAccount,
93
91
  }: {
94
92
  chainId: number;
95
- premintConfigVersion: PremintConfigVersion;
93
+ premintConfigVersion: T;
96
94
  tokenCreationConfig: Partial<TokenConfigForVersion<T>> & { tokenURI: string };
97
95
  creatorAccount: Address;
98
96
  }): TokenConfigForVersion<T> => {
97
+ if (premintConfigVersion === PremintConfigVersion.V3) {
98
+ throw new Error("PremintV3 not supported in SDK");
99
+ }
100
+
99
101
  const fixedPriceMinter =
100
- tokenCreationConfig.fixedPriceMinter ||
101
- getDefaultFixedPriceMinterAddress(chainId);
102
+ (
103
+ tokenCreationConfig as
104
+ | Partial<TokenCreationConfigV1>
105
+ | Partial<TokenCreationConfigV2>
106
+ ).fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
102
107
 
103
108
  if (premintConfigVersion === PremintConfigVersion.V1) {
104
109
  return {
105
110
  fixedPriceMinter,
106
111
  ...defaultTokenConfigV1MintArguments(),
107
112
  royaltyRecipient: creatorAccount,
108
- ...tokenCreationConfig,
109
- };
113
+ ...(tokenCreationConfig as Partial<TokenCreationConfigV1>),
114
+ } as TokenCreationConfigV1;
110
115
  } else if (premintConfigVersion === PremintConfigVersion.V2) {
111
116
  return {
112
117
  fixedPriceMinter,
@@ -265,7 +270,11 @@ class PremintClient {
265
270
  uid: uid,
266
271
  });
267
272
 
268
- const deletedPremint = markPremintDeleted(premintConfig);
273
+ const deletedPremint = {
274
+ ...premintConfig,
275
+ version: premintConfig.version + 1,
276
+ deleted: true,
277
+ };
269
278
 
270
279
  return await this.signAndSubmitPremint({
271
280
  walletClient,
@@ -363,6 +372,7 @@ class PremintClient {
363
372
 
364
373
  const premintConfig = makeNewPremint({
365
374
  tokenConfig: makeTokenConfigWithDefaults({
375
+ // @ts-ignore
366
376
  premintConfigVersion: actualVersion,
367
377
  tokenCreationConfig,
368
378
  creatorAccount:
@@ -511,16 +521,7 @@ class PremintClient {
511
521
  platformReferral?: Address;
512
522
  mintRecipient?: Address;
513
523
  };
514
- }): Promise<
515
- SimulateContractParameters<
516
- typeof zoraCreator1155PremintExecutorImplABI,
517
- "premintV1" | "premintV2",
518
- any,
519
- any,
520
- any,
521
- Account | Address
522
- >
523
- > {
524
+ }) {
524
525
  if (mintArguments && mintArguments?.quantityToMint < 1) {
525
526
  throw new Error("Quantity to mint cannot be below 1");
526
527
  }
@@ -537,6 +538,10 @@ class PremintClient {
537
538
 
538
539
  const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
539
540
 
541
+ if (premintConfigVersion === PremintConfigVersion.V3) {
542
+ throw new Error("PremintV3 not supported in premint SDK");
543
+ }
544
+
540
545
  const value = (
541
546
  await getPremintMintCosts({
542
547
  tokenContract,
@@ -546,7 +551,7 @@ class PremintClient {
546
551
  })
547
552
  ).totalCost;
548
553
 
549
- const mintArgumentsContract: MintArguments = {
554
+ const mintArgumentsContract: PremintMintArguments = {
550
555
  mintComment: mintArguments?.mintComment || "",
551
556
  mintRecipient:
552
557
  mintArguments?.mintRecipient ||
@@ -1,5 +1,5 @@
1
1
  import { Address, zeroAddress } from "viem";
2
- import { foundry } from "viem/chains";
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 [deployerAccount, creatorAccount, collectorAccount] =
122
- (await walletClient.getAddresses()) as [Address, Address, Address, Address];
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: zoraCreator1155FactoryImplAddress[999],
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: 3118200,
155
+ forkBlockNumber: 8948974,
156
+ anvilChainId: zoraSepolia.id,
149
157
  });
150
158
 
151
159
  describe("ZoraCreator1155Preminter", () => {
152
- // skip for now - we need to make this work on zora testnet chain too
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: "getContractAddress",
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: 999,
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: "getContractAddress",
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: foundry.id,
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: "getContractAddress",
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: foundry.id,
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: "getContractAddress",
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: foundry.id,
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: 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: "premintV1",
393
+ functionName: "premint",
385
394
  account: collectorAccount,
386
- chain: foundry,
395
+ chain: viemClients.chain,
387
396
  address: PREMINTER_ADDRESS,
388
397
  args: [
389
398
  contractConfig,
390
- premintConfig1,
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: foundry.id,
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: "premintV2",
472
+ functionName: "premint",
458
473
  account: collectorAccount,
459
- chain: foundry,
474
+ chain: viemClients.chain,
460
475
  address: PREMINTER_ADDRESS,
461
476
  args: [
462
477
  contractConfig,
463
- premintConfig2,
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
- zoraSepoliaAnvilTest(
509
- "can decode the CreatorAttribution event",
510
- async ({ viemClients }) => {
511
- const {
512
- fixedPriceMinterAddress,
513
- accounts: { creatorAccount, collectorAccount },
514
- } = await setupContracts({ viemClients });
515
- const premintConfig = defaultPremintConfigV2({
516
- fixedPriceMinter: fixedPriceMinterAddress,
517
- creatorAccount,
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
- const valueToSend = (
551
- await getPremintMintCosts({
552
- publicClient: viemClients.publicClient,
553
- quantityToMint,
554
- tokenContract: contractAddress,
555
- tokenPrice: premintConfig.tokenConfig.pricePerToken,
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
- await viemClients.testClient.setBalance({
560
- address: collectorAccount,
561
- value: parseEther("10"),
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
- // now have the collector execute the first signed message;
565
- // it should create the contract, the token,
566
- // and min the quantity to mint tokens to the collector
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
- // ensure it succeeded
590
- const receipt = await viemClients.publicClient.waitForTransactionReceipt({
591
- hash: mintHash,
592
- });
558
+ // modify contract config to have collaborators
559
+ contractConfig.additionalAdmins = [collaboratorAccount];
593
560
 
594
- expect(receipt.status).toBe("success");
561
+ const contractAddress = await viemClients.publicClient.readContract({
562
+ abi: preminterAbi,
563
+ address: PREMINTER_ADDRESS,
564
+ functionName: "getContractWithAdditionalAdminsAddress",
565
+ args: [contractConfig],
566
+ });
595
567
 
596
- // get the CreatorAttribution event from the erc1155 contract:
597
- const topics = await viemClients.publicClient.getContractEvents({
598
- abi: zoraCreator1155ImplABI,
599
- address: contractAddress,
600
- eventName: "CreatorAttribution",
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
- expect(topics.length).toBe(1);
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
- const creatorAttributionEvent = topics[0]!;
660
+ // ensure it succeeded
661
+ expect(
662
+ (
663
+ await viemClients.publicClient.waitForTransactionReceipt({
664
+ hash: tx,
665
+ })
666
+ ).status,
667
+ ).toBe("success");
606
668
 
607
- const { creator: creatorFromEvent } = creatorAttributionEvent.args;
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
- const recoveredSigner = await recoverCreatorFromCreatorAttribution({
610
- creatorAttribution: creatorAttributionEvent.args,
611
- chainId: signingChainId,
612
- tokenContract: contractAddress,
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
- expect(creatorFromEvent).toBe(creatorAccount);
616
- expect(recoveredSigner).toBe(creatorFromEvent);
617
- },
618
- );
710
+ expect(tokenBalances).toEqual([quantityToMint, quantityToMint]);
711
+ },
712
+ // 10 second timeout
713
+ 40 * 1000,
714
+ );
619
715
  });