@zoralabs/protocol-sdk 0.8.0 → 0.9.1

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 (79) 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.map +1 -1
  13. package/dist/create/contract-setup.d.ts +1 -0
  14. package/dist/create/contract-setup.d.ts.map +1 -1
  15. package/dist/create/mint-from-create.d.ts +12 -0
  16. package/dist/create/mint-from-create.d.ts.map +1 -0
  17. package/dist/create/minter-defaults.d.ts +5 -0
  18. package/dist/create/minter-defaults.d.ts.map +1 -0
  19. package/dist/create/minter-setup.d.ts +14 -0
  20. package/dist/create/minter-setup.d.ts.map +1 -0
  21. package/dist/create/token-setup.d.ts +4 -19
  22. package/dist/create/token-setup.d.ts.map +1 -1
  23. package/dist/create/types.d.ts +34 -7
  24. package/dist/create/types.d.ts.map +1 -1
  25. package/dist/create/update.d.ts +15 -0
  26. package/dist/create/update.d.ts.map +1 -0
  27. package/dist/index.cjs +2359 -1932
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2379 -1947
  32. package/dist/index.js.map +1 -1
  33. package/dist/ipfs/token-metadata.d.ts +1 -0
  34. package/dist/ipfs/token-metadata.d.ts.map +1 -1
  35. package/dist/mint/mint-client.d.ts +2 -6
  36. package/dist/mint/mint-client.d.ts.map +1 -1
  37. package/dist/mint/mint-queries.d.ts +6 -2
  38. package/dist/mint/mint-queries.d.ts.map +1 -1
  39. package/dist/mint/mint-transactions.d.ts +9 -7
  40. package/dist/mint/mint-transactions.d.ts.map +1 -1
  41. package/dist/mint/subgraph-mint-getter.d.ts +5 -4
  42. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  43. package/dist/mint/subgraph-queries.d.ts +42 -15
  44. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  45. package/dist/mint/types.d.ts +33 -13
  46. package/dist/mint/types.d.ts.map +1 -1
  47. package/dist/sparks/sparks-contracts.d.ts +96 -96
  48. package/dist/types.d.ts +1 -1
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/utils.d.ts +1 -8
  51. package/dist/utils.d.ts.map +1 -1
  52. package/package.json +2 -2
  53. package/src/allow-list/allow-list-client.ts +105 -0
  54. package/src/allow-list/types.ts +15 -0
  55. package/src/apis/generated/allow-list-api-types.ts +288 -0
  56. package/src/apis/http-api-base.ts +12 -0
  57. package/src/apis/subgraph-querier.ts +38 -0
  58. package/src/create/1155-create-helper.test.ts +217 -89
  59. package/src/create/1155-create-helper.ts +25 -4
  60. package/src/create/contract-setup.ts +8 -0
  61. package/src/create/mint-from-create.ts +119 -0
  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 +58 -9
  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 +40 -19
  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 +58 -16
  77. package/src/premint/premint-client.test.ts +6 -5
  78. package/src/types.ts +1 -1
  79. package/src/utils.ts +1 -25
@@ -4,18 +4,22 @@ import {
4
4
  getTokenIdFromCreateReceipt,
5
5
  } from "./1155-create-helper";
6
6
  import { createCreatorClient } from "src/sdk";
7
- import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
8
- import { waitForSuccess } from "src/test-utils";
9
- import { parseEther } from "viem";
10
7
  import {
11
- MintableParameters,
12
- makePrepareMint1155TokenParams,
13
- } from "src/mint/mint-transactions";
8
+ zoraCreator1155ImplABI,
9
+ zoraTimedSaleStrategyAddress,
10
+ } from "@zoralabs/protocol-deployments";
11
+ import { waitForSuccess } from "src/test-utils";
12
+ import { Address, parseEther, PublicClient, TransactionReceipt } from "viem";
13
+ import { makePrepareMint1155TokenParams } from "src/mint/mint-transactions";
14
14
  import { forkUrls, makeAnvilTest } from "src/anvil";
15
15
  import { zora } from "viem/chains";
16
+ import { AllowList } from "src/allow-list/types";
17
+ import { createAllowList } from "src/allow-list/allow-list-client";
18
+ import { NewContractParams } from "./types";
16
19
 
17
- const demoTokenMetadataURI = "ipfs://DUMMY/token.json";
18
- const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
20
+ export const demoTokenMetadataURI =
21
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
22
+ export const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
19
23
 
20
24
  const anvilTest = makeAnvilTest({
21
25
  forkUrl: forkUrls.zoraMainnet,
@@ -23,9 +27,46 @@ const anvilTest = makeAnvilTest({
23
27
  anvilChainId: zora.id,
24
28
  });
25
29
 
30
+ const PERMISSION_BITS = {
31
+ MINTER: 2n ** 2n,
32
+ };
33
+
34
+ const minterIsMinterOnToken = async ({
35
+ publicClient,
36
+ contractAddress,
37
+ tokenId,
38
+ minter,
39
+ }: {
40
+ publicClient: Pick<PublicClient, "readContract">;
41
+ contractAddress: Address;
42
+ tokenId: bigint;
43
+ minter: Address;
44
+ }) => {
45
+ return await publicClient.readContract({
46
+ abi: zoraCreator1155ImplABI,
47
+ address: contractAddress,
48
+ functionName: "isAdminOrRole",
49
+ args: [minter, tokenId, PERMISSION_BITS.MINTER],
50
+ });
51
+ };
52
+
53
+ function logFailure(receipt: TransactionReceipt) {
54
+ if (receipt.status !== "success") {
55
+ console.log("transaction failed");
56
+ console.log(receipt.logs);
57
+ }
58
+ }
59
+
60
+ function randomNewContract(): NewContractParams {
61
+ return {
62
+ name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
63
+ uri: demoContractMetadataURI,
64
+ };
65
+ }
66
+
26
67
  describe("create-helper", () => {
27
68
  anvilTest(
28
- "creates a new 1155 contract and token",
69
+ "when no sales config is provided, it creates a new 1155 contract and token using the timed sale strategy",
29
70
  async ({ viemClients: { publicClient, walletClient, chain } }) => {
30
71
  const addresses = await walletClient.getAddresses();
31
72
  const creatorAddress = addresses[0]!;
@@ -34,32 +75,95 @@ describe("create-helper", () => {
34
75
  chainId: chain.id,
35
76
  publicClient: publicClient,
36
77
  });
37
- const { parameters, contractAddress: collectionAddress } =
38
- await creatorClient.create1155({
39
- contract: {
40
- name: "testContract",
41
- uri: demoContractMetadataURI,
42
- },
43
- token: {
44
- tokenMetadataURI: demoTokenMetadataURI,
45
- mintToCreatorCount: 1,
46
- },
47
- account: creatorAddress,
48
- });
78
+ const {
79
+ parameters: parameters,
80
+ contractAddress,
81
+ newTokenId,
82
+ } = await creatorClient.create1155({
83
+ contract: randomNewContract(),
84
+ token: {
85
+ tokenMetadataURI: demoTokenMetadataURI,
86
+ mintToCreatorCount: 1,
87
+ },
88
+ account: creatorAddress,
89
+ });
90
+
49
91
  const { request } = await publicClient.simulateContract(parameters);
50
92
  const hash = await walletClient.writeContract(request);
51
93
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
94
+ logFailure(receipt);
95
+ expect(receipt.status).toBe("success");
52
96
  expect(receipt).not.toBeNull();
53
97
  expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
54
98
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
55
99
  expect(getContractAddressFromReceipt(receipt)).to.be.equal(
56
- collectionAddress,
100
+ contractAddress,
57
101
  );
102
+
103
+ expect(
104
+ await minterIsMinterOnToken({
105
+ contractAddress,
106
+ tokenId: newTokenId,
107
+ publicClient,
108
+ minter:
109
+ zoraTimedSaleStrategyAddress[
110
+ chain.id as keyof typeof zoraTimedSaleStrategyAddress
111
+ ],
112
+ }),
113
+ ).toBe(true);
58
114
  },
59
115
  20 * 1000,
60
116
  );
61
117
  anvilTest(
62
- "creates a new contract, then can create a new token on this existing contract",
118
+ "when price is set to 0, it creates a new 1155 contract and token using the timed sale strategy",
119
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
120
+ const addresses = await walletClient.getAddresses();
121
+ const creatorAddress = addresses[0]!;
122
+
123
+ const creatorClient = createCreatorClient({
124
+ chainId: chain.id,
125
+ publicClient: publicClient,
126
+ });
127
+ const {
128
+ parameters: parameters,
129
+ contractAddress,
130
+ newTokenId,
131
+ } = await creatorClient.create1155({
132
+ contract: randomNewContract(),
133
+ token: {
134
+ tokenMetadataURI: demoTokenMetadataURI,
135
+ salesConfig: {
136
+ pricePerToken: 0n,
137
+ },
138
+ },
139
+ account: creatorAddress,
140
+ });
141
+
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",
63
167
  async ({ viemClients: { publicClient, walletClient, chain } }) => {
64
168
  const addresses = await walletClient.getAddresses();
65
169
  const creatorAccount = addresses[0]!;
@@ -71,10 +175,7 @@ describe("create-helper", () => {
71
175
 
72
176
  const { parameters: request, contractAddress: contractAddress } =
73
177
  await creatorClient.create1155({
74
- contract: {
75
- name: "testContract2",
76
- uri: demoContractMetadataURI,
77
- },
178
+ contract: randomNewContract(),
78
179
  token: {
79
180
  tokenMetadataURI: demoTokenMetadataURI,
80
181
  mintToCreatorCount: 3,
@@ -85,6 +186,8 @@ describe("create-helper", () => {
85
186
  await publicClient.simulateContract(request);
86
187
  const hash = await walletClient.writeContract(simulateResponse);
87
188
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
189
+ logFailure(receipt);
190
+ expect(receipt.status).toBe("success");
88
191
  const firstTokenId = getTokenIdFromCreateReceipt(receipt);
89
192
  expect(firstTokenId).to.be.equal(1n);
90
193
  expect(receipt).not.toBeNull();
@@ -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
  );
@@ -137,10 +243,7 @@ describe("create-helper", () => {
137
243
  contractAddress: collectionAddress,
138
244
  newTokenId,
139
245
  } = await creatorClient.create1155({
140
- contract: {
141
- name: "testContract",
142
- uri: demoContractMetadataURI,
143
- },
246
+ contract: randomNewContract(),
144
247
  token: {
145
248
  tokenMetadataURI: demoTokenMetadataURI,
146
249
  createReferral,
@@ -151,7 +254,7 @@ describe("create-helper", () => {
151
254
  await publicClient.simulateContract(request);
152
255
  const hash = await walletClient.writeContract(simulationResponse);
153
256
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
154
- expect(receipt).not.toBeNull();
257
+ expect(receipt.status).toBe("success");
155
258
  expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
156
259
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
157
260
 
@@ -179,23 +282,14 @@ describe("create-helper", () => {
179
282
  chainId: chain.id,
180
283
  publicClient: publicClient,
181
284
  });
182
- const {
183
- parameters: request,
184
- newTokenId,
185
- newToken,
186
- minter,
187
- contractAddress: collectionAddress,
188
- contractVersion,
189
- } = await creatorClient.create1155({
190
- contract: {
191
- name: "testContract",
192
- uri: demoContractMetadataURI,
193
- },
194
- token: {
195
- tokenMetadataURI: demoTokenMetadataURI,
196
- },
197
- account: creatorAddress,
198
- });
285
+ const { parameters: request, prepareMint } =
286
+ await creatorClient.create1155({
287
+ contract: randomNewContract(),
288
+ token: {
289
+ tokenMetadataURI: demoTokenMetadataURI,
290
+ },
291
+ account: creatorAddress,
292
+ });
199
293
  const { request: createSimulation } =
200
294
  await publicClient.simulateContract(request);
201
295
  await waitForSuccess(
@@ -203,20 +297,6 @@ describe("create-helper", () => {
203
297
  publicClient,
204
298
  );
205
299
 
206
- const salesConfigAndTokenInfo: MintableParameters = {
207
- mintFeePerQuantity: parseEther("0.000777"),
208
- contractVersion,
209
- salesConfig: {
210
- saleType: "fixedPrice",
211
- address: minter,
212
- pricePerToken: newToken.salesConfig.pricePerToken,
213
- // these dont matter
214
- maxTokensPerAddress: 0n,
215
- saleEnd: "",
216
- saleStart: "",
217
- },
218
- };
219
-
220
300
  const quantityToMint = 5n;
221
301
 
222
302
  // now try to mint a free mint
@@ -227,11 +307,8 @@ describe("create-helper", () => {
227
307
  value: parseEther("10"),
228
308
  });
229
309
 
230
- const mintParams = makePrepareMint1155TokenParams({
231
- tokenContract: collectionAddress,
310
+ const { parameters: mintParams } = await prepareMint({
232
311
  minterAccount: minterAddress,
233
- tokenId: newTokenId,
234
- salesConfigAndTokenInfo,
235
312
  quantityToMint,
236
313
  });
237
314
 
@@ -246,7 +323,7 @@ describe("create-helper", () => {
246
323
  );
247
324
 
248
325
  anvilTest(
249
- "creates a new 1155 paid mint that can be minted",
326
+ "creates a new 1155 paid mint that can be minted using the fixed price minter",
250
327
  async ({
251
328
  viemClients: { testClient, publicClient, walletClient, chain },
252
329
  }) => {
@@ -264,14 +341,10 @@ describe("create-helper", () => {
264
341
  parameters: request,
265
342
  contractAddress: collectionAddress,
266
343
  newTokenId,
267
- newToken,
268
344
  minter,
269
345
  contractVersion,
270
346
  } = await creatorClient.create1155({
271
- contract: {
272
- name: "testContract",
273
- uri: demoContractMetadataURI,
274
- },
347
+ contract: randomNewContract(),
275
348
  token: {
276
349
  tokenMetadataURI: demoTokenMetadataURI,
277
350
  salesConfig: {
@@ -287,20 +360,6 @@ describe("create-helper", () => {
287
360
  publicClient,
288
361
  );
289
362
 
290
- const salesConfigAndTokenInfo: MintableParameters = {
291
- mintFeePerQuantity: parseEther("0.000777"),
292
- contractVersion,
293
- salesConfig: {
294
- saleType: "fixedPrice",
295
- address: minter,
296
- pricePerToken: newToken.salesConfig.pricePerToken,
297
- // these dont matter
298
- maxTokensPerAddress: 0n,
299
- saleEnd: "",
300
- saleStart: "",
301
- },
302
- };
303
-
304
363
  const quantityToMint = 5n;
305
364
 
306
365
  // now try to mint a free mint
@@ -315,7 +374,23 @@ describe("create-helper", () => {
315
374
  tokenContract: collectionAddress,
316
375
  minterAccount: minterAddress,
317
376
  tokenId: newTokenId,
318
- salesConfigAndTokenInfo,
377
+ salesConfigAndTokenInfo: {
378
+ contractVersion,
379
+ salesConfig: {
380
+ mintFeePerQuantity: await publicClient.readContract({
381
+ abi: zoraCreator1155ImplABI,
382
+ functionName: "mintFee",
383
+ address: collectionAddress,
384
+ }),
385
+ saleType: "fixedPrice",
386
+ address: minter,
387
+ pricePerToken,
388
+ // these dont matter
389
+ maxTokensPerAddress: 0n,
390
+ saleEnd: "",
391
+ saleStart: "",
392
+ },
393
+ },
319
394
  quantityToMint,
320
395
  });
321
396
 
@@ -328,4 +403,57 @@ describe("create-helper", () => {
328
403
  },
329
404
  20 * 1000,
330
405
  );
406
+
407
+ anvilTest(
408
+ "creates an allow list mint contract",
409
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
410
+ const creator = (await walletClient.getAddresses())[0]!;
411
+ const allowList: AllowList = {
412
+ entries: [
413
+ {
414
+ user: "0xf69fEc6d858c77e969509843852178bd24CAd2B6",
415
+ price: 2n,
416
+ maxCanMint: 10000,
417
+ },
418
+ {
419
+ user: "0xcD08da546414dd463C89705B5E72CE1AeebF1567",
420
+ price: 3n,
421
+ maxCanMint: 10,
422
+ },
423
+ ],
424
+ };
425
+
426
+ const root = await createAllowList({
427
+ allowList,
428
+ });
429
+
430
+ const creatorClient = createCreatorClient({
431
+ chainId: chain.id,
432
+ publicClient: publicClient,
433
+ });
434
+
435
+ const { parameters: parameters } = await creatorClient.create1155({
436
+ contract: {
437
+ name: "test allowlists",
438
+ uri: "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
439
+ },
440
+ token: {
441
+ tokenMetadataURI:
442
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
443
+ salesConfig: {
444
+ type: "allowlistMint",
445
+ presaleMerkleRoot: `0x${root}`,
446
+ },
447
+ },
448
+ account: creator,
449
+ });
450
+
451
+ const { request } = await publicClient.simulateContract(parameters);
452
+
453
+ await waitForSuccess(
454
+ await walletClient.writeContract(request),
455
+ publicClient,
456
+ );
457
+ },
458
+ );
331
459
  });
@@ -26,6 +26,7 @@ import {
26
26
  NewContractParams,
27
27
  } from "./types";
28
28
  import { constructCreate1155TokenCalls } from "./token-setup";
29
+ import { makeOnchainPrepareMintFromCreate } from "./mint-from-create";
29
30
 
30
31
  // Default royalty bps
31
32
  const ROYALTY_BPS_DEFAULT = 1000;
@@ -192,7 +193,7 @@ async function createNew1155ContractAndToken({
192
193
  minter,
193
194
  newToken,
194
195
  setupActions: tokenSetupActions,
195
- } = prepareSetupActions({
196
+ } = await prepareSetupActions({
196
197
  chainId,
197
198
  account,
198
199
  contractVersion,
@@ -218,6 +219,15 @@ async function createNew1155ContractAndToken({
218
219
  contract,
219
220
  });
220
221
 
222
+ const prepareMint = makeOnchainPrepareMintFromCreate({
223
+ contractAddress: contractAddress,
224
+ contractVersion,
225
+ minter,
226
+ publicClient,
227
+ result: newToken.salesConfig,
228
+ tokenId: nextTokenId,
229
+ });
230
+
221
231
  return {
222
232
  parameters: request,
223
233
  tokenSetupActions,
@@ -226,6 +236,7 @@ async function createNew1155ContractAndToken({
226
236
  contractAddress: contractAddress,
227
237
  contractVersion,
228
238
  minter,
239
+ prepareMint,
229
240
  };
230
241
  }
231
242
 
@@ -250,7 +261,7 @@ async function createNew1155Token({
250
261
  minter,
251
262
  newToken,
252
263
  setupActions: tokenSetupActions,
253
- } = prepareSetupActions({
264
+ } = await prepareSetupActions({
254
265
  chainId,
255
266
  account,
256
267
  contractVersion,
@@ -265,6 +276,15 @@ async function createNew1155Token({
265
276
  tokenSetupActions,
266
277
  });
267
278
 
279
+ const prepareMint = makeOnchainPrepareMintFromCreate({
280
+ contractAddress: contractAddress,
281
+ contractVersion,
282
+ minter,
283
+ publicClient,
284
+ result: newToken.salesConfig,
285
+ tokenId: nextTokenId,
286
+ });
287
+
268
288
  return {
269
289
  parameters: request,
270
290
  tokenSetupActions,
@@ -272,10 +292,11 @@ async function createNew1155Token({
272
292
  newToken,
273
293
  contractVersion,
274
294
  minter,
295
+ prepareMint,
275
296
  };
276
297
  }
277
298
 
278
- function prepareSetupActions({
299
+ async function prepareSetupActions({
279
300
  chainId,
280
301
  account,
281
302
  contractVersion,
@@ -291,7 +312,7 @@ function prepareSetupActions({
291
312
  minter,
292
313
  newToken,
293
314
  setupActions: tokenSetupActions,
294
- } = constructCreate1155TokenCalls({
315
+ } = await constructCreate1155TokenCalls({
295
316
  chainId: chainId,
296
317
  ownerAddress: account,
297
318
  contractVersion,
@@ -27,6 +27,7 @@ export async function getContractInfoExistingContract({
27
27
  // Account that is the creator of the contract
28
28
  }): Promise<{
29
29
  contractVersion: string;
30
+ contractName: string;
30
31
  nextTokenId: bigint;
31
32
  }> {
32
33
  // Check if contract exists either from metadata or the static address passed in.
@@ -50,8 +51,15 @@ export async function getContractInfoExistingContract({
50
51
  functionName: "nextTokenId",
51
52
  });
52
53
 
54
+ const contractName = await publicClient.readContract({
55
+ address: contractAddress,
56
+ abi: zoraCreator1155ImplABI,
57
+ functionName: "name",
58
+ });
59
+
53
60
  return {
54
61
  contractVersion,
62
+ contractName,
55
63
  nextTokenId,
56
64
  };
57
65
  }
@@ -0,0 +1,119 @@
1
+ import { Address, parseEther, PublicClient, zeroAddress } from "viem";
2
+ import { ConcreteSalesConfig } from "./types";
3
+ import {
4
+ AsyncPrepareMint,
5
+ MintParametersBase,
6
+ OnchainSalesStrategies,
7
+ PrepareMintReturn,
8
+ } from "src/mint/types";
9
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
10
+ import {
11
+ makePrepareMint1155TokenParams,
12
+ parseMintCosts,
13
+ } from "src/mint/mint-transactions";
14
+ import { getRequiredErc20Approvals } from "src/mint/mint-queries";
15
+
16
+ async function toSalesStrategyFromSubgraph({
17
+ minter,
18
+ salesConfig,
19
+ publicClient,
20
+ contractAddress,
21
+ }: {
22
+ minter: Address;
23
+ salesConfig: ConcreteSalesConfig;
24
+ publicClient: Pick<PublicClient, "readContract">;
25
+ contractAddress: Address;
26
+ }): Promise<OnchainSalesStrategies> {
27
+ if (salesConfig.type === "timed") {
28
+ return {
29
+ saleType: "timed",
30
+ address: minter,
31
+ // for now we hardcode this
32
+ mintFeePerQuantity: parseEther("0.000111"),
33
+ saleStart: salesConfig.saleStart.toString(),
34
+ saleEnd: salesConfig.saleEnd.toString(),
35
+ // the following are not needed for now but we wanna satisfy concrete
36
+ erc20Z: zeroAddress,
37
+ mintFee: 0n,
38
+ pool: zeroAddress,
39
+ secondaryActivated: false,
40
+ };
41
+ }
42
+ if (salesConfig.type === "erc20Mint") {
43
+ return {
44
+ saleType: "erc20",
45
+ address: minter,
46
+ mintFeePerQuantity: 0n,
47
+ saleStart: salesConfig.saleStart.toString(),
48
+ saleEnd: salesConfig.saleEnd.toString(),
49
+ currency: salesConfig.currency,
50
+ pricePerToken: salesConfig.pricePerToken,
51
+ maxTokensPerAddress: salesConfig.maxTokensPerAddress,
52
+ };
53
+ }
54
+ const contractMintFee = await publicClient.readContract({
55
+ abi: zoraCreator1155ImplABI,
56
+ address: contractAddress,
57
+ functionName: "mintFee",
58
+ });
59
+ if (salesConfig.type === "fixedPrice") {
60
+ return {
61
+ saleType: "fixedPrice",
62
+ address: minter,
63
+ maxTokensPerAddress: salesConfig.maxTokensPerAddress,
64
+ mintFeePerQuantity: contractMintFee,
65
+ pricePerToken: salesConfig.pricePerToken,
66
+ saleStart: salesConfig.saleStart.toString(),
67
+ saleEnd: salesConfig.saleEnd.toString(),
68
+ };
69
+ }
70
+ return {
71
+ saleType: "allowlist",
72
+ address: minter,
73
+ saleStart: salesConfig.saleStart.toString(),
74
+ saleEnd: salesConfig.saleEnd.toString(),
75
+ merkleRoot: salesConfig.presaleMerkleRoot,
76
+ mintFeePerQuantity: contractMintFee,
77
+ };
78
+ }
79
+ export function makeOnchainPrepareMintFromCreate({
80
+ contractAddress,
81
+ tokenId,
82
+ result,
83
+ minter,
84
+ publicClient,
85
+ contractVersion,
86
+ }: {
87
+ contractAddress: Address;
88
+ tokenId: bigint;
89
+ result: ConcreteSalesConfig;
90
+ minter: Address;
91
+ publicClient: Pick<PublicClient, "readContract">;
92
+ contractVersion: string;
93
+ }): AsyncPrepareMint {
94
+ return async (params: MintParametersBase): Promise<PrepareMintReturn> => {
95
+ const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
96
+ minter,
97
+ contractAddress,
98
+ publicClient,
99
+ salesConfig: result,
100
+ });
101
+ return {
102
+ parameters: makePrepareMint1155TokenParams({
103
+ salesConfigAndTokenInfo: {
104
+ salesConfig: subgraphSalesConfig,
105
+ contractVersion,
106
+ },
107
+ ...params,
108
+ tokenContract: contractAddress,
109
+ tokenId,
110
+ }),
111
+ costs: parseMintCosts({
112
+ allowListEntry: params.allowListEntry,
113
+ quantityToMint: BigInt(params.quantityToMint),
114
+ salesConfig: subgraphSalesConfig,
115
+ }),
116
+ erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig),
117
+ };
118
+ };
119
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, it, expect, assert } from "vitest";
2
+ import { parseNameIntoSymbol } from "./minter-defaults";
3
+
4
+ describe("parseNameIntoSymbol", () => {
5
+ it("removes spaces and vowels and converts to uppercase", () => {
6
+ const symbol = parseNameIntoSymbol("My 4 To *5 @-Name");
7
+
8
+ expect(symbol).toBe("$MY4T");
9
+ });
10
+ it("works with less than 4 characters", () => {
11
+ const symbol = parseNameIntoSymbol("M4y a");
12
+
13
+ expect(symbol).toBe("$M4Y");
14
+ });
15
+
16
+ it("works with no characters", () => {
17
+ assert.throws(() => {
18
+ parseNameIntoSymbol("AEIO U");
19
+ }, "Not enough valid characters to generate a symbol");
20
+ });
21
+ });