@zoralabs/protocol-sdk 0.6.0 → 0.7.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 (59) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +6 -0
  3. package/dist/constants.d.ts +0 -1
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/index.cjs +845 -407
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +829 -391
  8. package/dist/index.js.map +1 -1
  9. package/dist/mint/mint-client.d.ts +28 -4071
  10. package/dist/mint/mint-client.d.ts.map +1 -1
  11. package/dist/mint/mint-queries.d.ts +38 -0
  12. package/dist/mint/mint-queries.d.ts.map +1 -0
  13. package/dist/mint/mint-transactions.d.ts +20 -0
  14. package/dist/mint/mint-transactions.d.ts.map +1 -0
  15. package/dist/mint/subgraph-mint-getter.d.ts +14 -7
  16. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  17. package/dist/mint/subgraph-queries.d.ts +55 -0
  18. package/dist/mint/subgraph-queries.d.ts.map +1 -0
  19. package/dist/mint/types.d.ts +117 -19
  20. package/dist/mint/types.d.ts.map +1 -1
  21. package/dist/mint/utils.d.ts +2 -0
  22. package/dist/mint/utils.d.ts.map +1 -0
  23. package/dist/mints/mints-contracts.d.ts +3 -4494
  24. package/dist/mints/mints-contracts.d.ts.map +1 -1
  25. package/dist/premint/conversions.d.ts +12 -15
  26. package/dist/premint/conversions.d.ts.map +1 -1
  27. package/dist/premint/premint-api-client.d.ts +14 -11
  28. package/dist/premint/premint-api-client.d.ts.map +1 -1
  29. package/dist/premint/premint-client.d.ts +15 -5
  30. package/dist/premint/premint-client.d.ts.map +1 -1
  31. package/dist/premint/preminter.d.ts +1 -1
  32. package/dist/premint/preminter.d.ts.map +1 -1
  33. package/dist/sdk.d.ts +4 -2
  34. package/dist/sdk.d.ts.map +1 -1
  35. package/dist/types.d.ts +3 -0
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +10 -2
  38. package/dist/utils.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/constants.ts +0 -36
  41. package/src/create/1155-create-helper.test.ts +9 -7
  42. package/src/mint/mint-client.test.ts +96 -47
  43. package/src/mint/mint-client.ts +75 -343
  44. package/src/mint/mint-queries.ts +320 -0
  45. package/src/mint/mint-transactions.ts +253 -0
  46. package/src/mint/subgraph-mint-getter.ts +216 -123
  47. package/src/mint/subgraph-queries.ts +170 -0
  48. package/src/mint/types.ts +140 -23
  49. package/src/mint/utils.ts +14 -0
  50. package/src/premint/conversions.ts +26 -2
  51. package/src/premint/premint-api-client.ts +48 -16
  52. package/src/premint/premint-client.test.ts +29 -23
  53. package/src/premint/premint-client.ts +64 -36
  54. package/src/premint/preminter.ts +2 -3
  55. package/src/sdk.ts +7 -4
  56. package/src/types.ts +18 -0
  57. package/src/utils.ts +29 -28
  58. package/test-integration/setup-test-contracts.ts +96 -0
  59. package/test-integration/premint-client.test.ts +0 -148
@@ -29,7 +29,6 @@ import {
29
29
  PremintConfigWithVersion,
30
30
  TokenCreationConfig,
31
31
  } from "@zoralabs/protocol-deployments";
32
- import { MintCosts } from "src/mint/mint-client";
33
32
  import { PublicClient } from "src/utils";
34
33
  import {
35
34
  ContractCreationConfigAndAddress,
@@ -38,6 +37,7 @@ import {
38
37
  } from "./contract-types";
39
38
  import { IPremintGetter } from "./premint-api-client";
40
39
  import { isPremintConfigV1, isPremintConfigV2 } from "./conversions";
40
+ import { MintCosts } from "src/mint/types";
41
41
 
42
42
  export const getPremintExecutorAddress = () =>
43
43
  zoraCreator1155PremintExecutorImplAddress[999] as Address;
@@ -380,7 +380,6 @@ export async function getPremintMintCosts({
380
380
  totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt,
381
381
  };
382
382
  }
383
-
384
383
  export async function getPremintPricePerToken({
385
384
  collection,
386
385
  uid,
@@ -390,7 +389,7 @@ export async function getPremintPricePerToken({
390
389
  uid: number;
391
390
  premintGetter: IPremintGetter;
392
391
  }) {
393
- const premintConfigWithVersion = await premintGetter.getSignature({
392
+ const { premint: premintConfigWithVersion } = await premintGetter.get({
394
393
  collectionAddress: collection,
395
394
  uid,
396
395
  });
package/src/sdk.ts CHANGED
@@ -7,7 +7,7 @@ import { MintClient } from "./mint/mint-client";
7
7
  import { ClientConfig } from "./utils";
8
8
  import { IPremintAPI, PremintAPIClient } from "./premint/premint-api-client";
9
9
  import { SubgraphMintGetter } from "./mint/subgraph-mint-getter";
10
- import { IMintGetter } from "./mint/types";
10
+ import { IOnchainMintGetter } from "./mint/types";
11
11
 
12
12
  export type CreatorClient = {
13
13
  createPremint: PremintClient["createPremint"];
@@ -21,6 +21,8 @@ export type CollectorClient = {
21
21
  getCollectDataFromPremintReceipt: PremintClient["getDataFromPremintReceipt"];
22
22
  mint: MintClient["mint"];
23
23
  getMintCosts: MintClient["getMintCosts"];
24
+ getToken: MintClient["get"];
25
+ getTokensOfContract: MintClient["getOfContract"];
24
26
  };
25
27
 
26
28
  export type CreatorClientConfig = ClientConfig & {
@@ -61,7 +63,7 @@ export type CollectorClientConfig = ClientConfig & {
61
63
  /** API for getting premints. Defaults to the Zora Premint API */
62
64
  premintGetter?: IPremintAPI;
63
65
  /** API for getting onchain mints. Defaults to the Zora Creator Subgraph */
64
- mintGetter?: IMintGetter;
66
+ mintGetter?: IOnchainMintGetter;
65
67
  };
66
68
 
67
69
  /**
@@ -78,7 +80,6 @@ export function createCollectorClient(
78
80
  const mintGetterToUse =
79
81
  params.mintGetter || new SubgraphMintGetter(params.chainId);
80
82
  const mintClient = new MintClient({
81
- chainId: params.chainId,
82
83
  publicClient: params.publicClient,
83
84
  premintGetter: premintGetterToUse,
84
85
  mintGetter: mintGetterToUse,
@@ -86,12 +87,14 @@ export function createCollectorClient(
86
87
 
87
88
  return {
88
89
  getPremint: (p) =>
89
- premintGetterToUse.getSignature({
90
+ premintGetterToUse.get({
90
91
  collectionAddress: p.address,
91
92
  uid: p.uid,
92
93
  }),
93
94
  getCollectDataFromPremintReceipt: (p) =>
94
95
  getDataFromPremintReceipt(p, params.chainId),
96
+ getToken: (p) => mintClient.get(p),
97
+ getTokensOfContract: (p) => mintClient.getOfContract(p),
95
98
  mint: (p) => mintClient.mint(p),
96
99
  getMintCosts: (p) => mintClient.getMintCosts(p),
97
100
  };
package/src/types.ts CHANGED
@@ -1 +1,19 @@
1
+ import {
2
+ Account,
3
+ Address,
4
+ PublicClient,
5
+ SimulateContractParameters,
6
+ } from "viem";
7
+
1
8
  export type GenericTokenIdTypes = number | bigint | string;
9
+
10
+ export type IPublicClient = Pick<PublicClient, "readContract">;
11
+
12
+ export type SimulateContractParametersWithAccount = SimulateContractParameters<
13
+ any,
14
+ any,
15
+ any,
16
+ any,
17
+ any,
18
+ Account | Address
19
+ >;
package/src/utils.ts CHANGED
@@ -1,31 +1,9 @@
1
- import {
2
- Abi,
3
- Account,
4
- Address,
5
- Chain,
6
- ContractFunctionArgs,
7
- ContractFunctionName,
8
- PublicClient as BasePublicClient,
9
- SimulateContractParameters,
10
- AbiStateMutability,
11
- } from "viem";
12
-
13
- export const makeContractParameters = <
14
- const abi extends Abi | readonly unknown[],
15
- stateMutabiliy extends AbiStateMutability,
16
- functionName extends ContractFunctionName<abi, stateMutabiliy>,
17
- args extends ContractFunctionArgs<abi, stateMutabiliy, functionName>,
18
- chainOverride extends Chain | undefined,
19
- accountOverride extends Account | Address | undefined = undefined,
20
- >(
21
- args: SimulateContractParameters<
22
- abi,
23
- functionName,
24
- args,
25
- Chain,
26
- chainOverride,
27
- accountOverride
28
- >,
1
+ import { Account, Address, PublicClient as BasePublicClient } from "viem";
2
+ import { IHttpClient } from "./apis/http-api-base";
3
+ import { SimulateContractParametersWithAccount } from "./types";
4
+
5
+ export const makeContractParameters = (
6
+ args: SimulateContractParametersWithAccount,
29
7
  ) => args;
30
8
 
31
9
  export type PublicClient = Pick<BasePublicClient, "readContract">;
@@ -60,3 +38,26 @@ export function mintRecipientOrAccount({
60
38
  export type Concrete<Type> = {
61
39
  [Property in keyof Type]-?: Type[Property];
62
40
  };
41
+
42
+ export async function querySubgraphWithRetries({
43
+ httpClient,
44
+ subgraphUrl,
45
+ query,
46
+ variables,
47
+ }: {
48
+ httpClient: IHttpClient;
49
+ subgraphUrl: string;
50
+ query: string;
51
+ variables: any;
52
+ }) {
53
+ const { retries, post } = httpClient;
54
+
55
+ const result = await retries(async () => {
56
+ return await post<any>(subgraphUrl, {
57
+ query,
58
+ variables,
59
+ });
60
+ });
61
+
62
+ return result?.data;
63
+ }
@@ -0,0 +1,96 @@
1
+ import {
2
+ createCollectorClient,
3
+ createCreatorClient,
4
+ getPremintCollectionAddress,
5
+ } from "src";
6
+ import {
7
+ LocalAccount,
8
+ createPublicClient,
9
+ createWalletClient,
10
+ http,
11
+ parseEther,
12
+ } from "viem";
13
+ import { privateKeyToAccount } from "viem/accounts";
14
+ import { zoraSepolia } from "viem/chains";
15
+
16
+ const publicClient = createPublicClient({
17
+ chain: zoraSepolia,
18
+ transport: http(),
19
+ });
20
+
21
+ const walletClient = createWalletClient({
22
+ chain: zoraSepolia,
23
+ transport: http(),
24
+ });
25
+
26
+ const creatorClient = createCreatorClient({
27
+ chainId: zoraSepolia.id,
28
+ publicClient,
29
+ });
30
+
31
+ const collectorClient = createCollectorClient({
32
+ chainId: zoraSepolia.id,
33
+ publicClient,
34
+ });
35
+
36
+ export const createPremintsOnContract = async ({
37
+ creatorAccount,
38
+ }: {
39
+ creatorAccount: LocalAccount;
40
+ }) => {
41
+ const collectionAddress = await getPremintCollectionAddress({
42
+ publicClient,
43
+ contract: {
44
+ contractAdmin: creatorAccount.address,
45
+ contractName: "testContract",
46
+ contractURI:
47
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
48
+ },
49
+ });
50
+
51
+ console.log({ collectionAddress });
52
+
53
+ const { typedDataDefinition, submit } = await creatorClient.createPremint({
54
+ contract: {
55
+ contractAdmin: creatorAccount.address,
56
+ contractName: "testContract",
57
+ contractURI:
58
+ "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
59
+ },
60
+ token: {
61
+ payoutRecipient: creatorAccount.address,
62
+ tokenURI:
63
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
64
+ pricePerToken: parseEther("0.001"),
65
+ },
66
+ });
67
+
68
+ const signature = await walletClient.signTypedData({
69
+ account: creatorAccount,
70
+ ...typedDataDefinition,
71
+ });
72
+
73
+ await submit({
74
+ signature,
75
+ });
76
+
77
+ const mints = await collectorClient.getTokensOfContract({
78
+ tokenContract: collectionAddress,
79
+ });
80
+
81
+ console.log({ mints: mints.map((x) => x.mintable) });
82
+ };
83
+
84
+ const setupTestContracts = async () => {
85
+ const creatorAccount = privateKeyToAccount(
86
+ // random private key created by cast
87
+ "0x0d32fcabfe28c779974a77dc635163f062be2bc0b10eea62994235617b44092f",
88
+ );
89
+
90
+ // create 2 premints on a contract
91
+ await createPremintsOnContract({
92
+ creatorAccount,
93
+ });
94
+ };
95
+
96
+ setupTestContracts();
@@ -1,148 +0,0 @@
1
- import { zoraSepolia, zoraTestnet } from "viem/chains";
2
- import { describe } from "vitest";
3
-
4
- import { createPremintClient } from "src/premint/premint-client";
5
- import { forkUrls, makeAnvilTest } from "src/anvil";
6
- import { PremintConfigVersion } from "src/premint/contract-types";
7
-
8
- const zoraGoerliTest = makeAnvilTest({
9
- forkBlockNumber: 2107926,
10
- forkUrl: forkUrls.zoraGoerli,
11
- anvilChainId: zoraTestnet.id,
12
- });
13
-
14
- const zoraSepoliaTest = makeAnvilTest({
15
- forkBlockNumber: 3118200,
16
- forkUrl: forkUrls.zoraSepolia,
17
- anvilChainId: zoraSepolia.id,
18
- });
19
-
20
- const tests = [
21
- {
22
- anvilTest: zoraGoerliTest,
23
- chain: zoraTestnet,
24
- },
25
- {
26
- anvilTest: zoraSepoliaTest,
27
- chain: zoraSepolia,
28
- },
29
- ];
30
-
31
- tests.forEach(({ anvilTest, chain }) => {
32
- describe(chain.name, () => {
33
- describe("ZoraCreator1155Premint", () => {
34
- describe("v2 signatures", () => {
35
- anvilTest(
36
- "can sign and execute on the forked premint contract",
37
- async ({
38
- viemClients: { walletClient, publicClient, testClient },
39
- }) => {
40
- const [creatorAccount, createReferralAccount, minterAccount] =
41
- await walletClient.getAddresses();
42
- const premintClient = createPremintClient({
43
- chainId: chain,
44
- publicClient,
45
- });
46
-
47
- const { uid, verifyingContract } =
48
- await premintClient.createPremint({
49
- walletClient,
50
- payoutRecipient: creatorAccount!,
51
- checkSignature: true,
52
- contract: {
53
- contractAdmin: creatorAccount!,
54
- contractName: "Testing Contract Premint V2",
55
- contractURI:
56
- "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3f",
57
- additionalAdmins: [],
58
- },
59
- premintConfigVersion: PremintConfigVersion.V2,
60
- token: {
61
- tokenURI:
62
- "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2f",
63
- createReferral: createReferralAccount!,
64
- },
65
- });
66
-
67
- const mintParameters = await premintClient.makeMintParameters({
68
- minterAccount: minterAccount!,
69
- tokenContract: verifyingContract,
70
- uid,
71
- });
72
-
73
- const mintCosts = await premintClient.getMintCosts({
74
- tokenContract: verifyingContract,
75
- quantityToMint: 1n,
76
- pricePerToken: 0n,
77
- });
78
-
79
- await testClient.setBalance({
80
- address: minterAccount!,
81
- value: mintCosts.totalCostEth,
82
- });
83
-
84
- // if simulation succeeds, mint will succeed
85
- await publicClient.simulateContract(mintParameters);
86
- },
87
- 20 * 1000,
88
- );
89
- });
90
-
91
- describe("v1 signatures", () => {
92
- anvilTest(
93
- "can sign and execute on the forked premint contract",
94
- async ({
95
- viemClients: { walletClient, publicClient, testClient },
96
- }) => {
97
- const [creatorAccount, minterAccount] =
98
- await walletClient.getAddresses();
99
- const premintClient = createPremintClient({
100
- chainId: chain,
101
- publicClient,
102
- });
103
-
104
- const { uid, verifyingContract } =
105
- await premintClient.createPremint({
106
- walletClient,
107
- payoutRecipient: creatorAccount!,
108
- checkSignature: true,
109
- contract: {
110
- contractAdmin: creatorAccount!,
111
- contractName: `Testing Contract Premint V1 ${publicClient.chain?.name}`,
112
- contractURI:
113
- "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3fg",
114
- additionalAdmins: [],
115
- },
116
- premintConfigVersion: PremintConfigVersion.V1,
117
- token: {
118
- tokenURI:
119
- "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
120
- },
121
- });
122
-
123
- const mintParameters = await premintClient.makeMintParameters({
124
- minterAccount: minterAccount!,
125
- tokenContract: verifyingContract,
126
- uid,
127
- });
128
-
129
- const mintCosts = await premintClient.getMintCosts({
130
- tokenContract: verifyingContract,
131
- quantityToMint: 1n,
132
- pricePerToken: 0n,
133
- });
134
-
135
- await testClient.setBalance({
136
- address: minterAccount!,
137
- value: mintCosts.totalCostEth,
138
- });
139
-
140
- // if simulation succeeds, mint will succeed
141
- await publicClient.simulateContract(mintParameters);
142
- },
143
- 20 * 1000,
144
- );
145
- });
146
- });
147
- });
148
- });