@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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +21 -0
- package/README.md +243 -79
- package/dist/apis/http-api-base.d.ts +6 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/index.cjs +363 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +350 -226
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +216 -12
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +53 -14
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +13 -6
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +14 -16
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/http-api-base.ts +12 -0
- package/src/mint/mint-api-client.ts +71 -34
- package/src/mint/mint-client.test.ts +23 -27
- package/src/mint/mint-client.ts +321 -153
- package/src/premint/premint-api-client.ts +72 -18
- package/src/premint/premint-client.test.ts +23 -18
- package/src/premint/premint-client.ts +35 -48
package/dist/index.cjs
CHANGED
|
@@ -33,15 +33,16 @@ __export(src_exports, {
|
|
|
33
33
|
createMintClient: () => createMintClient,
|
|
34
34
|
createPremintClient: () => createPremintClient,
|
|
35
35
|
encodePremintForAPI: () => encodePremintForAPI,
|
|
36
|
+
get1155MintCosts: () => get1155MintCosts,
|
|
37
|
+
getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
|
|
36
38
|
getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
|
|
37
|
-
getSalesConfigFixedPrice: () => getSalesConfigFixedPrice,
|
|
38
39
|
getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
|
|
39
40
|
preminterTypedDataDefinition: () => preminterTypedDataDefinition
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(src_exports);
|
|
42
43
|
|
|
43
44
|
// src/premint/premint-client.ts
|
|
44
|
-
var
|
|
45
|
+
var import_viem2 = require("viem");
|
|
45
46
|
var import_protocol_deployments = require("@zoralabs/protocol-deployments");
|
|
46
47
|
|
|
47
48
|
// src/premint/preminter.ts
|
|
@@ -162,6 +163,11 @@ var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
|
|
|
162
163
|
throw err;
|
|
163
164
|
}
|
|
164
165
|
};
|
|
166
|
+
var httpClient = {
|
|
167
|
+
get,
|
|
168
|
+
post,
|
|
169
|
+
retries
|
|
170
|
+
};
|
|
165
171
|
|
|
166
172
|
// src/constants.ts
|
|
167
173
|
var ZORA_API_BASE = "https://api.zora.co/";
|
|
@@ -171,29 +177,6 @@ function getSubgraph(name, version) {
|
|
|
171
177
|
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
172
178
|
}
|
|
173
179
|
|
|
174
|
-
// src/premint/premint-api-client.ts
|
|
175
|
-
var postSignature = async (data) => retries(
|
|
176
|
-
() => post(`${ZORA_API_BASE}premint/signature`, data)
|
|
177
|
-
);
|
|
178
|
-
var getNextUID = async (path) => retries(
|
|
179
|
-
() => get(
|
|
180
|
-
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`
|
|
181
|
-
)
|
|
182
|
-
);
|
|
183
|
-
var getSignature = async (path) => retries(
|
|
184
|
-
() => get(
|
|
185
|
-
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`
|
|
186
|
-
)
|
|
187
|
-
);
|
|
188
|
-
var PremintAPIClient = {
|
|
189
|
-
postSignature,
|
|
190
|
-
getSignature,
|
|
191
|
-
getNextUID
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// src/apis/client-base.ts
|
|
195
|
-
var import_viem2 = require("viem");
|
|
196
|
-
|
|
197
180
|
// src/apis/chain-constants.ts
|
|
198
181
|
var import_chains = require("viem/chains");
|
|
199
182
|
var import_viem = require("viem");
|
|
@@ -274,27 +257,107 @@ var networkConfigByChain = {
|
|
|
274
257
|
}
|
|
275
258
|
};
|
|
276
259
|
|
|
277
|
-
// src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
this.network = networkConfig;
|
|
260
|
+
// src/mint/mint-api-client.ts
|
|
261
|
+
function encodeQueryParameters(params) {
|
|
262
|
+
return new URLSearchParams(params).toString();
|
|
263
|
+
}
|
|
264
|
+
var getApiNetworkConfigForChain = (chainId) => {
|
|
265
|
+
if (!networkConfigByChain[chainId]) {
|
|
266
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
286
267
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
268
|
+
return networkConfigByChain[chainId];
|
|
269
|
+
};
|
|
270
|
+
var MintAPIClient = class {
|
|
271
|
+
constructor(chainId, httpClient2) {
|
|
272
|
+
this.httpClient = httpClient2 || httpClient;
|
|
273
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
274
|
+
}
|
|
275
|
+
async getMintable(path, query) {
|
|
276
|
+
const httpClient2 = this.httpClient;
|
|
277
|
+
return httpClient2.retries(() => {
|
|
278
|
+
return httpClient2.get(
|
|
279
|
+
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
async getSalesConfigFixedPrice({
|
|
284
|
+
contractAddress,
|
|
285
|
+
tokenId
|
|
286
|
+
}) {
|
|
287
|
+
const { retries: retries2, post: post2 } = this.httpClient;
|
|
288
|
+
return retries2(async () => {
|
|
289
|
+
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
290
|
+
query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
|
|
291
|
+
variables: {
|
|
292
|
+
id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
async getMintableForToken({
|
|
299
|
+
tokenContract,
|
|
300
|
+
tokenId
|
|
301
|
+
}) {
|
|
302
|
+
return await this.getMintable(
|
|
303
|
+
{
|
|
304
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
305
|
+
collection_address: tokenContract
|
|
306
|
+
},
|
|
307
|
+
{ token_id: tokenId?.toString() }
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/premint/premint-api-client.ts
|
|
313
|
+
var postSignature = async ({
|
|
314
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
315
|
+
...data
|
|
316
|
+
}) => retries2(
|
|
317
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
318
|
+
);
|
|
319
|
+
var getNextUID = async ({
|
|
320
|
+
chain_name,
|
|
321
|
+
collection_address,
|
|
322
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
323
|
+
}) => retries2(
|
|
324
|
+
() => get2(
|
|
325
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
|
|
326
|
+
)
|
|
327
|
+
);
|
|
328
|
+
var getSignature = async ({
|
|
329
|
+
collection_address,
|
|
330
|
+
uid,
|
|
331
|
+
chain_name,
|
|
332
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
333
|
+
}) => retries2(
|
|
334
|
+
() => get2(
|
|
335
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
336
|
+
)
|
|
337
|
+
);
|
|
338
|
+
var PremintAPIClient = class {
|
|
339
|
+
constructor(chainId, httpClient2) {
|
|
340
|
+
this.postSignature = async (data) => postSignature({
|
|
341
|
+
...data,
|
|
342
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
343
|
+
httpClient: this.httpClient
|
|
344
|
+
});
|
|
345
|
+
this.getNextUID = async (path) => getNextUID({
|
|
346
|
+
...path,
|
|
347
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
348
|
+
httpClient: this.httpClient
|
|
349
|
+
});
|
|
350
|
+
this.getSignature = async ({
|
|
351
|
+
collection_address,
|
|
352
|
+
uid
|
|
353
|
+
}) => getSignature({
|
|
354
|
+
collection_address,
|
|
355
|
+
uid,
|
|
356
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
357
|
+
httpClient: this.httpClient
|
|
358
|
+
});
|
|
359
|
+
this.httpClient = httpClient2 || httpClient;
|
|
360
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
298
361
|
}
|
|
299
362
|
};
|
|
300
363
|
|
|
@@ -313,7 +376,7 @@ var DefaultMintArguments = {
|
|
|
313
376
|
function getPremintedLogFromReceipt(receipt) {
|
|
314
377
|
for (const data of receipt.logs) {
|
|
315
378
|
try {
|
|
316
|
-
const decodedLog = (0,
|
|
379
|
+
const decodedLog = (0, import_viem2.decodeEventLog)({
|
|
317
380
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
318
381
|
eventName: "Preminted",
|
|
319
382
|
...data
|
|
@@ -356,13 +419,11 @@ var encodePremintForAPI = ({
|
|
|
356
419
|
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
357
420
|
}
|
|
358
421
|
});
|
|
359
|
-
var PremintClient = class
|
|
360
|
-
constructor(chain,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
this.apiClient = apiClient;
|
|
422
|
+
var PremintClient = class {
|
|
423
|
+
constructor(chain, publicClient, httpClient2) {
|
|
424
|
+
this.chain = chain;
|
|
425
|
+
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
426
|
+
this.publicClient = publicClient || (0, import_viem2.createPublicClient)({ chain, transport: (0, import_viem2.http)() });
|
|
366
427
|
}
|
|
367
428
|
/**
|
|
368
429
|
* The premint executor address is deployed to the same address across all chains.
|
|
@@ -419,7 +480,6 @@ var PremintClient = class extends ClientBase {
|
|
|
419
480
|
account
|
|
420
481
|
}) {
|
|
421
482
|
const signatureResponse = await this.apiClient.getSignature({
|
|
422
|
-
chain_name: this.network.zoraBackendChainName,
|
|
423
483
|
collection_address: collection.toLowerCase(),
|
|
424
484
|
uid
|
|
425
485
|
});
|
|
@@ -439,7 +499,6 @@ var PremintClient = class extends ClientBase {
|
|
|
439
499
|
account,
|
|
440
500
|
checkSignature: false,
|
|
441
501
|
verifyingContract: collection,
|
|
442
|
-
publicClient: this.getPublicClient(),
|
|
443
502
|
uid,
|
|
444
503
|
collection: {
|
|
445
504
|
...signerData.collection,
|
|
@@ -466,11 +525,9 @@ var PremintClient = class extends ClientBase {
|
|
|
466
525
|
walletClient,
|
|
467
526
|
uid,
|
|
468
527
|
account,
|
|
469
|
-
collection
|
|
470
|
-
publicClient
|
|
528
|
+
collection
|
|
471
529
|
}) {
|
|
472
530
|
const signatureResponse = await this.apiClient.getSignature({
|
|
473
|
-
chain_name: this.network.zoraBackendChainName,
|
|
474
531
|
collection_address: collection.toLowerCase(),
|
|
475
532
|
uid
|
|
476
533
|
});
|
|
@@ -487,7 +544,6 @@ var PremintClient = class extends ClientBase {
|
|
|
487
544
|
account,
|
|
488
545
|
checkSignature: false,
|
|
489
546
|
verifyingContract: collection,
|
|
490
|
-
publicClient: this.getPublicClient(publicClient),
|
|
491
547
|
uid,
|
|
492
548
|
collection: signerData.collection,
|
|
493
549
|
premintConfig: signerData.premint
|
|
@@ -501,7 +557,6 @@ var PremintClient = class extends ClientBase {
|
|
|
501
557
|
*/
|
|
502
558
|
async signAndSubmitPremint({
|
|
503
559
|
walletClient,
|
|
504
|
-
publicClient,
|
|
505
560
|
verifyingContract,
|
|
506
561
|
premintConfig,
|
|
507
562
|
uid,
|
|
@@ -524,7 +579,7 @@ var PremintClient = class extends ClientBase {
|
|
|
524
579
|
})
|
|
525
580
|
});
|
|
526
581
|
if (checkSignature) {
|
|
527
|
-
const [isValidSignature] = await publicClient.readContract({
|
|
582
|
+
const [isValidSignature] = await this.publicClient.readContract({
|
|
528
583
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
529
584
|
address: this.getExecutorAddress(),
|
|
530
585
|
functionName: "isValidSignature",
|
|
@@ -537,7 +592,6 @@ var PremintClient = class extends ClientBase {
|
|
|
537
592
|
const apiData = {
|
|
538
593
|
collection,
|
|
539
594
|
premint: encodePremintForAPI(premintConfig),
|
|
540
|
-
chain_name: this.network.zoraBackendChainName,
|
|
541
595
|
signature
|
|
542
596
|
};
|
|
543
597
|
const premint = await this.apiClient.postSignature(apiData);
|
|
@@ -567,13 +621,11 @@ var PremintClient = class extends ClientBase {
|
|
|
567
621
|
account,
|
|
568
622
|
collection,
|
|
569
623
|
token,
|
|
570
|
-
publicClient,
|
|
571
624
|
walletClient,
|
|
572
625
|
executionSettings,
|
|
573
626
|
checkSignature = false
|
|
574
627
|
}) {
|
|
575
|
-
|
|
576
|
-
const newContractAddress = await publicClient.readContract({
|
|
628
|
+
const newContractAddress = await this.publicClient.readContract({
|
|
577
629
|
address: this.getExecutorAddress(),
|
|
578
630
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
579
631
|
functionName: "getContractAddress",
|
|
@@ -588,7 +640,6 @@ var PremintClient = class extends ClientBase {
|
|
|
588
640
|
let uid = executionSettings?.uid;
|
|
589
641
|
if (!uid) {
|
|
590
642
|
const uidResponse = await this.apiClient.getNextUID({
|
|
591
|
-
chain_name: this.network.zoraBackendChainName,
|
|
592
643
|
collection_address: newContractAddress.toLowerCase()
|
|
593
644
|
});
|
|
594
645
|
uid = uidResponse.next_uid;
|
|
@@ -609,7 +660,6 @@ var PremintClient = class extends ClientBase {
|
|
|
609
660
|
premintConfig,
|
|
610
661
|
checkSignature,
|
|
611
662
|
account,
|
|
612
|
-
publicClient,
|
|
613
663
|
walletClient,
|
|
614
664
|
collection
|
|
615
665
|
});
|
|
@@ -626,7 +676,6 @@ var PremintClient = class extends ClientBase {
|
|
|
626
676
|
uid
|
|
627
677
|
}) {
|
|
628
678
|
return await this.apiClient.getSignature({
|
|
629
|
-
chain_name: this.network.zoraBackendChainName,
|
|
630
679
|
collection_address: address,
|
|
631
680
|
uid
|
|
632
681
|
});
|
|
@@ -638,11 +687,9 @@ var PremintClient = class extends ClientBase {
|
|
|
638
687
|
* @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
|
|
639
688
|
*/
|
|
640
689
|
async isValidSignature({
|
|
641
|
-
data
|
|
642
|
-
publicClient
|
|
690
|
+
data
|
|
643
691
|
}) {
|
|
644
|
-
|
|
645
|
-
const [isValid, contractAddress, recoveredSigner] = await publicClient.readContract({
|
|
692
|
+
const [isValid, contractAddress, recoveredSigner] = await this.publicClient.readContract({
|
|
646
693
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
647
694
|
address: this.getExecutorAddress(),
|
|
648
695
|
functionName: "isValidSignature",
|
|
@@ -663,10 +710,11 @@ var PremintClient = class extends ClientBase {
|
|
|
663
710
|
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
664
711
|
}
|
|
665
712
|
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
713
|
+
const network = getApiNetworkConfigForChain(this.chain.id);
|
|
666
714
|
return {
|
|
667
715
|
explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
668
|
-
zoraCollect: `https://${
|
|
669
|
-
zoraManage: `https://${
|
|
716
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
717
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
670
718
|
};
|
|
671
719
|
}
|
|
672
720
|
/**
|
|
@@ -681,7 +729,7 @@ var PremintClient = class extends ClientBase {
|
|
|
681
729
|
* @param settings.publicClient Optional public client for preflight checks.
|
|
682
730
|
* @returns receipt, log, zoraURL
|
|
683
731
|
*/
|
|
684
|
-
async
|
|
732
|
+
async makeMintParameters({
|
|
685
733
|
data,
|
|
686
734
|
account,
|
|
687
735
|
mintArguments
|
|
@@ -710,45 +758,19 @@ var PremintClient = class extends ClientBase {
|
|
|
710
758
|
address: targetAddress,
|
|
711
759
|
args
|
|
712
760
|
};
|
|
713
|
-
return
|
|
714
|
-
request
|
|
715
|
-
};
|
|
761
|
+
return request;
|
|
716
762
|
}
|
|
717
763
|
};
|
|
718
764
|
function createPremintClient({
|
|
719
765
|
chain,
|
|
720
|
-
|
|
766
|
+
httpClient: httpClient2,
|
|
767
|
+
publicClient
|
|
721
768
|
}) {
|
|
722
|
-
return new PremintClient(chain,
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// src/mint/mint-api-client.ts
|
|
726
|
-
function encodeQueryParameters(params) {
|
|
727
|
-
return new URLSearchParams(params).toString();
|
|
769
|
+
return new PremintClient(chain, publicClient, httpClient2);
|
|
728
770
|
}
|
|
729
|
-
var getMintable = async (path, query) => retries(() => {
|
|
730
|
-
return get(
|
|
731
|
-
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
|
|
732
|
-
);
|
|
733
|
-
});
|
|
734
|
-
var getSalesConfigFixedPrice = async ({
|
|
735
|
-
contractAddress,
|
|
736
|
-
tokenId,
|
|
737
|
-
subgraphUrl
|
|
738
|
-
}) => retries(async () => {
|
|
739
|
-
const response = await post(subgraphUrl, {
|
|
740
|
-
query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
|
|
741
|
-
variables: { id: `${contractAddress.toLowerCase()}-${tokenId}` }
|
|
742
|
-
});
|
|
743
|
-
return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
|
|
744
|
-
});
|
|
745
|
-
var MintAPIClient = {
|
|
746
|
-
getMintable,
|
|
747
|
-
getSalesConfigFixedPrice
|
|
748
|
-
};
|
|
749
771
|
|
|
750
772
|
// src/mint/mint-client.ts
|
|
751
|
-
var
|
|
773
|
+
var import_viem3 = require("viem");
|
|
752
774
|
var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
|
|
753
775
|
var MintError = class extends Error {
|
|
754
776
|
};
|
|
@@ -758,158 +780,258 @@ var Errors = {
|
|
|
758
780
|
MintError,
|
|
759
781
|
MintInactiveError
|
|
760
782
|
};
|
|
761
|
-
var zora721Abi = (0,
|
|
783
|
+
var zora721Abi = (0, import_viem3.parseAbi)([
|
|
762
784
|
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
763
785
|
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
764
786
|
]);
|
|
765
|
-
var MintClient = class
|
|
766
|
-
constructor(chain,
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
apiClient = MintAPIClient;
|
|
770
|
-
}
|
|
771
|
-
this.apiClient = apiClient;
|
|
787
|
+
var MintClient = class {
|
|
788
|
+
constructor(chain, publicClient, httpClient2) {
|
|
789
|
+
this.apiClient = new MintAPIClient(chain.id, httpClient2);
|
|
790
|
+
this.publicClient = publicClient || (0, import_viem3.createPublicClient)({ chain, transport: (0, import_viem3.http)() });
|
|
772
791
|
}
|
|
792
|
+
/**
|
|
793
|
+
* Gets mintable information for a given token
|
|
794
|
+
* @param param0.tokenContract The contract address of the token to mint.
|
|
795
|
+
* @param param0.tokenId The token id to mint.
|
|
796
|
+
* @returns
|
|
797
|
+
*/
|
|
773
798
|
async getMintable({
|
|
774
799
|
tokenContract,
|
|
775
800
|
tokenId
|
|
776
801
|
}) {
|
|
777
|
-
return this.apiClient.
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
},
|
|
782
|
-
{ token_id: tokenId?.toString() }
|
|
783
|
-
);
|
|
802
|
+
return await this.apiClient.getMintableForToken({
|
|
803
|
+
tokenContract,
|
|
804
|
+
tokenId: tokenId?.toString()
|
|
805
|
+
});
|
|
784
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* Returns the parameters needed to prepare a transaction mint a token.
|
|
809
|
+
* @param param0.minterAccount The account that will mint the token.
|
|
810
|
+
* @param param0.mintable The mintable token to mint.
|
|
811
|
+
* @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
|
|
812
|
+
* @returns
|
|
813
|
+
*/
|
|
785
814
|
async makePrepareMintTokenParams({
|
|
786
|
-
|
|
787
|
-
|
|
815
|
+
...rest
|
|
816
|
+
}) {
|
|
817
|
+
return makePrepareMintTokenParams({
|
|
818
|
+
...rest,
|
|
819
|
+
apiClient: this.apiClient,
|
|
820
|
+
publicClient: this.publicClient
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
825
|
+
* @param param0.mintable The mintable token to mint.
|
|
826
|
+
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
827
|
+
* @returns
|
|
828
|
+
*/
|
|
829
|
+
async getMintCosts({
|
|
788
830
|
mintable,
|
|
789
|
-
|
|
831
|
+
quantityToMint
|
|
790
832
|
}) {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
throw new MintError("No minting context data from zora API");
|
|
799
|
-
}
|
|
800
|
-
if (!["zora_create", "zora_create_1155"].includes(
|
|
801
|
-
mintable.mint_context?.mint_context_type
|
|
802
|
-
)) {
|
|
803
|
-
throw new MintError(
|
|
804
|
-
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
|
|
805
|
-
);
|
|
806
|
-
}
|
|
807
|
-
const thisPublicClient = this.getPublicClient(publicClient);
|
|
808
|
-
if (mintable.mint_context.mint_context_type === "zora_create_1155") {
|
|
809
|
-
return {
|
|
810
|
-
simulateContractParameters: await this.prepareMintZora1155({
|
|
811
|
-
publicClient: thisPublicClient,
|
|
812
|
-
mintArguments,
|
|
813
|
-
sender: minterAccount,
|
|
814
|
-
mintable
|
|
815
|
-
})
|
|
816
|
-
};
|
|
833
|
+
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
834
|
+
if (mintContextType === "zora_create_1155") {
|
|
835
|
+
return await get1155MintCosts({
|
|
836
|
+
mintable,
|
|
837
|
+
publicClient: this.publicClient,
|
|
838
|
+
quantityToMint: BigInt(quantityToMint)
|
|
839
|
+
});
|
|
817
840
|
}
|
|
818
|
-
if (
|
|
819
|
-
return {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
mintable
|
|
825
|
-
})
|
|
826
|
-
};
|
|
841
|
+
if (mintContextType === "zora_create") {
|
|
842
|
+
return await get721MintCosts({
|
|
843
|
+
mintable,
|
|
844
|
+
publicClient: this.publicClient,
|
|
845
|
+
quantityToMint: BigInt(quantityToMint)
|
|
846
|
+
});
|
|
827
847
|
}
|
|
828
|
-
throw new
|
|
848
|
+
throw new MintError(
|
|
849
|
+
`Mintable type ${mintContextType} is currently unsupported.`
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
function createMintClient({
|
|
854
|
+
chain,
|
|
855
|
+
publicClient,
|
|
856
|
+
httpClient: httpClient2
|
|
857
|
+
}) {
|
|
858
|
+
return new MintClient(chain, publicClient, httpClient2);
|
|
859
|
+
}
|
|
860
|
+
function validateMintableAndGetContextType(mintable) {
|
|
861
|
+
if (!mintable) {
|
|
862
|
+
throw new MintError("No mintable found");
|
|
863
|
+
}
|
|
864
|
+
if (!mintable.is_active) {
|
|
865
|
+
throw new MintInactiveError("Minting token is inactive");
|
|
866
|
+
}
|
|
867
|
+
if (!mintable.mint_context) {
|
|
868
|
+
throw new MintError("No minting context data from zora API");
|
|
869
|
+
}
|
|
870
|
+
if (!["zora_create", "zora_create_1155"].includes(
|
|
871
|
+
mintable.mint_context?.mint_context_type
|
|
872
|
+
)) {
|
|
873
|
+
throw new MintError(
|
|
874
|
+
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
return mintable.mint_context.mint_context_type;
|
|
878
|
+
}
|
|
879
|
+
async function makePrepareMintTokenParams({
|
|
880
|
+
publicClient,
|
|
881
|
+
mintable,
|
|
882
|
+
apiClient,
|
|
883
|
+
...rest
|
|
884
|
+
}) {
|
|
885
|
+
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
886
|
+
const thisPublicClient = publicClient;
|
|
887
|
+
if (mintContextType === "zora_create_1155") {
|
|
888
|
+
return makePrepareMint1155TokenParams({
|
|
889
|
+
apiClient,
|
|
890
|
+
publicClient: thisPublicClient,
|
|
891
|
+
mintable,
|
|
892
|
+
mintContextType,
|
|
893
|
+
...rest
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
if (mintContextType === "zora_create") {
|
|
897
|
+
return makePrepareMint721TokenParams({
|
|
898
|
+
publicClient: thisPublicClient,
|
|
899
|
+
mintable,
|
|
900
|
+
mintContextType,
|
|
901
|
+
...rest
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
throw new MintError(
|
|
905
|
+
`Mintable type ${mintContextType} is currently unsupported.`
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
async function get721MintCosts({
|
|
909
|
+
mintable,
|
|
910
|
+
publicClient,
|
|
911
|
+
quantityToMint
|
|
912
|
+
}) {
|
|
913
|
+
const address = mintable.collection.address;
|
|
914
|
+
const [_, mintFee] = await publicClient.readContract({
|
|
915
|
+
abi: zora721Abi,
|
|
916
|
+
address,
|
|
917
|
+
functionName: "zoraFeeForAmount",
|
|
918
|
+
args: [BigInt(quantityToMint)]
|
|
919
|
+
});
|
|
920
|
+
const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
921
|
+
return {
|
|
922
|
+
mintFee,
|
|
923
|
+
tokenPurchaseCost,
|
|
924
|
+
totalCost: mintFee + tokenPurchaseCost
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
async function makePrepareMint721TokenParams({
|
|
928
|
+
publicClient,
|
|
929
|
+
minterAccount,
|
|
930
|
+
mintable,
|
|
931
|
+
mintContextType,
|
|
932
|
+
mintArguments
|
|
933
|
+
}) {
|
|
934
|
+
if (mintContextType !== "zora_create") {
|
|
935
|
+
throw new Error("Minted token type must be for 1155");
|
|
829
936
|
}
|
|
830
|
-
|
|
937
|
+
const mintValue = (await get721MintCosts({
|
|
831
938
|
mintable,
|
|
832
|
-
sender,
|
|
833
939
|
publicClient,
|
|
834
|
-
mintArguments
|
|
835
|
-
})
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
940
|
+
quantityToMint: BigInt(mintArguments.quantityToMint)
|
|
941
|
+
})).totalCost;
|
|
942
|
+
const result = {
|
|
943
|
+
abi: zora721Abi,
|
|
944
|
+
address: mintable.contract_address,
|
|
945
|
+
account: minterAccount,
|
|
946
|
+
functionName: "mintWithRewards",
|
|
947
|
+
value: mintValue,
|
|
948
|
+
args: [
|
|
949
|
+
mintArguments.mintToAddress,
|
|
950
|
+
BigInt(mintArguments.quantityToMint),
|
|
951
|
+
mintArguments.mintComment || "",
|
|
952
|
+
mintArguments.mintReferral || import_viem3.zeroAddress
|
|
953
|
+
]
|
|
954
|
+
};
|
|
955
|
+
return result;
|
|
956
|
+
}
|
|
957
|
+
async function get1155MintFee({
|
|
958
|
+
collectionAddress,
|
|
959
|
+
publicClient
|
|
960
|
+
}) {
|
|
961
|
+
return await publicClient.readContract({
|
|
962
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
963
|
+
functionName: "mintFee",
|
|
964
|
+
address: collectionAddress
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
async function get1155MintCosts({
|
|
968
|
+
mintable,
|
|
969
|
+
publicClient,
|
|
970
|
+
quantityToMint
|
|
971
|
+
}) {
|
|
972
|
+
const address = mintable.collection.address;
|
|
973
|
+
const mintFee = await get1155MintFee({
|
|
974
|
+
collectionAddress: address,
|
|
975
|
+
publicClient
|
|
976
|
+
});
|
|
977
|
+
const mintFeeForTokens = mintFee * quantityToMint;
|
|
978
|
+
const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
979
|
+
return {
|
|
980
|
+
mintFee: mintFeeForTokens,
|
|
981
|
+
tokenPurchaseCost,
|
|
982
|
+
totalCost: mintFeeForTokens + tokenPurchaseCost
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
async function makePrepareMint1155TokenParams({
|
|
986
|
+
apiClient,
|
|
987
|
+
publicClient,
|
|
988
|
+
minterAccount,
|
|
989
|
+
mintable,
|
|
990
|
+
mintContextType,
|
|
991
|
+
mintArguments
|
|
992
|
+
}) {
|
|
993
|
+
if (mintContextType !== "zora_create_1155") {
|
|
994
|
+
throw new Error("Minted token type must be for 1155");
|
|
869
995
|
}
|
|
870
|
-
|
|
996
|
+
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
997
|
+
const address = mintable.collection.address;
|
|
998
|
+
const mintValue = (await get1155MintCosts({
|
|
871
999
|
mintable,
|
|
872
1000
|
publicClient,
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1001
|
+
quantityToMint: mintQuantity
|
|
1002
|
+
})).totalCost;
|
|
1003
|
+
const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
|
|
1004
|
+
contractAddress: address,
|
|
1005
|
+
tokenId: BigInt(mintable.token_id)
|
|
1006
|
+
});
|
|
1007
|
+
const result = {
|
|
1008
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
1009
|
+
functionName: "mintWithRewards",
|
|
1010
|
+
account: minterAccount,
|
|
1011
|
+
value: mintValue,
|
|
1012
|
+
address,
|
|
1013
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1014
|
+
args: [
|
|
1015
|
+
tokenFixedPriceMinter || import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999],
|
|
1016
|
+
BigInt(mintable.token_id),
|
|
1017
|
+
mintQuantity,
|
|
1018
|
+
(0, import_viem3.encodeAbiParameters)((0, import_viem3.parseAbiParameters)("address, string"), [
|
|
890
1019
|
mintArguments.mintToAddress,
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
function createMintClient({
|
|
900
|
-
chain,
|
|
901
|
-
mintAPIClient
|
|
902
|
-
}) {
|
|
903
|
-
return new MintClient(chain, mintAPIClient);
|
|
1020
|
+
mintArguments.mintComment || ""
|
|
1021
|
+
]),
|
|
1022
|
+
mintArguments.mintReferral || import_viem3.zeroAddress
|
|
1023
|
+
]
|
|
1024
|
+
};
|
|
1025
|
+
return result;
|
|
904
1026
|
}
|
|
905
1027
|
|
|
906
1028
|
// src/create/1155-create-helper.ts
|
|
907
1029
|
var import_protocol_deployments3 = require("@zoralabs/protocol-deployments");
|
|
908
|
-
var
|
|
1030
|
+
var import_viem4 = require("viem");
|
|
909
1031
|
var SALE_END_FOREVER = 18446744073709551615n;
|
|
910
1032
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
911
1033
|
var DEFAULT_SALE_SETTINGS = {
|
|
912
|
-
fundsRecipient:
|
|
1034
|
+
fundsRecipient: import_viem4.zeroAddress,
|
|
913
1035
|
// Free Mint
|
|
914
1036
|
pricePerToken: 0n,
|
|
915
1037
|
// Sale start time – defaults to beginning of unix time
|
|
@@ -948,32 +1070,32 @@ function create1155TokenSetupArgs({
|
|
|
948
1070
|
...salesConfig
|
|
949
1071
|
};
|
|
950
1072
|
const setupActions = [
|
|
951
|
-
(0,
|
|
1073
|
+
(0, import_viem4.encodeFunctionData)({
|
|
952
1074
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
953
1075
|
functionName: "assumeLastTokenIdMatches",
|
|
954
1076
|
args: [nextTokenId - 1n]
|
|
955
1077
|
}),
|
|
956
|
-
createReferral ? (0,
|
|
1078
|
+
createReferral ? (0, import_viem4.encodeFunctionData)({
|
|
957
1079
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
958
1080
|
functionName: "setupNewTokenWithCreateReferral",
|
|
959
1081
|
args: [tokenMetadataURI, maxSupply, createReferral]
|
|
960
|
-
}) : (0,
|
|
1082
|
+
}) : (0, import_viem4.encodeFunctionData)({
|
|
961
1083
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
962
1084
|
functionName: "setupNewToken",
|
|
963
1085
|
args: [tokenMetadataURI, maxSupply]
|
|
964
1086
|
}),
|
|
965
|
-
(0,
|
|
1087
|
+
(0, import_viem4.encodeFunctionData)({
|
|
966
1088
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
967
1089
|
functionName: "addPermission",
|
|
968
1090
|
args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
|
|
969
1091
|
}),
|
|
970
|
-
(0,
|
|
1092
|
+
(0, import_viem4.encodeFunctionData)({
|
|
971
1093
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
972
1094
|
functionName: "callSale",
|
|
973
1095
|
args: [
|
|
974
1096
|
nextTokenId,
|
|
975
1097
|
fixedPriceMinterAddress,
|
|
976
|
-
(0,
|
|
1098
|
+
(0, import_viem4.encodeFunctionData)({
|
|
977
1099
|
abi: import_protocol_deployments3.zoraCreatorFixedPriceSaleStrategyABI,
|
|
978
1100
|
functionName: "setSale",
|
|
979
1101
|
args: [nextTokenId, salesConfigWithDefaults]
|
|
@@ -983,7 +1105,7 @@ function create1155TokenSetupArgs({
|
|
|
983
1105
|
];
|
|
984
1106
|
if (mintToCreatorCount) {
|
|
985
1107
|
setupActions.push(
|
|
986
|
-
(0,
|
|
1108
|
+
(0, import_viem4.encodeFunctionData)({
|
|
987
1109
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
988
1110
|
functionName: "adminMint",
|
|
989
1111
|
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
@@ -992,7 +1114,7 @@ function create1155TokenSetupArgs({
|
|
|
992
1114
|
}
|
|
993
1115
|
if (royaltySettings) {
|
|
994
1116
|
setupActions.push(
|
|
995
|
-
(0,
|
|
1117
|
+
(0, import_viem4.encodeFunctionData)({
|
|
996
1118
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
997
1119
|
functionName: "updateRoyaltiesForToken",
|
|
998
1120
|
args: [
|
|
@@ -1011,7 +1133,7 @@ function create1155TokenSetupArgs({
|
|
|
1011
1133
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
1012
1134
|
for (const data of receipt.logs) {
|
|
1013
1135
|
try {
|
|
1014
|
-
const decodedLog = (0,
|
|
1136
|
+
const decodedLog = (0, import_viem4.decodeEventLog)({
|
|
1015
1137
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
1016
1138
|
eventName: "SetupNewToken",
|
|
1017
1139
|
...data
|
|
@@ -1164,8 +1286,9 @@ function create1155CreatorClient({
|
|
|
1164
1286
|
createMintClient,
|
|
1165
1287
|
createPremintClient,
|
|
1166
1288
|
encodePremintForAPI,
|
|
1289
|
+
get1155MintCosts,
|
|
1290
|
+
getApiNetworkConfigForChain,
|
|
1167
1291
|
getPremintedLogFromReceipt,
|
|
1168
|
-
getSalesConfigFixedPrice,
|
|
1169
1292
|
getTokenIdFromCreateReceipt,
|
|
1170
1293
|
preminterTypedDataDefinition
|
|
1171
1294
|
});
|