@zoralabs/protocol-sdk 0.4.0 → 0.4.1

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.
@@ -23,6 +23,8 @@ import {
23
23
  markPremintDeleted,
24
24
  makeNewPremint,
25
25
  supportsPremintVersion,
26
+ getPremintMintCosts,
27
+ makeMintRewardsRecipient,
26
28
  } from "./preminter";
27
29
  import {
28
30
  PremintConfigV2,
@@ -39,9 +41,9 @@ import type { PremintSignatureResponse } from "./premint-api-client";
39
41
  import { PremintAPIClient } from "./premint-api-client";
40
42
  import type { DecodeEventLogReturnType } from "viem";
41
43
  import { OPEN_EDITION_MINT_SIZE } from "../constants";
42
- import { REWARD_PER_TOKEN } from "src/apis/chain-constants";
43
44
  import { IHttpClient } from "src/apis/http-api-base";
44
45
  import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
46
+ import { MintCosts } from "src/mint/mint-client";
45
47
 
46
48
  type PremintedLogType = DecodeEventLogReturnType<
47
49
  typeof zoraCreator1155PremintExecutorImplABI,
@@ -461,6 +463,23 @@ class PremintClient {
461
463
  });
462
464
  }
463
465
 
466
+ async getMintCosts({
467
+ tokenContract,
468
+ quantityToMint,
469
+ tokenCreationConfig,
470
+ }: {
471
+ quantityToMint: bigint;
472
+ tokenContract: Address;
473
+ tokenCreationConfig: TokenCreationConfig;
474
+ }): Promise<MintCosts> {
475
+ return await getPremintMintCosts({
476
+ publicClient: this.publicClient,
477
+ quantityToMint,
478
+ tokenContract,
479
+ tokenPrice: tokenCreationConfig.pricePerToken,
480
+ });
481
+ }
482
+
464
483
  /**
465
484
  * Execute premint on-chain
466
485
  *
@@ -486,6 +505,7 @@ class PremintClient {
486
505
  quantityToMint: number;
487
506
  mintComment?: string;
488
507
  mintReferral?: Address;
508
+ platformReferral?: Address;
489
509
  mintRecipient?: Address;
490
510
  };
491
511
  }): Promise<SimulateContractParameters> {
@@ -505,7 +525,14 @@ class PremintClient {
505
525
 
506
526
  const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
507
527
 
508
- const value = numberToMint * REWARD_PER_TOKEN;
528
+ const value = (
529
+ await getPremintMintCosts({
530
+ tokenContract,
531
+ quantityToMint: numberToMint,
532
+ publicClient: this.publicClient,
533
+ tokenPrice: premintConfig.tokenConfig.pricePerToken,
534
+ })
535
+ ).totalCost;
509
536
 
510
537
  if (premintConfigVersion === PremintConfigVersion.V1) {
511
538
  return {
@@ -545,7 +572,10 @@ class PremintClient {
545
572
  {
546
573
  mintComment: mintArguments?.mintComment || "",
547
574
  mintRecipient: mintArguments?.mintRecipient || accountAddress,
548
- mintReferral: mintArguments?.mintReferral || zeroAddress,
575
+ mintRewardsRecipients: makeMintRewardsRecipient({
576
+ mintReferral: mintArguments?.mintReferral,
577
+ platformReferral: mintArguments?.platformReferral,
578
+ }),
549
579
  },
550
580
  ],
551
581
  } satisfies SimulateContractParameters<
@@ -14,6 +14,7 @@ import {
14
14
  isValidSignature,
15
15
  recoverCreatorFromCreatorAttribution,
16
16
  getPremintExecutorAddress,
17
+ getPremintMintCosts,
17
18
  } from "./preminter";
18
19
  import {
19
20
  ContractCreationConfig,
@@ -102,8 +103,6 @@ const defaultPremintConfigV2 = ({
102
103
  version: 0,
103
104
  });
104
105
 
105
- const ZORA_MINT_FEE = parseEther("0.000777");
106
-
107
106
  const PREMINTER_ADDRESS = getPremintExecutorAddress();
108
107
 
109
108
  const anvilTest = makeAnvilTest({
@@ -140,6 +139,11 @@ async function setupContracts({
140
139
  };
141
140
  }
142
141
 
142
+ const zoraSepoliaAnvilTest = makeAnvilTest({
143
+ forkUrl: forkUrls.zoraSepolia,
144
+ forkBlockNumber: 1905837,
145
+ });
146
+
143
147
  describe("ZoraCreator1155Preminter", () => {
144
148
  // skip for now - we need to make this work on zora testnet chain too
145
149
  anvilTest(
@@ -186,7 +190,7 @@ describe("ZoraCreator1155Preminter", () => {
186
190
  },
187
191
  20 * 1000,
188
192
  );
189
- anvilTest(
193
+ zoraSepoliaAnvilTest(
190
194
  "can sign and recover a v1 premint config signature",
191
195
  async ({ viemClients }) => {
192
196
  const {
@@ -239,10 +243,7 @@ describe("ZoraCreator1155Preminter", () => {
239
243
 
240
244
  20 * 1000,
241
245
  );
242
- makeAnvilTest({
243
- forkUrl: forkUrls.zoraSepolia,
244
- forkBlockNumber: 1262991,
245
- })(
246
+ zoraSepoliaAnvilTest(
246
247
  "can sign and recover a v2 premint config signature",
247
248
  async ({ viemClients }) => {
248
249
  const {
@@ -296,7 +297,7 @@ describe("ZoraCreator1155Preminter", () => {
296
297
 
297
298
  20 * 1000,
298
299
  );
299
- anvilTest(
300
+ zoraSepoliaAnvilTest(
300
301
  "can sign and mint multiple tokens",
301
302
  async ({ viemClients }) => {
302
303
  const {
@@ -337,9 +338,14 @@ describe("ZoraCreator1155Preminter", () => {
337
338
 
338
339
  const quantityToMint = 2n;
339
340
 
340
- const valueToSend =
341
- (ZORA_MINT_FEE + premintConfig1.tokenConfig.pricePerToken) *
342
- quantityToMint;
341
+ const valueToSend = (
342
+ await getPremintMintCosts({
343
+ publicClient: viemClients.publicClient,
344
+ quantityToMint,
345
+ tokenContract: contractAddress,
346
+ tokenPrice: premintConfig1.tokenConfig.pricePerToken,
347
+ })
348
+ ).totalCost;
343
349
 
344
350
  await viemClients.testClient.setBalance({
345
351
  address: collectorAccount,
@@ -361,7 +367,7 @@ describe("ZoraCreator1155Preminter", () => {
361
367
  const mintArguments: MintArguments = {
362
368
  mintComment: "",
363
369
  mintRecipient: collectorAccount,
364
- mintReferral: collectorAccount,
370
+ mintRewardsRecipients: [],
365
371
  };
366
372
 
367
373
  // now have the collector execute the first signed message;
@@ -433,9 +439,14 @@ describe("ZoraCreator1155Preminter", () => {
433
439
 
434
440
  const quantityToMint2 = 4n;
435
441
 
436
- const valueToSend2 =
437
- (ZORA_MINT_FEE + premintConfig2.tokenConfig.pricePerToken) *
438
- quantityToMint2;
442
+ const valueToSend2 = (
443
+ await getPremintMintCosts({
444
+ publicClient: viemClients.publicClient,
445
+ quantityToMint: quantityToMint2,
446
+ tokenContract: contractAddress,
447
+ tokenPrice: premintConfig2.tokenConfig.pricePerToken,
448
+ })
449
+ ).totalCost;
439
450
 
440
451
  const simulationResult = await viemClients.publicClient.simulateContract({
441
452
  abi: preminterAbi,
@@ -490,7 +501,7 @@ describe("ZoraCreator1155Preminter", () => {
490
501
  40 * 1000,
491
502
  );
492
503
 
493
- anvilTest(
504
+ zoraSepoliaAnvilTest(
494
505
  "can decode the CreatorAttribution event",
495
506
  async ({ viemClients }) => {
496
507
  const {
@@ -532,9 +543,14 @@ describe("ZoraCreator1155Preminter", () => {
532
543
 
533
544
  const quantityToMint = 2n;
534
545
 
535
- const valueToSend =
536
- (ZORA_MINT_FEE + premintConfig.tokenConfig.pricePerToken) *
537
- quantityToMint;
546
+ const valueToSend = (
547
+ await getPremintMintCosts({
548
+ publicClient: viemClients.publicClient,
549
+ quantityToMint,
550
+ tokenContract: contractAddress,
551
+ tokenPrice: premintConfig.tokenConfig.pricePerToken,
552
+ })
553
+ ).totalCost;
538
554
 
539
555
  await viemClients.testClient.setBalance({
540
556
  address: collectorAccount,
@@ -560,7 +576,7 @@ describe("ZoraCreator1155Preminter", () => {
560
576
  {
561
577
  mintComment: "",
562
578
  mintRecipient: collectorAccount,
563
- mintReferral: zeroAddress,
579
+ mintRewardsRecipients: [],
564
580
  },
565
581
  ],
566
582
  value: valueToSend,
@@ -16,6 +16,7 @@ import {
16
16
  concat,
17
17
  recoverAddress,
18
18
  GetEventArgs,
19
+ parseEther,
19
20
  } from "viem";
20
21
  import {
21
22
  ContractCreationConfig,
@@ -30,6 +31,7 @@ import {
30
31
  v1Types,
31
32
  v2Types,
32
33
  } from "./contract-types";
34
+ import { MintCosts } from "src/mint/mint-client";
33
35
 
34
36
  export const getPremintExecutorAddress = () =>
35
37
  zoraCreator1155PremintExecutorImplAddress[999];
@@ -393,3 +395,56 @@ export function makeNewPremint<T extends TokenCreationConfig>({
393
395
  tokenConfig,
394
396
  } as PremintConfigForTokenCreationConfig<T>;
395
397
  }
398
+
399
+ export async function getPremintMintFee({
400
+ tokenContract,
401
+ publicClient,
402
+ }: {
403
+ tokenContract: Address;
404
+ publicClient: PublicClient;
405
+ }) {
406
+ // try reading mint fee function from premint executor. this will revert
407
+ // if the abi is not up to date yet
408
+ try {
409
+ return await publicClient.readContract({
410
+ address: getPremintExecutorAddress(),
411
+ abi: zoraCreator1155PremintExecutorImplABI,
412
+ functionName: "mintFee",
413
+ args: [tokenContract],
414
+ });
415
+ } catch (e) {
416
+ console.error(e);
417
+
418
+ return parseEther("0.000777");
419
+ }
420
+ }
421
+
422
+ export async function getPremintMintCosts({
423
+ publicClient,
424
+ tokenContract,
425
+ tokenPrice,
426
+ quantityToMint,
427
+ }: {
428
+ tokenContract: Address;
429
+ tokenPrice: bigint;
430
+ quantityToMint: bigint;
431
+ publicClient: PublicClient;
432
+ }): Promise<MintCosts> {
433
+ const mintFee = await getPremintMintFee({ tokenContract, publicClient });
434
+
435
+ return {
436
+ mintFee: mintFee * quantityToMint,
437
+ tokenPurchaseCost: tokenPrice * quantityToMint,
438
+ totalCost: (mintFee + tokenPrice) * quantityToMint,
439
+ };
440
+ }
441
+
442
+ export function makeMintRewardsRecipient({
443
+ mintReferral = zeroAddress,
444
+ platformReferral = zeroAddress,
445
+ }: {
446
+ mintReferral?: Address;
447
+ platformReferral?: Address;
448
+ }): Address[] {
449
+ return [mintReferral, platformReferral];
450
+ }