@zoralabs/protocol-sdk 0.5.17 → 0.6.0

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 (63) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +1 -416
  4. package/dist/create/1155-create-helper.d.ts +16 -55
  5. package/dist/create/1155-create-helper.d.ts.map +1 -1
  6. package/dist/create/contract-setup.d.ts +14 -0
  7. package/dist/create/contract-setup.d.ts.map +1 -0
  8. package/dist/create/token-setup.d.ts +27 -0
  9. package/dist/create/token-setup.d.ts.map +1 -0
  10. package/dist/create/types.d.ts +45 -0
  11. package/dist/create/types.d.ts.map +1 -0
  12. package/dist/index.cjs +1273 -857
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1233 -831
  17. package/dist/index.js.map +1 -1
  18. package/dist/mint/mint-client.d.ts +4083 -43
  19. package/dist/mint/mint-client.d.ts.map +1 -1
  20. package/dist/mint/subgraph-mint-getter.d.ts +17 -0
  21. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
  22. package/dist/mint/types.d.ts +79 -0
  23. package/dist/mint/types.d.ts.map +1 -0
  24. package/dist/mints/mints-contracts.d.ts +24 -24
  25. package/dist/premint/contract-types.d.ts +4 -4
  26. package/dist/premint/contract-types.d.ts.map +1 -1
  27. package/dist/premint/conversions.d.ts +3 -1
  28. package/dist/premint/conversions.d.ts.map +1 -1
  29. package/dist/premint/premint-api-client.d.ts +27 -14
  30. package/dist/premint/premint-api-client.d.ts.map +1 -1
  31. package/dist/premint/premint-client.d.ts +62 -46
  32. package/dist/premint/premint-client.d.ts.map +1 -1
  33. package/dist/premint/preminter.d.ts +19 -7
  34. package/dist/premint/preminter.d.ts.map +1 -1
  35. package/dist/sdk.d.ts +43 -0
  36. package/dist/sdk.d.ts.map +1 -0
  37. package/dist/utils.d.ts +17 -6870
  38. package/dist/utils.d.ts.map +1 -1
  39. package/package.json +3 -2
  40. package/src/create/1155-create-helper.test.ts +235 -56
  41. package/src/create/1155-create-helper.ts +141 -309
  42. package/src/create/contract-setup.ts +88 -0
  43. package/src/create/token-setup.ts +379 -0
  44. package/src/create/types.ts +57 -0
  45. package/src/index.ts +5 -1
  46. package/src/mint/mint-client.test.ts +50 -61
  47. package/src/mint/mint-client.ts +321 -157
  48. package/src/mint/{mint-api-client.ts → subgraph-mint-getter.ts} +2 -25
  49. package/src/mint/types.ts +122 -0
  50. package/src/mints/mints-contracts.test.ts +1 -1
  51. package/src/mints/mints-contracts.ts +4 -4
  52. package/src/premint/contract-types.ts +4 -4
  53. package/src/premint/conversions.ts +12 -2
  54. package/src/premint/premint-api-client.ts +55 -43
  55. package/src/premint/premint-client.test.ts +75 -65
  56. package/src/premint/premint-client.ts +126 -153
  57. package/src/premint/preminter.test.ts +4 -5
  58. package/src/premint/preminter.ts +63 -13
  59. package/src/sdk.ts +98 -0
  60. package/src/utils.ts +30 -23
  61. package/test-integration/premint-client.test.ts +8 -8
  62. package/dist/mint/mint-api-client.d.ts +0 -35
  63. package/dist/mint/mint-api-client.d.ts.map +0 -1
@@ -36,6 +36,8 @@ import {
36
36
  ContractCreationConfigOrAddress,
37
37
  ContractCreationConfigWithOptionalAdditionalAdmins,
38
38
  } from "./contract-types";
39
+ import { IPremintGetter } from "./premint-api-client";
40
+ import { isPremintConfigV1, isPremintConfigV2 } from "./conversions";
39
41
 
40
42
  export const getPremintExecutorAddress = () =>
41
43
  zoraCreator1155PremintExecutorImplAddress[999] as Address;
@@ -271,8 +273,8 @@ export const supportsPremintVersion = async ({
271
273
 
272
274
  export async function getPremintCollectionAddress({
273
275
  publicClient,
274
- collection,
275
- collectionAddress,
276
+ contract: collection,
277
+ contractAddress: collectionAddress,
276
278
  }: {
277
279
  publicClient: PublicClient;
278
280
  } & ContractCreationConfigOrAddress): Promise<Address> {
@@ -355,26 +357,74 @@ export async function getPremintMintFee({
355
357
  }
356
358
  }
357
359
 
360
+ type GetMintCostsParams = {
361
+ tokenContract: Address;
362
+ tokenPrice: bigint;
363
+ quantityToMint: bigint | number;
364
+ publicClient: PublicClient;
365
+ };
366
+
358
367
  export async function getPremintMintCosts({
359
368
  publicClient,
360
369
  tokenContract,
361
370
  tokenPrice,
362
371
  quantityToMint,
363
- }: {
364
- tokenContract: Address;
365
- tokenPrice: bigint;
366
- quantityToMint: bigint;
367
- publicClient: PublicClient;
368
- }): Promise<MintCosts> {
372
+ }: GetMintCostsParams): Promise<MintCosts> {
369
373
  const mintFee = await getPremintMintFee({ tokenContract, publicClient });
370
374
 
375
+ const quantityToMintBigInt = BigInt(quantityToMint);
376
+
371
377
  return {
372
- mintFee: mintFee * quantityToMint,
373
- tokenPurchaseCost: tokenPrice * quantityToMint,
374
- totalCost: (mintFee + tokenPrice) * quantityToMint,
378
+ mintFee: mintFee * quantityToMintBigInt,
379
+ totalPurchaseCost: tokenPrice * quantityToMintBigInt,
380
+ totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt,
375
381
  };
376
382
  }
377
383
 
384
+ export async function getPremintPricePerToken({
385
+ collection,
386
+ uid,
387
+ premintGetter,
388
+ }: {
389
+ collection: Address;
390
+ uid: number;
391
+ premintGetter: IPremintGetter;
392
+ }) {
393
+ const premintConfigWithVersion = await premintGetter.getSignature({
394
+ collectionAddress: collection,
395
+ uid,
396
+ });
397
+
398
+ if (
399
+ isPremintConfigV1(premintConfigWithVersion) ||
400
+ isPremintConfigV2(premintConfigWithVersion)
401
+ ) {
402
+ return premintConfigWithVersion.premintConfig.tokenConfig.pricePerToken;
403
+ }
404
+
405
+ throw new Error("Premint version not supported to get price");
406
+ }
407
+
408
+ export async function getPremintMintCostsWithUnknownTokenPrice({
409
+ premintGetter,
410
+ uid,
411
+ ...rest
412
+ }: Omit<GetMintCostsParams, "tokenPrice"> & {
413
+ premintGetter: IPremintGetter;
414
+ uid: number;
415
+ }) {
416
+ const pricePerToken = await getPremintPricePerToken({
417
+ uid,
418
+ premintGetter,
419
+ collection: rest.tokenContract,
420
+ });
421
+
422
+ return await getPremintMintCosts({
423
+ ...rest,
424
+ tokenPrice: pricePerToken,
425
+ });
426
+ }
427
+
378
428
  export function makeMintRewardsRecipient({
379
429
  mintReferral = zeroAddress,
380
430
  platformReferral = zeroAddress,
@@ -416,13 +466,13 @@ export const toContractCreationConfigOrAddress = ({
416
466
  }) => {
417
467
  if (typeof collection !== "undefined") {
418
468
  return {
419
- collection,
469
+ contract: collection,
420
470
  };
421
471
  }
422
472
 
423
473
  if (typeof collectionAddress !== "undefined") {
424
474
  return {
425
- collectionAddress,
475
+ contractAddress: collectionAddress,
426
476
  };
427
477
  }
428
478
 
package/src/sdk.ts ADDED
@@ -0,0 +1,98 @@
1
+ import {
2
+ PremintClient,
3
+ getDataFromPremintReceipt,
4
+ } from "./premint/premint-client";
5
+ import { Create1155Client } from "./create/1155-create-helper";
6
+ import { MintClient } from "./mint/mint-client";
7
+ import { ClientConfig } from "./utils";
8
+ import { IPremintAPI, PremintAPIClient } from "./premint/premint-api-client";
9
+ import { SubgraphMintGetter } from "./mint/subgraph-mint-getter";
10
+ import { IMintGetter } from "./mint/types";
11
+
12
+ export type CreatorClient = {
13
+ createPremint: PremintClient["createPremint"];
14
+ updatePremint: PremintClient["updatePremint"];
15
+ deletePremint: PremintClient["deletePremint"];
16
+ create1155: Create1155Client["createNew1155Token"];
17
+ };
18
+
19
+ export type CollectorClient = {
20
+ getPremint: PremintClient["getPremint"];
21
+ getCollectDataFromPremintReceipt: PremintClient["getDataFromPremintReceipt"];
22
+ mint: MintClient["mint"];
23
+ getMintCosts: MintClient["getMintCosts"];
24
+ };
25
+
26
+ export type CreatorClientConfig = ClientConfig & {
27
+ /** API for submitting and getting premints. Defaults to the Zora Premint API */
28
+ premintApi?: IPremintAPI;
29
+ };
30
+
31
+ /**
32
+ * Builds the sdk for creating/managing 1155 contracts and tokens
33
+ *
34
+ * @param clientConfig - Configuration for the client {@link CreatorClientConfig}
35
+ * @returns CreatorClient {@link CreatorClient}
36
+ * */
37
+ export function createCreatorClient(
38
+ clientConfig: CreatorClientConfig,
39
+ ): CreatorClient {
40
+ const premintClient = new PremintClient({
41
+ chainId: clientConfig.chainId,
42
+ publicClient: clientConfig.publicClient,
43
+ premintApi:
44
+ clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId),
45
+ });
46
+
47
+ const create1155CreatorClient = new Create1155Client({
48
+ chainId: clientConfig.chainId,
49
+ publicClient: clientConfig.publicClient,
50
+ });
51
+
52
+ return {
53
+ createPremint: (p) => premintClient.createPremint(p),
54
+ updatePremint: (p) => premintClient.updatePremint(p),
55
+ deletePremint: (p) => premintClient.deletePremint(p),
56
+ create1155: (p) => create1155CreatorClient.createNew1155Token(p),
57
+ };
58
+ }
59
+
60
+ export type CollectorClientConfig = ClientConfig & {
61
+ /** API for getting premints. Defaults to the Zora Premint API */
62
+ premintGetter?: IPremintAPI;
63
+ /** API for getting onchain mints. Defaults to the Zora Creator Subgraph */
64
+ mintGetter?: IMintGetter;
65
+ };
66
+
67
+ /**
68
+ * Builds the sdk for collecting Premints, 1155, and 721 tokens.
69
+ *
70
+ * @param clientConfig - Configuration for the client {@link CollectorClientConfig}
71
+ * @returns CollectorClient {@link CollectorClient}
72
+ */
73
+ export function createCollectorClient(
74
+ params: CollectorClientConfig,
75
+ ): CollectorClient {
76
+ const premintGetterToUse =
77
+ params.premintGetter || new PremintAPIClient(params.chainId);
78
+ const mintGetterToUse =
79
+ params.mintGetter || new SubgraphMintGetter(params.chainId);
80
+ const mintClient = new MintClient({
81
+ chainId: params.chainId,
82
+ publicClient: params.publicClient,
83
+ premintGetter: premintGetterToUse,
84
+ mintGetter: mintGetterToUse,
85
+ });
86
+
87
+ return {
88
+ getPremint: (p) =>
89
+ premintGetterToUse.getSignature({
90
+ collectionAddress: p.address,
91
+ uid: p.uid,
92
+ }),
93
+ getCollectDataFromPremintReceipt: (p) =>
94
+ getDataFromPremintReceipt(p, params.chainId),
95
+ mint: (p) => mintClient.mint(p),
96
+ getMintCosts: (p) => mintClient.getMintCosts(p),
97
+ };
98
+ }
package/src/utils.ts CHANGED
@@ -7,23 +7,14 @@ import {
7
7
  ContractFunctionName,
8
8
  PublicClient as BasePublicClient,
9
9
  SimulateContractParameters,
10
- Transport,
11
- createPublicClient,
12
- http,
10
+ AbiStateMutability,
13
11
  } from "viem";
14
- import {
15
- IHttpClient,
16
- httpClient as defaultHttpClient,
17
- } from "./apis/http-api-base";
18
12
 
19
- export const makeSimulateContractParamaters = <
13
+ export const makeContractParameters = <
20
14
  const abi extends Abi | readonly unknown[],
21
- functionName extends ContractFunctionName<abi, "nonpayable" | "payable">,
22
- args extends ContractFunctionArgs<
23
- abi,
24
- "nonpayable" | "payable",
25
- functionName
26
- >,
15
+ stateMutabiliy extends AbiStateMutability,
16
+ functionName extends ContractFunctionName<abi, stateMutabiliy>,
17
+ args extends ContractFunctionArgs<abi, stateMutabiliy, functionName>,
27
18
  chainOverride extends Chain | undefined,
28
19
  accountOverride extends Account | Address | undefined = undefined,
29
20
  >(
@@ -37,19 +28,35 @@ export const makeSimulateContractParamaters = <
37
28
  >,
38
29
  ) => args;
39
30
 
40
- export type PublicClient = BasePublicClient<Transport, Chain>;
31
+ export type PublicClient = Pick<BasePublicClient, "readContract">;
41
32
 
42
33
  export type ClientConfig = {
43
- chain: Chain;
44
- publicClient?: PublicClient;
45
- httpClient?: IHttpClient;
34
+ /** The chain that the client is to run on. */
35
+ chainId: number;
36
+ /** Optional public client for the chain. If not provide, it is created. */
37
+ publicClient: PublicClient;
46
38
  };
47
39
 
48
- export function setupClient({ chain, httpClient, publicClient }: ClientConfig) {
40
+ export function setupClient({ chainId, publicClient }: ClientConfig) {
49
41
  return {
50
- chain,
51
- httpClient: httpClient || defaultHttpClient,
52
- publicClient:
53
- publicClient || createPublicClient({ chain, transport: http() }),
42
+ chainId,
43
+ publicClient,
54
44
  };
55
45
  }
46
+
47
+ export function mintRecipientOrAccount({
48
+ mintRecipient,
49
+ minterAccount,
50
+ }: {
51
+ mintRecipient?: Address;
52
+ minterAccount: Address | Account;
53
+ }): Address {
54
+ return (
55
+ mintRecipient ||
56
+ (typeof minterAccount === "string" ? minterAccount : minterAccount.address)
57
+ );
58
+ }
59
+
60
+ export type Concrete<Type> = {
61
+ [Property in keyof Type]-?: Type[Property];
62
+ };
@@ -40,7 +40,7 @@ tests.forEach(({ anvilTest, chain }) => {
40
40
  const [creatorAccount, createReferralAccount, minterAccount] =
41
41
  await walletClient.getAddresses();
42
42
  const premintClient = createPremintClient({
43
- chain,
43
+ chainId: chain,
44
44
  publicClient,
45
45
  });
46
46
 
@@ -49,7 +49,7 @@ tests.forEach(({ anvilTest, chain }) => {
49
49
  walletClient,
50
50
  payoutRecipient: creatorAccount!,
51
51
  checkSignature: true,
52
- collection: {
52
+ contract: {
53
53
  contractAdmin: creatorAccount!,
54
54
  contractName: "Testing Contract Premint V2",
55
55
  contractURI:
@@ -57,7 +57,7 @@ tests.forEach(({ anvilTest, chain }) => {
57
57
  additionalAdmins: [],
58
58
  },
59
59
  premintConfigVersion: PremintConfigVersion.V2,
60
- tokenCreationConfig: {
60
+ token: {
61
61
  tokenURI:
62
62
  "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2f",
63
63
  createReferral: createReferralAccount!,
@@ -78,7 +78,7 @@ tests.forEach(({ anvilTest, chain }) => {
78
78
 
79
79
  await testClient.setBalance({
80
80
  address: minterAccount!,
81
- value: mintCosts.totalCost,
81
+ value: mintCosts.totalCostEth,
82
82
  });
83
83
 
84
84
  // if simulation succeeds, mint will succeed
@@ -97,7 +97,7 @@ tests.forEach(({ anvilTest, chain }) => {
97
97
  const [creatorAccount, minterAccount] =
98
98
  await walletClient.getAddresses();
99
99
  const premintClient = createPremintClient({
100
- chain,
100
+ chainId: chain,
101
101
  publicClient,
102
102
  });
103
103
 
@@ -106,7 +106,7 @@ tests.forEach(({ anvilTest, chain }) => {
106
106
  walletClient,
107
107
  payoutRecipient: creatorAccount!,
108
108
  checkSignature: true,
109
- collection: {
109
+ contract: {
110
110
  contractAdmin: creatorAccount!,
111
111
  contractName: `Testing Contract Premint V1 ${publicClient.chain?.name}`,
112
112
  contractURI:
@@ -114,7 +114,7 @@ tests.forEach(({ anvilTest, chain }) => {
114
114
  additionalAdmins: [],
115
115
  },
116
116
  premintConfigVersion: PremintConfigVersion.V1,
117
- tokenCreationConfig: {
117
+ token: {
118
118
  tokenURI:
119
119
  "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
120
120
  },
@@ -134,7 +134,7 @@ tests.forEach(({ anvilTest, chain }) => {
134
134
 
135
135
  await testClient.setBalance({
136
136
  address: minterAccount!,
137
- value: mintCosts.totalCost,
137
+ value: mintCosts.totalCostEth,
138
138
  });
139
139
 
140
140
  // if simulation succeeds, mint will succeed
@@ -1,35 +0,0 @@
1
- import { Address } from "viem";
2
- import { IHttpClient } from "../apis/http-api-base";
3
- import { NetworkConfig } from "src/apis/chain-constants";
4
- import { GenericTokenIdTypes } from "src/types";
5
- export type SaleType = "fixedPrice" | "erc20";
6
- type SaleStrategy<T extends SaleType> = {
7
- saleType: T;
8
- address: Address;
9
- pricePerToken: bigint;
10
- saleEnd: string;
11
- saleStart: string;
12
- maxTokensPerAddress: bigint;
13
- };
14
- type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice">;
15
- type ERC20SaleStrategy = SaleStrategy<"erc20"> & {
16
- currency: Address;
17
- };
18
- type SaleStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
19
- export type SalesConfigAndTokenInfo = {
20
- salesConfig: SaleStrategies;
21
- mintFeePerQuantity: bigint;
22
- };
23
- export declare const getApiNetworkConfigForChain: (chainId: number) => NetworkConfig;
24
- export declare class MintAPIClient {
25
- httpClient: IHttpClient;
26
- networkConfig: NetworkConfig;
27
- constructor(chainId: number, httpClient?: IHttpClient);
28
- getSalesConfigAndTokenInfo({ tokenAddress, tokenId, saleType, }: {
29
- tokenAddress: Address;
30
- tokenId?: GenericTokenIdTypes;
31
- saleType?: SaleType;
32
- }): Promise<SalesConfigAndTokenInfo>;
33
- }
34
- export {};
35
- //# sourceMappingURL=mint-api-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mint-api-client.d.ts","sourceRoot":"","sources":["../../src/mint/mint-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAEL,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAwB,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGhD,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,OAAO,CAAC;AAiC9C,KAAK,YAAY,CAAC,CAAC,SAAS,QAAQ,IAAI;IACtC,QAAQ,EAAE,CAAC,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,KAAK,sBAAsB,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAEzD,KAAK,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG;IAC/C,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,KAAK,cAAc,GAAG,sBAAsB,GAAG,iBAAiB,CAAC;AAEjE,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,cAAc,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,2BAA2B,YAAa,MAAM,KAAG,aAK7D,CAAC;AAEF,qBAAa,aAAa;IACxB,UAAU,EAAE,WAAW,CAAC;IACxB,aAAa,EAAE,aAAa,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW;IAK/C,0BAA0B,CAAC,EAC/B,YAAY,EACZ,OAAO,EACP,QAAQ,GACT,EAAE;QACD,YAAY,EAAE,OAAO,CAAC;QACtB,OAAO,CAAC,EAAE,mBAAmB,CAAC;QAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;KACrB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAwFrC"}