@zoralabs/protocol-sdk 0.7.6 → 0.9.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 (80) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +17 -0
  3. package/dist/allow-list/allow-list-client.d.ts +26 -0
  4. package/dist/allow-list/allow-list-client.d.ts.map +1 -0
  5. package/dist/allow-list/types.d.ts +14 -0
  6. package/dist/allow-list/types.d.ts.map +1 -0
  7. package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
  8. package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
  9. package/dist/apis/http-api-base.d.ts.map +1 -1
  10. package/dist/apis/subgraph-querier.d.ts +18 -0
  11. package/dist/apis/subgraph-querier.d.ts.map +1 -0
  12. package/dist/create/1155-create-helper.d.ts +14 -11
  13. package/dist/create/1155-create-helper.d.ts.map +1 -1
  14. package/dist/create/contract-setup.d.ts +13 -8
  15. package/dist/create/contract-setup.d.ts.map +1 -1
  16. package/dist/create/minter-defaults.d.ts +5 -0
  17. package/dist/create/minter-defaults.d.ts.map +1 -0
  18. package/dist/create/minter-setup.d.ts +14 -0
  19. package/dist/create/minter-setup.d.ts.map +1 -0
  20. package/dist/create/token-setup.d.ts +4 -19
  21. package/dist/create/token-setup.d.ts.map +1 -1
  22. package/dist/create/types.d.ts +53 -13
  23. package/dist/create/types.d.ts.map +1 -1
  24. package/dist/create/update.d.ts +15 -0
  25. package/dist/create/update.d.ts.map +1 -0
  26. package/dist/index.cjs +1660 -1246
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1681 -1264
  31. package/dist/index.js.map +1 -1
  32. package/dist/ipfs/token-metadata.d.ts +1 -0
  33. package/dist/ipfs/token-metadata.d.ts.map +1 -1
  34. package/dist/mint/mint-client.d.ts +2 -6
  35. package/dist/mint/mint-client.d.ts.map +1 -1
  36. package/dist/mint/mint-queries.d.ts +3 -1
  37. package/dist/mint/mint-queries.d.ts.map +1 -1
  38. package/dist/mint/mint-transactions.d.ts +9 -7
  39. package/dist/mint/mint-transactions.d.ts.map +1 -1
  40. package/dist/mint/subgraph-mint-getter.d.ts +5 -4
  41. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  42. package/dist/mint/subgraph-queries.d.ts +42 -15
  43. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  44. package/dist/mint/types.d.ts +32 -13
  45. package/dist/mint/types.d.ts.map +1 -1
  46. package/dist/sdk.d.ts +2 -1
  47. package/dist/sdk.d.ts.map +1 -1
  48. package/dist/sparks/sparks-contracts.d.ts +96 -96
  49. package/dist/types.d.ts +1 -1
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/utils.d.ts +1 -8
  52. package/dist/utils.d.ts.map +1 -1
  53. package/package.json +2 -3
  54. package/src/allow-list/allow-list-client.ts +105 -0
  55. package/src/allow-list/types.ts +15 -0
  56. package/src/apis/generated/allow-list-api-types.ts +288 -0
  57. package/src/apis/http-api-base.ts +12 -0
  58. package/src/apis/subgraph-querier.ts +38 -0
  59. package/src/create/1155-create-helper.test.ts +269 -113
  60. package/src/create/1155-create-helper.ts +204 -90
  61. package/src/create/contract-setup.ts +54 -44
  62. package/src/create/minter-defaults.test.ts +21 -0
  63. package/src/create/minter-defaults.ts +134 -0
  64. package/src/create/minter-setup.ts +293 -0
  65. package/src/create/token-setup.ts +14 -190
  66. package/src/create/types.ts +94 -25
  67. package/src/create/update.ts +93 -0
  68. package/src/index.ts +4 -0
  69. package/src/ipfs/token-metadata.ts +18 -0
  70. package/src/mint/mint-client.test.ts +219 -15
  71. package/src/mint/mint-client.ts +2 -34
  72. package/src/mint/mint-queries.ts +34 -13
  73. package/src/mint/mint-transactions.ts +104 -17
  74. package/src/mint/subgraph-mint-getter.ts +107 -50
  75. package/src/mint/subgraph-queries.ts +67 -37
  76. package/src/mint/types.ts +55 -16
  77. package/src/premint/premint-client.test.ts +6 -5
  78. package/src/sdk.ts +5 -2
  79. package/src/types.ts +1 -1
  80. package/src/utils.ts +1 -25
@@ -1,21 +1,78 @@
1
1
  import { describe, expect } from "vitest";
2
- import { getTokenIdFromCreateReceipt } from "./1155-create-helper";
3
- import { anvilTest } from "src/anvil";
2
+ import {
3
+ getContractAddressFromReceipt,
4
+ getTokenIdFromCreateReceipt,
5
+ } from "./1155-create-helper";
4
6
  import { createCreatorClient } from "src/sdk";
5
- import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
7
+ import {
8
+ zoraCreator1155ImplABI,
9
+ zoraTimedSaleStrategyAddress,
10
+ } from "@zoralabs/protocol-deployments";
6
11
  import { waitForSuccess } from "src/test-utils";
7
- import { parseEther } from "viem";
8
12
  import {
9
- MintableParameters,
10
- makePrepareMint1155TokenParams,
11
- } from "src/mint/mint-transactions";
13
+ Address,
14
+ parseEther,
15
+ PublicClient,
16
+ TransactionReceipt,
17
+ zeroAddress,
18
+ } from "viem";
19
+ import { makePrepareMint1155TokenParams } from "src/mint/mint-transactions";
20
+ import { forkUrls, makeAnvilTest } from "src/anvil";
21
+ import { zora } from "viem/chains";
22
+ import { AllowList } from "src/allow-list/types";
23
+ import { createAllowList } from "src/allow-list/allow-list-client";
24
+ import { NewContractParams } from "./types";
25
+
26
+ export const demoTokenMetadataURI =
27
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
28
+ export const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
29
+
30
+ const anvilTest = makeAnvilTest({
31
+ forkUrl: forkUrls.zoraMainnet,
32
+ forkBlockNumber: 18094820,
33
+ anvilChainId: zora.id,
34
+ });
35
+
36
+ const PERMISSION_BITS = {
37
+ MINTER: 2n ** 2n,
38
+ };
39
+
40
+ const minterIsMinterOnToken = async ({
41
+ publicClient,
42
+ contractAddress,
43
+ tokenId,
44
+ minter,
45
+ }: {
46
+ publicClient: Pick<PublicClient, "readContract">;
47
+ contractAddress: Address;
48
+ tokenId: bigint;
49
+ minter: Address;
50
+ }) => {
51
+ return await publicClient.readContract({
52
+ abi: zoraCreator1155ImplABI,
53
+ address: contractAddress,
54
+ functionName: "isAdminOrRole",
55
+ args: [minter, tokenId, PERMISSION_BITS.MINTER],
56
+ });
57
+ };
58
+
59
+ function logFailure(receipt: TransactionReceipt) {
60
+ if (receipt.status !== "success") {
61
+ console.log("transaction failed");
62
+ console.log(receipt.logs);
63
+ }
64
+ }
12
65
 
13
- const demoTokenMetadataURI = "ipfs://DUMMY/token.json";
14
- const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
66
+ function randomNewContract(): NewContractParams {
67
+ return {
68
+ name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
69
+ uri: demoContractMetadataURI,
70
+ };
71
+ }
15
72
 
16
73
  describe("create-helper", () => {
17
74
  anvilTest(
18
- "creates a new 1155 contract and token",
75
+ "when no sales config is provided, it creates a new 1155 contract and token using the timed sale strategy",
19
76
  async ({ viemClients: { publicClient, walletClient, chain } }) => {
20
77
  const addresses = await walletClient.getAddresses();
21
78
  const creatorAddress = addresses[0]!;
@@ -24,61 +81,113 @@ describe("create-helper", () => {
24
81
  chainId: chain.id,
25
82
  publicClient: publicClient,
26
83
  });
27
- const { parameters: request } = await creatorClient.create1155({
28
- contract: {
29
- name: "testContract",
30
- uri: demoContractMetadataURI,
31
- },
32
- token: {
33
- tokenMetadataURI: demoTokenMetadataURI,
34
- mintToCreatorCount: 1,
35
- },
36
- account: creatorAddress,
37
- });
38
- const { request: simulationResponse } =
39
- await publicClient.simulateContract(request);
40
- const hash = await walletClient.writeContract(simulationResponse);
84
+ const { parameters, contractAddress, newTokenId } =
85
+ await creatorClient.create1155({
86
+ contract: randomNewContract(),
87
+ token: {
88
+ tokenMetadataURI: demoTokenMetadataURI,
89
+ mintToCreatorCount: 1,
90
+ },
91
+ account: creatorAddress,
92
+ });
93
+
94
+ const { request } = await publicClient.simulateContract(parameters);
95
+ const hash = await walletClient.writeContract(request);
41
96
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
97
+ logFailure(receipt);
98
+ expect(receipt.status).toBe("success");
42
99
  expect(receipt).not.toBeNull();
43
100
  expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
44
101
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
102
+ expect(getContractAddressFromReceipt(receipt)).to.be.equal(
103
+ contractAddress,
104
+ );
105
+
106
+ expect(
107
+ await minterIsMinterOnToken({
108
+ contractAddress,
109
+ tokenId: newTokenId,
110
+ publicClient,
111
+ minter:
112
+ zoraTimedSaleStrategyAddress[
113
+ chain.id as keyof typeof zoraTimedSaleStrategyAddress
114
+ ],
115
+ }),
116
+ ).toBe(true);
45
117
  },
46
118
  20 * 1000,
47
119
  );
48
120
  anvilTest(
49
- "creates a new contract, then can create a new token on this existing contract",
121
+ "when price is set to 0, it creates a new 1155 contract and token using the timed sale strategy",
50
122
  async ({ viemClients: { publicClient, walletClient, chain } }) => {
51
123
  const addresses = await walletClient.getAddresses();
52
- const creatorAccount = addresses[0]!;
124
+ const creatorAddress = addresses[0]!;
53
125
 
54
126
  const creatorClient = createCreatorClient({
55
127
  chainId: chain.id,
56
128
  publicClient: publicClient,
57
129
  });
130
+ const { parameters, contractAddress, newTokenId } =
131
+ await creatorClient.create1155({
132
+ contract: randomNewContract(),
133
+ token: {
134
+ tokenMetadataURI: demoTokenMetadataURI,
135
+ salesConfig: {
136
+ pricePerToken: 0n,
137
+ },
138
+ },
139
+ account: creatorAddress,
140
+ });
58
141
 
59
- const {
60
- parameters: request,
61
- collectionAddress: contractAddress,
62
- contractExists,
63
- } = await creatorClient.create1155({
64
- contract: {
65
- name: "testContract2",
66
- uri: demoContractMetadataURI,
67
- },
68
- token: {
69
- tokenMetadataURI: demoTokenMetadataURI,
70
- mintToCreatorCount: 3,
71
- },
72
- account: creatorAccount,
142
+ const { request } = await publicClient.simulateContract(parameters);
143
+ const hash = await walletClient.writeContract(request);
144
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
145
+
146
+ logFailure(receipt);
147
+
148
+ expect(receipt.status).toBe("success");
149
+
150
+ expect(
151
+ await minterIsMinterOnToken({
152
+ contractAddress,
153
+ tokenId: newTokenId,
154
+ minter:
155
+ zoraTimedSaleStrategyAddress[
156
+ chain.id as keyof typeof zoraTimedSaleStrategyAddress
157
+ ],
158
+ publicClient,
159
+ }),
160
+ ).toBe(true);
161
+ },
162
+ 20 * 1000,
163
+ );
164
+
165
+ anvilTest(
166
+ "can create a new contract, then can create a new token on this existing contract",
167
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
168
+ const addresses = await walletClient.getAddresses();
169
+ const creatorAccount = addresses[0]!;
170
+
171
+ const creatorClient = createCreatorClient({
172
+ chainId: chain.id,
173
+ publicClient: publicClient,
73
174
  });
74
- expect(contractAddress).to.be.equal(
75
- "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
76
- );
77
- expect(contractExists).to.be.false;
175
+
176
+ const { parameters: request, contractAddress: contractAddress } =
177
+ await creatorClient.create1155({
178
+ contract: randomNewContract(),
179
+ token: {
180
+ tokenMetadataURI: demoTokenMetadataURI,
181
+ mintToCreatorCount: 3,
182
+ },
183
+ account: creatorAccount,
184
+ });
78
185
  const { request: simulateResponse } =
79
186
  await publicClient.simulateContract(request);
80
187
  const hash = await walletClient.writeContract(simulateResponse);
81
188
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
189
+ logFailure(receipt);
190
+ expect(receipt.status).toBe("success");
82
191
  const firstTokenId = getTokenIdFromCreateReceipt(receipt);
83
192
  expect(firstTokenId).to.be.equal(1n);
84
193
  expect(receipt).not.toBeNull();
@@ -93,21 +202,15 @@ describe("create-helper", () => {
93
202
  }),
94
203
  ).toBe(3n);
95
204
 
96
- const newTokenOnExistingContract = await creatorClient.create1155({
97
- contract: {
98
- name: "testContract2",
99
- uri: demoContractMetadataURI,
100
- },
101
- token: {
102
- tokenMetadataURI: demoTokenMetadataURI,
103
- mintToCreatorCount: 2,
104
- },
105
- account: creatorAccount,
106
- });
107
- expect(newTokenOnExistingContract.collectionAddress).to.be.equal(
108
- "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
109
- );
110
- expect(newTokenOnExistingContract.contractExists).to.be.true;
205
+ const newTokenOnExistingContract =
206
+ await creatorClient.create1155OnExistingContract({
207
+ contractAddress: contractAddress,
208
+ token: {
209
+ tokenMetadataURI: demoTokenMetadataURI,
210
+ mintToCreatorCount: 2,
211
+ },
212
+ account: creatorAccount,
213
+ });
111
214
  const { request: simulateRequest } = await publicClient.simulateContract(
112
215
  newTokenOnExistingContract.parameters,
113
216
  );
@@ -115,9 +218,12 @@ describe("create-helper", () => {
115
218
  const newReceipt = await publicClient.waitForTransactionReceipt({
116
219
  hash: newHash,
117
220
  });
221
+
222
+ logFailure(receipt);
223
+
224
+ expect(newReceipt.status).toBe("success");
118
225
  const tokenId = getTokenIdFromCreateReceipt(newReceipt);
119
226
  expect(tokenId).to.be.equal(2n);
120
- expect(newReceipt).not.toBeNull();
121
227
  },
122
228
  20 * 1000,
123
229
  );
@@ -132,11 +238,12 @@ describe("create-helper", () => {
132
238
  chainId: chain.id,
133
239
  publicClient: publicClient,
134
240
  });
135
- const { parameters: request } = await creatorClient.create1155({
136
- contract: {
137
- name: "testContract",
138
- uri: demoContractMetadataURI,
139
- },
241
+ const {
242
+ parameters: request,
243
+ contractAddress: collectionAddress,
244
+ newTokenId,
245
+ } = await creatorClient.create1155({
246
+ contract: randomNewContract(),
140
247
  token: {
141
248
  tokenMetadataURI: demoTokenMetadataURI,
142
249
  createReferral,
@@ -147,16 +254,16 @@ describe("create-helper", () => {
147
254
  await publicClient.simulateContract(request);
148
255
  const hash = await walletClient.writeContract(simulationResponse);
149
256
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
150
- expect(receipt).not.toBeNull();
151
- expect(receipt.to).to.equal("0xa72724cc3dcef210141a1b84c61824074151dc99");
152
- expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(2n);
257
+ expect(receipt.status).toBe("success");
258
+ expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
259
+ expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
153
260
 
154
261
  expect(
155
262
  await publicClient.readContract({
156
263
  abi: zoraCreator1155ImplABI,
157
- address: "0xa72724cc3dcef210141a1b84c61824074151dc99",
264
+ address: collectionAddress,
158
265
  functionName: "createReferrals",
159
- args: [2n],
266
+ args: [newTokenId],
160
267
  }),
161
268
  ).to.be.equal(createReferral);
162
269
  },
@@ -177,15 +284,12 @@ describe("create-helper", () => {
177
284
  });
178
285
  const {
179
286
  parameters: request,
180
- collectionAddress,
181
287
  newTokenId,
182
- newToken,
183
288
  minter,
289
+ contractAddress: collectionAddress,
290
+ contractVersion,
184
291
  } = await creatorClient.create1155({
185
- contract: {
186
- name: "testContract",
187
- uri: demoContractMetadataURI,
188
- },
292
+ contract: randomNewContract(),
189
293
  token: {
190
294
  tokenMetadataURI: demoTokenMetadataURI,
191
295
  },
@@ -198,20 +302,6 @@ describe("create-helper", () => {
198
302
  publicClient,
199
303
  );
200
304
 
201
- const salesConfigAndTokenInfo: MintableParameters = {
202
- mintFeePerQuantity: parseEther("0.000777"),
203
- contractVersion: "2.8.0",
204
- salesConfig: {
205
- saleType: "fixedPrice",
206
- address: minter,
207
- pricePerToken: newToken.salesConfig.pricePerToken,
208
- // these dont matter
209
- maxTokensPerAddress: 0n,
210
- saleEnd: "",
211
- saleStart: "",
212
- },
213
- };
214
-
215
305
  const quantityToMint = 5n;
216
306
 
217
307
  // now try to mint a free mint
@@ -226,7 +316,21 @@ describe("create-helper", () => {
226
316
  tokenContract: collectionAddress,
227
317
  minterAccount: minterAddress,
228
318
  tokenId: newTokenId,
229
- salesConfigAndTokenInfo,
319
+ salesConfigAndTokenInfo: {
320
+ contractVersion,
321
+ salesConfig: {
322
+ saleType: "timed",
323
+ address: minter,
324
+ // below fields arent used when determining mint price for minting
325
+ saleEnd: "",
326
+ saleStart: "",
327
+ erc20Z: zeroAddress,
328
+ pool: zeroAddress,
329
+ secondaryActivated: false,
330
+ mintFeePerQuantity: parseEther("0.000111"),
331
+ mintFee: 0n,
332
+ },
333
+ },
230
334
  quantityToMint,
231
335
  });
232
336
 
@@ -241,7 +345,7 @@ describe("create-helper", () => {
241
345
  );
242
346
 
243
347
  anvilTest(
244
- "creates a new 1155 paid mint that can be minted",
348
+ "creates a new 1155 paid mint that can be minted using the fixed price minter",
245
349
  async ({
246
350
  viemClients: { testClient, publicClient, walletClient, chain },
247
351
  }) => {
@@ -257,15 +361,12 @@ describe("create-helper", () => {
257
361
 
258
362
  const {
259
363
  parameters: request,
260
- collectionAddress,
364
+ contractAddress: collectionAddress,
261
365
  newTokenId,
262
- newToken,
263
366
  minter,
367
+ contractVersion,
264
368
  } = await creatorClient.create1155({
265
- contract: {
266
- name: "testContract",
267
- uri: demoContractMetadataURI,
268
- },
369
+ contract: randomNewContract(),
269
370
  token: {
270
371
  tokenMetadataURI: demoTokenMetadataURI,
271
372
  salesConfig: {
@@ -281,20 +382,6 @@ describe("create-helper", () => {
281
382
  publicClient,
282
383
  );
283
384
 
284
- const salesConfigAndTokenInfo: MintableParameters = {
285
- mintFeePerQuantity: parseEther("0.000777"),
286
- contractVersion: "2.8.0",
287
- salesConfig: {
288
- saleType: "fixedPrice",
289
- address: minter,
290
- pricePerToken: newToken.salesConfig.pricePerToken,
291
- // these dont matter
292
- maxTokensPerAddress: 0n,
293
- saleEnd: "",
294
- saleStart: "",
295
- },
296
- };
297
-
298
385
  const quantityToMint = 5n;
299
386
 
300
387
  // now try to mint a free mint
@@ -309,7 +396,23 @@ describe("create-helper", () => {
309
396
  tokenContract: collectionAddress,
310
397
  minterAccount: minterAddress,
311
398
  tokenId: newTokenId,
312
- salesConfigAndTokenInfo,
399
+ salesConfigAndTokenInfo: {
400
+ contractVersion,
401
+ salesConfig: {
402
+ mintFeePerQuantity: await publicClient.readContract({
403
+ abi: zoraCreator1155ImplABI,
404
+ functionName: "mintFee",
405
+ address: collectionAddress,
406
+ }),
407
+ saleType: "fixedPrice",
408
+ address: minter,
409
+ pricePerToken,
410
+ // these dont matter
411
+ maxTokensPerAddress: 0n,
412
+ saleEnd: "",
413
+ saleStart: "",
414
+ },
415
+ },
313
416
  quantityToMint,
314
417
  });
315
418
 
@@ -322,4 +425,57 @@ describe("create-helper", () => {
322
425
  },
323
426
  20 * 1000,
324
427
  );
428
+
429
+ anvilTest(
430
+ "creates an allow list mint contract",
431
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
432
+ const creator = (await walletClient.getAddresses())[0]!;
433
+ const allowList: AllowList = {
434
+ entries: [
435
+ {
436
+ user: "0xf69fEc6d858c77e969509843852178bd24CAd2B6",
437
+ price: 2n,
438
+ maxCanMint: 10000,
439
+ },
440
+ {
441
+ user: "0xcD08da546414dd463C89705B5E72CE1AeebF1567",
442
+ price: 3n,
443
+ maxCanMint: 10,
444
+ },
445
+ ],
446
+ };
447
+
448
+ const root = await createAllowList({
449
+ allowList,
450
+ });
451
+
452
+ const creatorClient = createCreatorClient({
453
+ chainId: chain.id,
454
+ publicClient: publicClient,
455
+ });
456
+
457
+ const { parameters } = await creatorClient.create1155({
458
+ contract: {
459
+ name: "test allowlists",
460
+ uri: "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
461
+ },
462
+ token: {
463
+ tokenMetadataURI:
464
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
465
+ salesConfig: {
466
+ type: "allowlistMint",
467
+ presaleMerkleRoot: `0x${root}`,
468
+ },
469
+ },
470
+ account: creator,
471
+ });
472
+
473
+ const { request } = await publicClient.simulateContract(parameters);
474
+
475
+ await waitForSuccess(
476
+ await walletClient.writeContract(request),
477
+ publicClient,
478
+ );
479
+ },
480
+ );
325
481
  });