@zoralabs/protocol-sdk 0.4.0 → 0.4.2

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/dist/index.cjs CHANGED
@@ -38,10 +38,13 @@ __export(src_exports, {
38
38
  getMintCosts: () => getMintCosts,
39
39
  getPremintCollectionAddress: () => getPremintCollectionAddress,
40
40
  getPremintExecutorAddress: () => getPremintExecutorAddress,
41
+ getPremintMintCosts: () => getPremintMintCosts,
42
+ getPremintMintFee: () => getPremintMintFee,
41
43
  getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
42
44
  getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
43
45
  isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
44
46
  isValidSignature: () => isValidSignature,
47
+ makeMintRewardsRecipient: () => makeMintRewardsRecipient,
45
48
  makeNewPremint: () => makeNewPremint,
46
49
  markPremintDeleted: () => markPremintDeleted,
47
50
  migratePremintConfigToV2: () => migratePremintConfigToV2,
@@ -287,17 +290,12 @@ var supportedPremintVersions = async ({
287
290
  tokenContract,
288
291
  publicClient
289
292
  }) => {
290
- try {
291
- return await publicClient.readContract({
292
- abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
293
- address: getPremintExecutorAddress(),
294
- functionName: "supportedPremintSignatureVersions",
295
- args: [tokenContract]
296
- });
297
- } catch (e) {
298
- console.error(e);
299
- return ["1"];
300
- }
293
+ return await publicClient.readContract({
294
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
295
+ address: getPremintExecutorAddress(),
296
+ functionName: "supportedPremintSignatureVersions",
297
+ args: [tokenContract]
298
+ });
301
299
  };
302
300
  var supportsPremintVersion = async ({
303
301
  version,
@@ -353,6 +351,41 @@ function makeNewPremint({
353
351
  tokenConfig
354
352
  };
355
353
  }
354
+ async function getPremintMintFee({
355
+ tokenContract,
356
+ publicClient
357
+ }) {
358
+ try {
359
+ return await publicClient.readContract({
360
+ address: getPremintExecutorAddress(),
361
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
362
+ functionName: "mintFee",
363
+ args: [tokenContract]
364
+ });
365
+ } catch (e) {
366
+ console.error(e);
367
+ return (0, import_viem.parseEther)("0.000777");
368
+ }
369
+ }
370
+ async function getPremintMintCosts({
371
+ publicClient,
372
+ tokenContract,
373
+ tokenPrice,
374
+ quantityToMint
375
+ }) {
376
+ const mintFee = await getPremintMintFee({ tokenContract, publicClient });
377
+ return {
378
+ mintFee: mintFee * quantityToMint,
379
+ tokenPurchaseCost: tokenPrice * quantityToMint,
380
+ totalCost: (mintFee + tokenPrice) * quantityToMint
381
+ };
382
+ }
383
+ function makeMintRewardsRecipient({
384
+ mintReferral = import_viem.zeroAddress,
385
+ platformReferral = import_viem.zeroAddress
386
+ }) {
387
+ return [mintReferral, platformReferral];
388
+ }
356
389
 
357
390
  // src/apis/http-api-base.ts
358
391
  var BadResponseError = class extends Error {
@@ -593,55 +626,55 @@ var MintAPIClient = class {
593
626
  }
594
627
  };
595
628
 
596
- // src/premint/premint-api-client.ts
597
- var postSignature = async ({
598
- httpClient: { post: post2, retries: retries2 } = httpClient,
599
- ...data
600
- }) => retries2(
601
- () => post2(`${ZORA_API_BASE}premint/signature`, data)
602
- );
603
- var getNextUID = async ({
604
- chain_name,
605
- collection_address,
606
- httpClient: { retries: retries2, get: get2 } = httpClient
607
- }) => retries2(
608
- () => get2(
609
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
610
- )
611
- );
612
- var getSignature = async ({
613
- collection_address,
614
- uid,
615
- chain_name,
616
- httpClient: { retries: retries2, get: get2 } = httpClient
617
- }) => {
618
- const result = await retries2(
619
- () => get2(
620
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
621
- )
622
- );
623
- return {
624
- ...result,
625
- // for now - we stub the backend api to simulate returning v1
626
- premint_config_version: "1" /* V1 */
627
- };
628
- };
629
- var convertCollection = (collection) => ({
629
+ // src/premint/conversions.ts
630
+ var convertCollectionFromApi = (collection) => ({
630
631
  ...collection,
631
632
  contractAdmin: collection.contractAdmin
632
633
  });
633
- var convertPremintV1 = (premint) => ({
634
- ...premint,
635
- tokenConfig: {
636
- ...premint.tokenConfig,
637
- fixedPriceMinter: premint.tokenConfig.fixedPriceMinter,
638
- royaltyRecipient: premint.tokenConfig.royaltyRecipient,
639
- maxSupply: BigInt(premint.tokenConfig.maxSupply),
640
- pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
641
- mintStart: BigInt(premint.tokenConfig.mintStart),
642
- mintDuration: BigInt(premint.tokenConfig.mintDuration),
643
- maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
634
+ var convertPremintFromApi = (premint) => {
635
+ if (premint.config_version === "1" /* V1 */ || !premint.config_version) {
636
+ const tokenConfig = premint.tokenConfig;
637
+ return {
638
+ premintConfigVersion: "1" /* V1 */,
639
+ premintConfig: {
640
+ ...premint,
641
+ tokenConfig: {
642
+ ...tokenConfig,
643
+ fixedPriceMinter: tokenConfig.fixedPriceMinter,
644
+ royaltyRecipient: tokenConfig.royaltyRecipient,
645
+ maxSupply: BigInt(tokenConfig.maxSupply),
646
+ pricePerToken: BigInt(tokenConfig.pricePerToken),
647
+ mintStart: BigInt(tokenConfig.mintStart),
648
+ mintDuration: BigInt(tokenConfig.mintDuration),
649
+ maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
650
+ }
651
+ }
652
+ };
653
+ } else {
654
+ const tokenConfig = premint.tokenConfig;
655
+ return {
656
+ premintConfigVersion: "2" /* V2 */,
657
+ premintConfig: {
658
+ ...premint,
659
+ tokenConfig: {
660
+ ...tokenConfig,
661
+ fixedPriceMinter: tokenConfig.fixedPriceMinter,
662
+ payoutRecipient: tokenConfig.payoutRecipient,
663
+ createReferral: tokenConfig.createReferral,
664
+ maxSupply: BigInt(tokenConfig.maxSupply),
665
+ pricePerToken: BigInt(tokenConfig.pricePerToken),
666
+ mintStart: BigInt(tokenConfig.mintStart),
667
+ mintDuration: BigInt(tokenConfig.mintDuration),
668
+ maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
669
+ }
670
+ }
671
+ };
644
672
  }
673
+ };
674
+ var convertGetPremintApiResponse = (response) => ({
675
+ ...convertPremintFromApi(response.premint),
676
+ collection: convertCollectionFromApi(response.collection),
677
+ signature: response.signature
645
678
  });
646
679
  var encodePremintV1ForAPI = ({
647
680
  tokenConfig,
@@ -683,31 +716,68 @@ var encodePremintForAPI = ({
683
716
  }
684
717
  throw new Error(`Invalid premint config version ${premintConfigVersion}`);
685
718
  };
719
+ var encodePostSignatureInput = ({
720
+ collection,
721
+ premintConfigVersion,
722
+ premintConfig,
723
+ signature,
724
+ chainId
725
+ }) => ({
726
+ premint: encodePremintForAPI({
727
+ premintConfig,
728
+ premintConfigVersion
729
+ }),
730
+ signature,
731
+ collection,
732
+ chain_name: networkConfigByChain[chainId].zoraBackendChainName
733
+ });
734
+
735
+ // src/premint/premint-api-client.ts
736
+ var postSignature = async ({
737
+ httpClient: { post: post2, retries: retries2 } = httpClient,
738
+ ...data
739
+ }) => retries2(
740
+ () => post2(`${ZORA_API_BASE}premint/signature`, data)
741
+ );
742
+ var getNextUID = async ({
743
+ chain_name,
744
+ collection_address,
745
+ httpClient: { retries: retries2, get: get2 } = httpClient
746
+ }) => retries2(
747
+ () => get2(
748
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
749
+ )
750
+ );
751
+ var getSignature = async ({
752
+ collection_address,
753
+ uid,
754
+ chain_name,
755
+ httpClient: { retries: retries2, get: get2 } = httpClient
756
+ }) => {
757
+ const result = await retries2(
758
+ () => get2(
759
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
760
+ )
761
+ );
762
+ return result;
763
+ };
686
764
  var PremintAPIClient = class {
687
765
  constructor(chainId, httpClient2) {
688
766
  this.postSignature = async ({
689
767
  collection,
690
- premintConfigVersion,
691
- premintConfig,
692
- signature
768
+ signature,
769
+ ...premintConfigAndVersion
693
770
  }) => {
694
- if (premintConfigVersion === "1" /* V1 */) {
695
- const data = {
696
- premint: encodePremintForAPI({
697
- premintConfig,
698
- premintConfigVersion
699
- }),
700
- signature,
701
- collection
702
- };
703
- return postSignature({
704
- ...data,
705
- chain_name: this.networkConfig.zoraBackendChainName,
706
- httpClient: this.httpClient
707
- });
708
- } else {
709
- throw new Error("Unsupported premint config version");
710
- }
771
+ const data = encodePostSignatureInput({
772
+ collection,
773
+ ...premintConfigAndVersion,
774
+ chainId: this.networkConfig.chainId,
775
+ signature
776
+ });
777
+ return postSignature({
778
+ ...data,
779
+ httpClient: this.httpClient
780
+ });
711
781
  };
712
782
  this.getNextUID = async (collectionAddress) => (await getNextUID({
713
783
  collection_address: collectionAddress.toLowerCase(),
@@ -724,21 +794,7 @@ var PremintAPIClient = class {
724
794
  chain_name: this.networkConfig.zoraBackendChainName,
725
795
  httpClient: this.httpClient
726
796
  });
727
- const premintConfigVersion = response.premint_config_version || "1" /* V1 */;
728
- let premintConfig;
729
- if (premintConfigVersion === "1" /* V1 */) {
730
- premintConfig = convertPremintV1(response.premint);
731
- } else {
732
- throw new Error(
733
- `Unsupported premint config version: ${premintConfigVersion}`
734
- );
735
- }
736
- return {
737
- signature: response.signature,
738
- collection: convertCollection(response.collection),
739
- premintConfig,
740
- premintConfigVersion
741
- };
797
+ return convertGetPremintApiResponse(response);
742
798
  };
743
799
  this.httpClient = httpClient2 || httpClient;
744
800
  this.networkConfig = getApiNetworkConfigForChain(chainId);
@@ -797,10 +853,10 @@ function getPremintedLogFromReceipt(receipt) {
797
853
  try {
798
854
  const decodedLog = (0, import_viem4.decodeEventLog)({
799
855
  abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
800
- eventName: "Preminted",
856
+ eventName: "PremintedV2",
801
857
  ...data
802
858
  });
803
- if (decodedLog.eventName === "Preminted") {
859
+ if (decodedLog.eventName === "PremintedV2") {
804
860
  return decodedLog.args;
805
861
  }
806
862
  } catch (err) {
@@ -918,7 +974,7 @@ var PremintClient = class {
918
974
  * @returns
919
975
  */
920
976
  async signAndSubmitPremint(params) {
921
- const { premint, verifyingContract } = await signAndSubmitPremint({
977
+ const { verifyingContract } = await signAndSubmitPremint({
922
978
  ...params,
923
979
  chainId: this.chain.id,
924
980
  apiClient: this.apiClient,
@@ -928,8 +984,7 @@ var PremintClient = class {
928
984
  return {
929
985
  urls: this.makeUrls({ address: verifyingContract, uid }),
930
986
  uid,
931
- verifyingContract,
932
- premint
987
+ verifyingContract
933
988
  };
934
989
  }
935
990
  /**
@@ -1050,6 +1105,18 @@ var PremintClient = class {
1050
1105
  chain: this.chain
1051
1106
  });
1052
1107
  }
1108
+ async getMintCosts({
1109
+ tokenContract,
1110
+ quantityToMint,
1111
+ tokenCreationConfig
1112
+ }) {
1113
+ return await getPremintMintCosts({
1114
+ publicClient: this.publicClient,
1115
+ quantityToMint,
1116
+ tokenContract,
1117
+ tokenPrice: tokenCreationConfig.pricePerToken
1118
+ });
1119
+ }
1053
1120
  /**
1054
1121
  * Execute premint on-chain
1055
1122
  *
@@ -1079,12 +1146,25 @@ var PremintClient = class {
1079
1146
  uid
1080
1147
  });
1081
1148
  const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1082
- const value = numberToMint * REWARD_PER_TOKEN;
1149
+ const value = (await getPremintMintCosts({
1150
+ tokenContract,
1151
+ quantityToMint: numberToMint,
1152
+ publicClient: this.publicClient,
1153
+ tokenPrice: premintConfig.tokenConfig.pricePerToken
1154
+ })).totalCost;
1155
+ const mintArgumentsContract = {
1156
+ mintComment: mintArguments?.mintComment || "",
1157
+ mintRecipient: mintArguments?.mintRecipient || (typeof account === "string" ? account : account.address),
1158
+ mintRewardsRecipients: makeMintRewardsRecipient({
1159
+ mintReferral: mintArguments?.mintReferral,
1160
+ platformReferral: mintArguments?.platformReferral
1161
+ })
1162
+ };
1083
1163
  if (premintConfigVersion === "1" /* V1 */) {
1084
1164
  return {
1085
1165
  account,
1086
1166
  abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1087
- functionName: "premint",
1167
+ functionName: "premintV1",
1088
1168
  value,
1089
1169
  address: getPremintExecutorAddress(),
1090
1170
  args: [
@@ -1092,12 +1172,11 @@ var PremintClient = class {
1092
1172
  premintConfig,
1093
1173
  signature,
1094
1174
  numberToMint,
1095
- mintArguments?.mintComment || ""
1175
+ mintArgumentsContract
1096
1176
  ]
1097
1177
  };
1098
1178
  } else if (premintConfigVersion === "2" /* V2 */) {
1099
1179
  const toPost = premintConfig;
1100
- const accountAddress = typeof account === "string" ? account : account.address;
1101
1180
  return {
1102
1181
  account,
1103
1182
  abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
@@ -1110,11 +1189,7 @@ var PremintClient = class {
1110
1189
  toPost,
1111
1190
  signature,
1112
1191
  numberToMint,
1113
- {
1114
- mintComment: mintArguments?.mintComment || "",
1115
- mintRecipient: mintArguments?.mintRecipient || accountAddress,
1116
- mintReferral: mintArguments?.mintReferral || import_viem4.zeroAddress
1117
- }
1192
+ mintArgumentsContract
1118
1193
  ]
1119
1194
  };
1120
1195
  }
@@ -1598,10 +1673,13 @@ function create1155CreatorClient({
1598
1673
  getMintCosts,
1599
1674
  getPremintCollectionAddress,
1600
1675
  getPremintExecutorAddress,
1676
+ getPremintMintCosts,
1677
+ getPremintMintFee,
1601
1678
  getPremintedLogFromReceipt,
1602
1679
  getTokenIdFromCreateReceipt,
1603
1680
  isAuthorizedToCreatePremint,
1604
1681
  isValidSignature,
1682
+ makeMintRewardsRecipient,
1605
1683
  makeNewPremint,
1606
1684
  markPremintDeleted,
1607
1685
  migratePremintConfigToV2,