@zoralabs/protocol-sdk 0.3.2 → 0.3.3

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/premint/premint-client.ts
2
- import { decodeEventLog } from "viem";
2
+ import { createPublicClient, decodeEventLog, http } from "viem";
3
3
  import {
4
4
  zoraCreator1155PremintExecutorImplABI,
5
5
  zoraCreator1155PremintExecutorImplAddress,
@@ -124,6 +124,11 @@ var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
124
124
  throw err;
125
125
  }
126
126
  };
127
+ var httpClient = {
128
+ get,
129
+ post,
130
+ retries
131
+ };
127
132
 
128
133
  // src/constants.ts
129
134
  var ZORA_API_BASE = "https://api.zora.co/";
@@ -133,29 +138,6 @@ function getSubgraph(name, version) {
133
138
  return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
134
139
  }
135
140
 
136
- // src/premint/premint-api-client.ts
137
- var postSignature = async (data) => retries(
138
- () => post(`${ZORA_API_BASE}premint/signature`, data)
139
- );
140
- var getNextUID = async (path) => retries(
141
- () => get(
142
- `${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`
143
- )
144
- );
145
- var getSignature = async (path) => retries(
146
- () => get(
147
- `${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`
148
- )
149
- );
150
- var PremintAPIClient = {
151
- postSignature,
152
- getSignature,
153
- getNextUID
154
- };
155
-
156
- // src/apis/client-base.ts
157
- import { createPublicClient, http } from "viem";
158
-
159
141
  // src/apis/chain-constants.ts
160
142
  import {
161
143
  base,
@@ -246,27 +228,107 @@ var networkConfigByChain = {
246
228
  }
247
229
  };
248
230
 
249
- // src/apis/client-base.ts
250
- var ClientBase = class {
251
- constructor(chain) {
252
- this.chain = chain;
253
- const networkConfig = networkConfigByChain[chain.id];
254
- if (!networkConfig) {
255
- throw new Error(`Not configured for chain ${chain.id}`);
256
- }
257
- this.network = networkConfig;
231
+ // src/mint/mint-api-client.ts
232
+ function encodeQueryParameters(params) {
233
+ return new URLSearchParams(params).toString();
234
+ }
235
+ var getApiNetworkConfigForChain = (chainId) => {
236
+ if (!networkConfigByChain[chainId]) {
237
+ throw new Error(`chain id ${chainId} network not configured `);
258
238
  }
259
- /**
260
- * Getter for public client that instantiates a publicClient as needed
261
- *
262
- * @param publicClient Optional viem public client
263
- * @returns Existing public client or makes a new one for the given chain as needed.
264
- */
265
- getPublicClient(publicClient) {
266
- if (publicClient) {
267
- return publicClient;
268
- }
269
- return createPublicClient({ chain: this.chain, transport: http() });
239
+ return networkConfigByChain[chainId];
240
+ };
241
+ var MintAPIClient = class {
242
+ constructor(chainId, httpClient2) {
243
+ this.httpClient = httpClient2 || httpClient;
244
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
245
+ }
246
+ async getMintable(path, query) {
247
+ const httpClient2 = this.httpClient;
248
+ return httpClient2.retries(() => {
249
+ return httpClient2.get(
250
+ `${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
251
+ );
252
+ });
253
+ }
254
+ async getSalesConfigFixedPrice({
255
+ contractAddress,
256
+ tokenId
257
+ }) {
258
+ const { retries: retries2, post: post2 } = this.httpClient;
259
+ return retries2(async () => {
260
+ const response = await post2(this.networkConfig.subgraphUrl, {
261
+ query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
262
+ variables: {
263
+ id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`
264
+ }
265
+ });
266
+ return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
267
+ });
268
+ }
269
+ async getMintableForToken({
270
+ tokenContract,
271
+ tokenId
272
+ }) {
273
+ return await this.getMintable(
274
+ {
275
+ chain_name: this.networkConfig.zoraBackendChainName,
276
+ collection_address: tokenContract
277
+ },
278
+ { token_id: tokenId?.toString() }
279
+ );
280
+ }
281
+ };
282
+
283
+ // src/premint/premint-api-client.ts
284
+ var postSignature = async ({
285
+ httpClient: { post: post2, retries: retries2 } = httpClient,
286
+ ...data
287
+ }) => retries2(
288
+ () => post2(`${ZORA_API_BASE}premint/signature`, data)
289
+ );
290
+ var getNextUID = async ({
291
+ chain_name,
292
+ collection_address,
293
+ httpClient: { retries: retries2, get: get2 } = httpClient
294
+ }) => retries2(
295
+ () => get2(
296
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
297
+ )
298
+ );
299
+ var getSignature = async ({
300
+ collection_address,
301
+ uid,
302
+ chain_name,
303
+ httpClient: { retries: retries2, get: get2 } = httpClient
304
+ }) => retries2(
305
+ () => get2(
306
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
307
+ )
308
+ );
309
+ var PremintAPIClient = class {
310
+ constructor(chainId, httpClient2) {
311
+ this.postSignature = async (data) => postSignature({
312
+ ...data,
313
+ chain_name: this.networkConfig.zoraBackendChainName,
314
+ httpClient: this.httpClient
315
+ });
316
+ this.getNextUID = async (path) => getNextUID({
317
+ ...path,
318
+ chain_name: this.networkConfig.zoraBackendChainName,
319
+ httpClient: this.httpClient
320
+ });
321
+ this.getSignature = async ({
322
+ collection_address,
323
+ uid
324
+ }) => getSignature({
325
+ collection_address,
326
+ uid,
327
+ chain_name: this.networkConfig.zoraBackendChainName,
328
+ httpClient: this.httpClient
329
+ });
330
+ this.httpClient = httpClient2 || httpClient;
331
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
270
332
  }
271
333
  };
272
334
 
@@ -328,13 +390,11 @@ var encodePremintForAPI = ({
328
390
  maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
329
391
  }
330
392
  });
331
- var PremintClient = class extends ClientBase {
332
- constructor(chain, apiClient) {
333
- super(chain);
334
- if (!apiClient) {
335
- apiClient = PremintAPIClient;
336
- }
337
- this.apiClient = apiClient;
393
+ var PremintClient = class {
394
+ constructor(chain, publicClient, httpClient2) {
395
+ this.chain = chain;
396
+ this.apiClient = new PremintAPIClient(chain.id, httpClient2);
397
+ this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
338
398
  }
339
399
  /**
340
400
  * The premint executor address is deployed to the same address across all chains.
@@ -391,7 +451,6 @@ var PremintClient = class extends ClientBase {
391
451
  account
392
452
  }) {
393
453
  const signatureResponse = await this.apiClient.getSignature({
394
- chain_name: this.network.zoraBackendChainName,
395
454
  collection_address: collection.toLowerCase(),
396
455
  uid
397
456
  });
@@ -411,7 +470,6 @@ var PremintClient = class extends ClientBase {
411
470
  account,
412
471
  checkSignature: false,
413
472
  verifyingContract: collection,
414
- publicClient: this.getPublicClient(),
415
473
  uid,
416
474
  collection: {
417
475
  ...signerData.collection,
@@ -438,11 +496,9 @@ var PremintClient = class extends ClientBase {
438
496
  walletClient,
439
497
  uid,
440
498
  account,
441
- collection,
442
- publicClient
499
+ collection
443
500
  }) {
444
501
  const signatureResponse = await this.apiClient.getSignature({
445
- chain_name: this.network.zoraBackendChainName,
446
502
  collection_address: collection.toLowerCase(),
447
503
  uid
448
504
  });
@@ -459,7 +515,6 @@ var PremintClient = class extends ClientBase {
459
515
  account,
460
516
  checkSignature: false,
461
517
  verifyingContract: collection,
462
- publicClient: this.getPublicClient(publicClient),
463
518
  uid,
464
519
  collection: signerData.collection,
465
520
  premintConfig: signerData.premint
@@ -473,7 +528,6 @@ var PremintClient = class extends ClientBase {
473
528
  */
474
529
  async signAndSubmitPremint({
475
530
  walletClient,
476
- publicClient,
477
531
  verifyingContract,
478
532
  premintConfig,
479
533
  uid,
@@ -496,7 +550,7 @@ var PremintClient = class extends ClientBase {
496
550
  })
497
551
  });
498
552
  if (checkSignature) {
499
- const [isValidSignature] = await publicClient.readContract({
553
+ const [isValidSignature] = await this.publicClient.readContract({
500
554
  abi: zoraCreator1155PremintExecutorImplABI,
501
555
  address: this.getExecutorAddress(),
502
556
  functionName: "isValidSignature",
@@ -509,7 +563,6 @@ var PremintClient = class extends ClientBase {
509
563
  const apiData = {
510
564
  collection,
511
565
  premint: encodePremintForAPI(premintConfig),
512
- chain_name: this.network.zoraBackendChainName,
513
566
  signature
514
567
  };
515
568
  const premint = await this.apiClient.postSignature(apiData);
@@ -539,13 +592,11 @@ var PremintClient = class extends ClientBase {
539
592
  account,
540
593
  collection,
541
594
  token,
542
- publicClient,
543
595
  walletClient,
544
596
  executionSettings,
545
597
  checkSignature = false
546
598
  }) {
547
- publicClient = this.getPublicClient(publicClient);
548
- const newContractAddress = await publicClient.readContract({
599
+ const newContractAddress = await this.publicClient.readContract({
549
600
  address: this.getExecutorAddress(),
550
601
  abi: zoraCreator1155PremintExecutorImplABI,
551
602
  functionName: "getContractAddress",
@@ -560,7 +611,6 @@ var PremintClient = class extends ClientBase {
560
611
  let uid = executionSettings?.uid;
561
612
  if (!uid) {
562
613
  const uidResponse = await this.apiClient.getNextUID({
563
- chain_name: this.network.zoraBackendChainName,
564
614
  collection_address: newContractAddress.toLowerCase()
565
615
  });
566
616
  uid = uidResponse.next_uid;
@@ -581,7 +631,6 @@ var PremintClient = class extends ClientBase {
581
631
  premintConfig,
582
632
  checkSignature,
583
633
  account,
584
- publicClient,
585
634
  walletClient,
586
635
  collection
587
636
  });
@@ -598,7 +647,6 @@ var PremintClient = class extends ClientBase {
598
647
  uid
599
648
  }) {
600
649
  return await this.apiClient.getSignature({
601
- chain_name: this.network.zoraBackendChainName,
602
650
  collection_address: address,
603
651
  uid
604
652
  });
@@ -610,11 +658,9 @@ var PremintClient = class extends ClientBase {
610
658
  * @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
611
659
  */
612
660
  async isValidSignature({
613
- data,
614
- publicClient
661
+ data
615
662
  }) {
616
- publicClient = this.getPublicClient(publicClient);
617
- const [isValid, contractAddress, recoveredSigner] = await publicClient.readContract({
663
+ const [isValid, contractAddress, recoveredSigner] = await this.publicClient.readContract({
618
664
  abi: zoraCreator1155PremintExecutorImplABI,
619
665
  address: this.getExecutorAddress(),
620
666
  functionName: "isValidSignature",
@@ -635,10 +681,11 @@ var PremintClient = class extends ClientBase {
635
681
  return { explorer: null, zoraCollect: null, zoraManage: null };
636
682
  }
637
683
  const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
684
+ const network = getApiNetworkConfigForChain(this.chain.id);
638
685
  return {
639
686
  explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
640
- zoraCollect: `https://${this.network.isTestnet ? "testnet." : ""}zora.co/collect/${this.network.zoraPathChainName}:${address}/${zoraTokenPath}`,
641
- zoraManage: `https://${this.network.isTestnet ? "testnet." : ""}zora.co/collect/${this.network.zoraPathChainName}:${address}/${zoraTokenPath}`
687
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
688
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
642
689
  };
643
690
  }
644
691
  /**
@@ -653,7 +700,7 @@ var PremintClient = class extends ClientBase {
653
700
  * @param settings.publicClient Optional public client for preflight checks.
654
701
  * @returns receipt, log, zoraURL
655
702
  */
656
- async executePremint({
703
+ async makeMintParameters({
657
704
  data,
658
705
  account,
659
706
  mintArguments
@@ -682,49 +729,25 @@ var PremintClient = class extends ClientBase {
682
729
  address: targetAddress,
683
730
  args
684
731
  };
685
- return {
686
- request
687
- };
732
+ return request;
688
733
  }
689
734
  };
690
735
  function createPremintClient({
691
736
  chain,
692
- premintAPIClient
737
+ httpClient: httpClient2,
738
+ publicClient
693
739
  }) {
694
- return new PremintClient(chain, premintAPIClient);
740
+ return new PremintClient(chain, publicClient, httpClient2);
695
741
  }
696
742
 
697
- // src/mint/mint-api-client.ts
698
- function encodeQueryParameters(params) {
699
- return new URLSearchParams(params).toString();
700
- }
701
- var getMintable = async (path, query) => retries(() => {
702
- return get(
703
- `${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
704
- );
705
- });
706
- var getSalesConfigFixedPrice = async ({
707
- contractAddress,
708
- tokenId,
709
- subgraphUrl
710
- }) => retries(async () => {
711
- const response = await post(subgraphUrl, {
712
- query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
713
- variables: { id: `${contractAddress.toLowerCase()}-${tokenId}` }
714
- });
715
- return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
716
- });
717
- var MintAPIClient = {
718
- getMintable,
719
- getSalesConfigFixedPrice
720
- };
721
-
722
743
  // src/mint/mint-client.ts
723
744
  import {
745
+ createPublicClient as createPublicClient2,
724
746
  encodeAbiParameters,
725
747
  parseAbi,
726
748
  parseAbiParameters,
727
- zeroAddress
749
+ zeroAddress,
750
+ http as http2
728
751
  } from "viem";
729
752
  import {
730
753
  zoraCreator1155ImplABI,
@@ -742,145 +765,245 @@ var zora721Abi = parseAbi([
742
765
  "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
743
766
  "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
744
767
  ]);
745
- var MintClient = class extends ClientBase {
746
- constructor(chain, apiClient) {
747
- super(chain);
748
- if (!apiClient) {
749
- apiClient = MintAPIClient;
750
- }
751
- this.apiClient = apiClient;
768
+ var MintClient = class {
769
+ constructor(chain, publicClient, httpClient2) {
770
+ this.apiClient = new MintAPIClient(chain.id, httpClient2);
771
+ this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
752
772
  }
773
+ /**
774
+ * Gets mintable information for a given token
775
+ * @param param0.tokenContract The contract address of the token to mint.
776
+ * @param param0.tokenId The token id to mint.
777
+ * @returns
778
+ */
753
779
  async getMintable({
754
780
  tokenContract,
755
781
  tokenId
756
782
  }) {
757
- return this.apiClient.getMintable(
758
- {
759
- chain_name: this.network.zoraBackendChainName,
760
- collection_address: tokenContract
761
- },
762
- { token_id: tokenId?.toString() }
763
- );
783
+ return await this.apiClient.getMintableForToken({
784
+ tokenContract,
785
+ tokenId: tokenId?.toString()
786
+ });
764
787
  }
788
+ /**
789
+ * Returns the parameters needed to prepare a transaction mint a token.
790
+ * @param param0.minterAccount The account that will mint the token.
791
+ * @param param0.mintable The mintable token to mint.
792
+ * @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
793
+ * @returns
794
+ */
765
795
  async makePrepareMintTokenParams({
766
- publicClient,
767
- minterAccount,
796
+ ...rest
797
+ }) {
798
+ return makePrepareMintTokenParams({
799
+ ...rest,
800
+ apiClient: this.apiClient,
801
+ publicClient: this.publicClient
802
+ });
803
+ }
804
+ /**
805
+ * Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
806
+ * @param param0.mintable The mintable token to mint.
807
+ * @param param0.quantityToMint The quantity of tokens to mint.
808
+ * @returns
809
+ */
810
+ async getMintCosts({
768
811
  mintable,
769
- mintArguments
812
+ quantityToMint
770
813
  }) {
771
- if (!mintable) {
772
- throw new MintError("No mintable found");
773
- }
774
- if (!mintable.is_active) {
775
- throw new MintInactiveError("Minting token is inactive");
776
- }
777
- if (!mintable.mint_context) {
778
- throw new MintError("No minting context data from zora API");
779
- }
780
- if (!["zora_create", "zora_create_1155"].includes(
781
- mintable.mint_context?.mint_context_type
782
- )) {
783
- throw new MintError(
784
- `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
785
- );
786
- }
787
- const thisPublicClient = this.getPublicClient(publicClient);
788
- if (mintable.mint_context.mint_context_type === "zora_create_1155") {
789
- return {
790
- simulateContractParameters: await this.prepareMintZora1155({
791
- publicClient: thisPublicClient,
792
- mintArguments,
793
- sender: minterAccount,
794
- mintable
795
- })
796
- };
814
+ const mintContextType = validateMintableAndGetContextType(mintable);
815
+ if (mintContextType === "zora_create_1155") {
816
+ return await get1155MintCosts({
817
+ mintable,
818
+ publicClient: this.publicClient,
819
+ quantityToMint: BigInt(quantityToMint)
820
+ });
797
821
  }
798
- if (mintable.mint_context.mint_context_type === "zora_create") {
799
- return {
800
- simulateContractParameters: await this.prepareMintZora721({
801
- publicClient: thisPublicClient,
802
- mintArguments,
803
- sender: minterAccount,
804
- mintable
805
- })
806
- };
822
+ if (mintContextType === "zora_create") {
823
+ return await get721MintCosts({
824
+ mintable,
825
+ publicClient: this.publicClient,
826
+ quantityToMint: BigInt(quantityToMint)
827
+ });
807
828
  }
808
- throw new Error("Mintable type not found or recognized.");
829
+ throw new MintError(
830
+ `Mintable type ${mintContextType} is currently unsupported.`
831
+ );
809
832
  }
810
- async prepareMintZora1155({
833
+ };
834
+ function createMintClient({
835
+ chain,
836
+ publicClient,
837
+ httpClient: httpClient2
838
+ }) {
839
+ return new MintClient(chain, publicClient, httpClient2);
840
+ }
841
+ function validateMintableAndGetContextType(mintable) {
842
+ if (!mintable) {
843
+ throw new MintError("No mintable found");
844
+ }
845
+ if (!mintable.is_active) {
846
+ throw new MintInactiveError("Minting token is inactive");
847
+ }
848
+ if (!mintable.mint_context) {
849
+ throw new MintError("No minting context data from zora API");
850
+ }
851
+ if (!["zora_create", "zora_create_1155"].includes(
852
+ mintable.mint_context?.mint_context_type
853
+ )) {
854
+ throw new MintError(
855
+ `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
856
+ );
857
+ }
858
+ return mintable.mint_context.mint_context_type;
859
+ }
860
+ async function makePrepareMintTokenParams({
861
+ publicClient,
862
+ mintable,
863
+ apiClient,
864
+ ...rest
865
+ }) {
866
+ const mintContextType = validateMintableAndGetContextType(mintable);
867
+ const thisPublicClient = publicClient;
868
+ if (mintContextType === "zora_create_1155") {
869
+ return makePrepareMint1155TokenParams({
870
+ apiClient,
871
+ publicClient: thisPublicClient,
872
+ mintable,
873
+ mintContextType,
874
+ ...rest
875
+ });
876
+ }
877
+ if (mintContextType === "zora_create") {
878
+ return makePrepareMint721TokenParams({
879
+ publicClient: thisPublicClient,
880
+ mintable,
881
+ mintContextType,
882
+ ...rest
883
+ });
884
+ }
885
+ throw new MintError(
886
+ `Mintable type ${mintContextType} is currently unsupported.`
887
+ );
888
+ }
889
+ async function get721MintCosts({
890
+ mintable,
891
+ publicClient,
892
+ quantityToMint
893
+ }) {
894
+ const address = mintable.collection.address;
895
+ const [_, mintFee] = await publicClient.readContract({
896
+ abi: zora721Abi,
897
+ address,
898
+ functionName: "zoraFeeForAmount",
899
+ args: [BigInt(quantityToMint)]
900
+ });
901
+ const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
902
+ return {
903
+ mintFee,
904
+ tokenPurchaseCost,
905
+ totalCost: mintFee + tokenPurchaseCost
906
+ };
907
+ }
908
+ async function makePrepareMint721TokenParams({
909
+ publicClient,
910
+ minterAccount,
911
+ mintable,
912
+ mintContextType,
913
+ mintArguments
914
+ }) {
915
+ if (mintContextType !== "zora_create") {
916
+ throw new Error("Minted token type must be for 1155");
917
+ }
918
+ const mintValue = (await get721MintCosts({
811
919
  mintable,
812
- sender,
813
920
  publicClient,
814
- mintArguments
815
- }) {
816
- const mintQuantity = BigInt(mintArguments.quantityToMint);
817
- const address = mintable.collection.address;
818
- const mintFee = await publicClient.readContract({
819
- abi: zoraCreator1155ImplABI,
820
- functionName: "mintFee",
821
- address
822
- });
823
- const tokenFixedPriceMinter = await this.apiClient.getSalesConfigFixedPrice(
824
- {
825
- contractAddress: mintable.contract_address,
826
- tokenId: mintable.token_id,
827
- subgraphUrl: this.network.subgraphUrl
828
- }
829
- );
830
- const result = {
831
- abi: zoraCreator1155ImplABI,
832
- functionName: "mintWithRewards",
833
- account: sender,
834
- value: (mintFee + BigInt(mintable.cost.native_price.raw)) * mintQuantity,
835
- address,
836
- /* args: minter, tokenId, quantity, minterArguments, mintReferral */
837
- args: [
838
- tokenFixedPriceMinter || zoraCreatorFixedPriceSaleStrategyAddress2[999],
839
- BigInt(mintable.token_id),
840
- mintQuantity,
841
- encodeAbiParameters(parseAbiParameters("address, string"), [
842
- mintArguments.mintToAddress,
843
- mintArguments.mintComment || ""
844
- ]),
845
- mintArguments.mintReferral || zeroAddress
846
- ]
847
- };
848
- return result;
921
+ quantityToMint: BigInt(mintArguments.quantityToMint)
922
+ })).totalCost;
923
+ const result = {
924
+ abi: zora721Abi,
925
+ address: mintable.contract_address,
926
+ account: minterAccount,
927
+ functionName: "mintWithRewards",
928
+ value: mintValue,
929
+ args: [
930
+ mintArguments.mintToAddress,
931
+ BigInt(mintArguments.quantityToMint),
932
+ mintArguments.mintComment || "",
933
+ mintArguments.mintReferral || zeroAddress
934
+ ]
935
+ };
936
+ return result;
937
+ }
938
+ async function get1155MintFee({
939
+ collectionAddress,
940
+ publicClient
941
+ }) {
942
+ return await publicClient.readContract({
943
+ abi: zoraCreator1155ImplABI,
944
+ functionName: "mintFee",
945
+ address: collectionAddress
946
+ });
947
+ }
948
+ async function get1155MintCosts({
949
+ mintable,
950
+ publicClient,
951
+ quantityToMint
952
+ }) {
953
+ const address = mintable.collection.address;
954
+ const mintFee = await get1155MintFee({
955
+ collectionAddress: address,
956
+ publicClient
957
+ });
958
+ const mintFeeForTokens = mintFee * quantityToMint;
959
+ const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
960
+ return {
961
+ mintFee: mintFeeForTokens,
962
+ tokenPurchaseCost,
963
+ totalCost: mintFeeForTokens + tokenPurchaseCost
964
+ };
965
+ }
966
+ async function makePrepareMint1155TokenParams({
967
+ apiClient,
968
+ publicClient,
969
+ minterAccount,
970
+ mintable,
971
+ mintContextType,
972
+ mintArguments
973
+ }) {
974
+ if (mintContextType !== "zora_create_1155") {
975
+ throw new Error("Minted token type must be for 1155");
849
976
  }
850
- async prepareMintZora721({
977
+ const mintQuantity = BigInt(mintArguments.quantityToMint);
978
+ const address = mintable.collection.address;
979
+ const mintValue = (await get1155MintCosts({
851
980
  mintable,
852
981
  publicClient,
853
- sender,
854
- mintArguments
855
- }) {
856
- const [_, mintFee] = await publicClient.readContract({
857
- abi: zora721Abi,
858
- address: mintable.contract_address,
859
- functionName: "zoraFeeForAmount",
860
- args: [BigInt(mintArguments.quantityToMint)]
861
- });
862
- const result = {
863
- abi: zora721Abi,
864
- address: mintable.contract_address,
865
- account: sender,
866
- functionName: "mintWithRewards",
867
- value: mintFee + BigInt(mintable.cost.native_price.raw) * BigInt(mintArguments.quantityToMint),
868
- /* args: mint recipient, quantity to mint, mint comment, mintReferral */
869
- args: [
982
+ quantityToMint: mintQuantity
983
+ })).totalCost;
984
+ const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
985
+ contractAddress: address,
986
+ tokenId: BigInt(mintable.token_id)
987
+ });
988
+ const result = {
989
+ abi: zoraCreator1155ImplABI,
990
+ functionName: "mintWithRewards",
991
+ account: minterAccount,
992
+ value: mintValue,
993
+ address,
994
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
995
+ args: [
996
+ tokenFixedPriceMinter || zoraCreatorFixedPriceSaleStrategyAddress2[999],
997
+ BigInt(mintable.token_id),
998
+ mintQuantity,
999
+ encodeAbiParameters(parseAbiParameters("address, string"), [
870
1000
  mintArguments.mintToAddress,
871
- BigInt(mintArguments.quantityToMint),
872
- mintArguments.mintComment || "",
873
- mintArguments.mintReferral || zeroAddress
874
- ]
875
- };
876
- return result;
877
- }
878
- };
879
- function createMintClient({
880
- chain,
881
- mintAPIClient
882
- }) {
883
- return new MintClient(chain, mintAPIClient);
1001
+ mintArguments.mintComment || ""
1002
+ ]),
1003
+ mintArguments.mintReferral || zeroAddress
1004
+ ]
1005
+ };
1006
+ return result;
884
1007
  }
885
1008
 
886
1009
  // src/create/1155-create-helper.ts
@@ -1148,8 +1271,9 @@ export {
1148
1271
  createMintClient,
1149
1272
  createPremintClient,
1150
1273
  encodePremintForAPI,
1274
+ get1155MintCosts,
1275
+ getApiNetworkConfigForChain,
1151
1276
  getPremintedLogFromReceipt,
1152
- getSalesConfigFixedPrice,
1153
1277
  getTokenIdFromCreateReceipt,
1154
1278
  preminterTypedDataDefinition
1155
1279
  };