@zoralabs/protocol-sdk 0.3.3-prerelease.0 → 0.3.4
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 +7 -7
- package/CHANGELOG.md +23 -4
- 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 +385 -241
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +372 -227
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +219 -12
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +54 -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 +3 -2
- package/src/apis/http-api-base.ts +12 -0
- package/src/create/1155-create-helper.ts +1 -1
- package/src/mint/mint-api-client.ts +93 -34
- package/src/mint/mint-client.test.ts +23 -27
- package/src/mint/mint-client.ts +326 -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/tsconfig.json +2 -17
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/premint/premint-client.ts
|
|
2
|
-
import { decodeEventLog } from "viem";
|
|
2
|
+
import { createPublicClient, decodeEventLog, http } from "viem";
|
|
3
3
|
import {
|
|
4
4
|
zoraCreator1155PremintExecutorImplABI,
|
|
5
5
|
zoraCreator1155PremintExecutorImplAddress,
|
|
@@ -124,6 +124,11 @@ var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
|
|
|
124
124
|
throw err;
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
+
var httpClient = {
|
|
128
|
+
get,
|
|
129
|
+
post,
|
|
130
|
+
retries
|
|
131
|
+
};
|
|
127
132
|
|
|
128
133
|
// src/constants.ts
|
|
129
134
|
var ZORA_API_BASE = "https://api.zora.co/";
|
|
@@ -133,29 +138,6 @@ function getSubgraph(name, version) {
|
|
|
133
138
|
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
// src/premint/premint-api-client.ts
|
|
137
|
-
var postSignature = async (data) => retries(
|
|
138
|
-
() => post(`${ZORA_API_BASE}premint/signature`, data)
|
|
139
|
-
);
|
|
140
|
-
var getNextUID = async (path) => retries(
|
|
141
|
-
() => get(
|
|
142
|
-
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`
|
|
143
|
-
)
|
|
144
|
-
);
|
|
145
|
-
var getSignature = async (path) => retries(
|
|
146
|
-
() => get(
|
|
147
|
-
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
var PremintAPIClient = {
|
|
151
|
-
postSignature,
|
|
152
|
-
getSignature,
|
|
153
|
-
getNextUID
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// src/apis/client-base.ts
|
|
157
|
-
import { createPublicClient, http } from "viem";
|
|
158
|
-
|
|
159
141
|
// src/apis/chain-constants.ts
|
|
160
142
|
import {
|
|
161
143
|
base,
|
|
@@ -246,27 +228,125 @@ var networkConfigByChain = {
|
|
|
246
228
|
}
|
|
247
229
|
};
|
|
248
230
|
|
|
249
|
-
// src/
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
this.network = networkConfig;
|
|
231
|
+
// src/mint/mint-api-client.ts
|
|
232
|
+
function encodeQueryParameters(params) {
|
|
233
|
+
return new URLSearchParams(params).toString();
|
|
234
|
+
}
|
|
235
|
+
var getApiNetworkConfigForChain = (chainId) => {
|
|
236
|
+
if (!networkConfigByChain[chainId]) {
|
|
237
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
258
238
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
239
|
+
return networkConfigByChain[chainId];
|
|
240
|
+
};
|
|
241
|
+
var MintAPIClient = class {
|
|
242
|
+
constructor(chainId, httpClient2) {
|
|
243
|
+
this.httpClient = httpClient2 || httpClient;
|
|
244
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
245
|
+
}
|
|
246
|
+
async getMintable(path, query) {
|
|
247
|
+
const httpClient2 = this.httpClient;
|
|
248
|
+
return httpClient2.retries(() => {
|
|
249
|
+
return httpClient2.get(
|
|
250
|
+
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
async getSalesConfigFixedPrice({
|
|
255
|
+
contractAddress,
|
|
256
|
+
tokenId
|
|
257
|
+
}) {
|
|
258
|
+
const { retries: retries2, post: post2 } = this.httpClient;
|
|
259
|
+
return retries2(async () => {
|
|
260
|
+
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
261
|
+
query: `query ($id: ID!) {
|
|
262
|
+
zoraCreateToken(id: $id) {
|
|
263
|
+
id
|
|
264
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
265
|
+
type
|
|
266
|
+
fixedPrice {
|
|
267
|
+
address
|
|
268
|
+
pricePerToken
|
|
269
|
+
saleEnd
|
|
270
|
+
saleStart
|
|
271
|
+
maxTokensPerAddress
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}`,
|
|
276
|
+
variables: {
|
|
277
|
+
id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
const fixedPrice = response.data?.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPrice;
|
|
281
|
+
return {
|
|
282
|
+
address: fixedPrice.address,
|
|
283
|
+
pricePerToken: BigInt(fixedPrice.pricePerToken)
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
async getMintableForToken({
|
|
288
|
+
tokenContract,
|
|
289
|
+
tokenId
|
|
290
|
+
}) {
|
|
291
|
+
return await this.getMintable(
|
|
292
|
+
{
|
|
293
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
294
|
+
collection_address: tokenContract
|
|
295
|
+
},
|
|
296
|
+
{ token_id: tokenId?.toString() }
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// src/premint/premint-api-client.ts
|
|
302
|
+
var postSignature = async ({
|
|
303
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
304
|
+
...data
|
|
305
|
+
}) => retries2(
|
|
306
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
307
|
+
);
|
|
308
|
+
var getNextUID = async ({
|
|
309
|
+
chain_name,
|
|
310
|
+
collection_address,
|
|
311
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
312
|
+
}) => retries2(
|
|
313
|
+
() => get2(
|
|
314
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
|
|
315
|
+
)
|
|
316
|
+
);
|
|
317
|
+
var getSignature = async ({
|
|
318
|
+
collection_address,
|
|
319
|
+
uid,
|
|
320
|
+
chain_name,
|
|
321
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
322
|
+
}) => retries2(
|
|
323
|
+
() => get2(
|
|
324
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
var PremintAPIClient = class {
|
|
328
|
+
constructor(chainId, httpClient2) {
|
|
329
|
+
this.postSignature = async (data) => postSignature({
|
|
330
|
+
...data,
|
|
331
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
332
|
+
httpClient: this.httpClient
|
|
333
|
+
});
|
|
334
|
+
this.getNextUID = async (path) => getNextUID({
|
|
335
|
+
...path,
|
|
336
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
337
|
+
httpClient: this.httpClient
|
|
338
|
+
});
|
|
339
|
+
this.getSignature = async ({
|
|
340
|
+
collection_address,
|
|
341
|
+
uid
|
|
342
|
+
}) => getSignature({
|
|
343
|
+
collection_address,
|
|
344
|
+
uid,
|
|
345
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
346
|
+
httpClient: this.httpClient
|
|
347
|
+
});
|
|
348
|
+
this.httpClient = httpClient2 || httpClient;
|
|
349
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
270
350
|
}
|
|
271
351
|
};
|
|
272
352
|
|
|
@@ -328,13 +408,11 @@ var encodePremintForAPI = ({
|
|
|
328
408
|
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
329
409
|
}
|
|
330
410
|
});
|
|
331
|
-
var PremintClient = class
|
|
332
|
-
constructor(chain,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
this.apiClient = apiClient;
|
|
411
|
+
var PremintClient = class {
|
|
412
|
+
constructor(chain, publicClient, httpClient2) {
|
|
413
|
+
this.chain = chain;
|
|
414
|
+
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
415
|
+
this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
|
|
338
416
|
}
|
|
339
417
|
/**
|
|
340
418
|
* The premint executor address is deployed to the same address across all chains.
|
|
@@ -391,7 +469,6 @@ var PremintClient = class extends ClientBase {
|
|
|
391
469
|
account
|
|
392
470
|
}) {
|
|
393
471
|
const signatureResponse = await this.apiClient.getSignature({
|
|
394
|
-
chain_name: this.network.zoraBackendChainName,
|
|
395
472
|
collection_address: collection.toLowerCase(),
|
|
396
473
|
uid
|
|
397
474
|
});
|
|
@@ -411,7 +488,6 @@ var PremintClient = class extends ClientBase {
|
|
|
411
488
|
account,
|
|
412
489
|
checkSignature: false,
|
|
413
490
|
verifyingContract: collection,
|
|
414
|
-
publicClient: this.getPublicClient(),
|
|
415
491
|
uid,
|
|
416
492
|
collection: {
|
|
417
493
|
...signerData.collection,
|
|
@@ -438,11 +514,9 @@ var PremintClient = class extends ClientBase {
|
|
|
438
514
|
walletClient,
|
|
439
515
|
uid,
|
|
440
516
|
account,
|
|
441
|
-
collection
|
|
442
|
-
publicClient
|
|
517
|
+
collection
|
|
443
518
|
}) {
|
|
444
519
|
const signatureResponse = await this.apiClient.getSignature({
|
|
445
|
-
chain_name: this.network.zoraBackendChainName,
|
|
446
520
|
collection_address: collection.toLowerCase(),
|
|
447
521
|
uid
|
|
448
522
|
});
|
|
@@ -459,7 +533,6 @@ var PremintClient = class extends ClientBase {
|
|
|
459
533
|
account,
|
|
460
534
|
checkSignature: false,
|
|
461
535
|
verifyingContract: collection,
|
|
462
|
-
publicClient: this.getPublicClient(publicClient),
|
|
463
536
|
uid,
|
|
464
537
|
collection: signerData.collection,
|
|
465
538
|
premintConfig: signerData.premint
|
|
@@ -473,7 +546,6 @@ var PremintClient = class extends ClientBase {
|
|
|
473
546
|
*/
|
|
474
547
|
async signAndSubmitPremint({
|
|
475
548
|
walletClient,
|
|
476
|
-
publicClient,
|
|
477
549
|
verifyingContract,
|
|
478
550
|
premintConfig,
|
|
479
551
|
uid,
|
|
@@ -496,7 +568,7 @@ var PremintClient = class extends ClientBase {
|
|
|
496
568
|
})
|
|
497
569
|
});
|
|
498
570
|
if (checkSignature) {
|
|
499
|
-
const [isValidSignature] = await publicClient.readContract({
|
|
571
|
+
const [isValidSignature] = await this.publicClient.readContract({
|
|
500
572
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
501
573
|
address: this.getExecutorAddress(),
|
|
502
574
|
functionName: "isValidSignature",
|
|
@@ -509,7 +581,6 @@ var PremintClient = class extends ClientBase {
|
|
|
509
581
|
const apiData = {
|
|
510
582
|
collection,
|
|
511
583
|
premint: encodePremintForAPI(premintConfig),
|
|
512
|
-
chain_name: this.network.zoraBackendChainName,
|
|
513
584
|
signature
|
|
514
585
|
};
|
|
515
586
|
const premint = await this.apiClient.postSignature(apiData);
|
|
@@ -539,13 +610,11 @@ var PremintClient = class extends ClientBase {
|
|
|
539
610
|
account,
|
|
540
611
|
collection,
|
|
541
612
|
token,
|
|
542
|
-
publicClient,
|
|
543
613
|
walletClient,
|
|
544
614
|
executionSettings,
|
|
545
615
|
checkSignature = false
|
|
546
616
|
}) {
|
|
547
|
-
|
|
548
|
-
const newContractAddress = await publicClient.readContract({
|
|
617
|
+
const newContractAddress = await this.publicClient.readContract({
|
|
549
618
|
address: this.getExecutorAddress(),
|
|
550
619
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
551
620
|
functionName: "getContractAddress",
|
|
@@ -560,7 +629,6 @@ var PremintClient = class extends ClientBase {
|
|
|
560
629
|
let uid = executionSettings?.uid;
|
|
561
630
|
if (!uid) {
|
|
562
631
|
const uidResponse = await this.apiClient.getNextUID({
|
|
563
|
-
chain_name: this.network.zoraBackendChainName,
|
|
564
632
|
collection_address: newContractAddress.toLowerCase()
|
|
565
633
|
});
|
|
566
634
|
uid = uidResponse.next_uid;
|
|
@@ -581,7 +649,6 @@ var PremintClient = class extends ClientBase {
|
|
|
581
649
|
premintConfig,
|
|
582
650
|
checkSignature,
|
|
583
651
|
account,
|
|
584
|
-
publicClient,
|
|
585
652
|
walletClient,
|
|
586
653
|
collection
|
|
587
654
|
});
|
|
@@ -598,7 +665,6 @@ var PremintClient = class extends ClientBase {
|
|
|
598
665
|
uid
|
|
599
666
|
}) {
|
|
600
667
|
return await this.apiClient.getSignature({
|
|
601
|
-
chain_name: this.network.zoraBackendChainName,
|
|
602
668
|
collection_address: address,
|
|
603
669
|
uid
|
|
604
670
|
});
|
|
@@ -610,11 +676,9 @@ var PremintClient = class extends ClientBase {
|
|
|
610
676
|
* @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
|
|
611
677
|
*/
|
|
612
678
|
async isValidSignature({
|
|
613
|
-
data
|
|
614
|
-
publicClient
|
|
679
|
+
data
|
|
615
680
|
}) {
|
|
616
|
-
|
|
617
|
-
const [isValid, contractAddress, recoveredSigner] = await publicClient.readContract({
|
|
681
|
+
const [isValid, contractAddress, recoveredSigner] = await this.publicClient.readContract({
|
|
618
682
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
619
683
|
address: this.getExecutorAddress(),
|
|
620
684
|
functionName: "isValidSignature",
|
|
@@ -635,10 +699,11 @@ var PremintClient = class extends ClientBase {
|
|
|
635
699
|
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
636
700
|
}
|
|
637
701
|
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
702
|
+
const network = getApiNetworkConfigForChain(this.chain.id);
|
|
638
703
|
return {
|
|
639
704
|
explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
640
|
-
zoraCollect: `https://${
|
|
641
|
-
zoraManage: `https://${
|
|
705
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
706
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
642
707
|
};
|
|
643
708
|
}
|
|
644
709
|
/**
|
|
@@ -653,7 +718,7 @@ var PremintClient = class extends ClientBase {
|
|
|
653
718
|
* @param settings.publicClient Optional public client for preflight checks.
|
|
654
719
|
* @returns receipt, log, zoraURL
|
|
655
720
|
*/
|
|
656
|
-
async
|
|
721
|
+
async makeMintParameters({
|
|
657
722
|
data,
|
|
658
723
|
account,
|
|
659
724
|
mintArguments
|
|
@@ -682,49 +747,25 @@ var PremintClient = class extends ClientBase {
|
|
|
682
747
|
address: targetAddress,
|
|
683
748
|
args
|
|
684
749
|
};
|
|
685
|
-
return
|
|
686
|
-
request
|
|
687
|
-
};
|
|
750
|
+
return request;
|
|
688
751
|
}
|
|
689
752
|
};
|
|
690
753
|
function createPremintClient({
|
|
691
754
|
chain,
|
|
692
|
-
|
|
755
|
+
httpClient: httpClient2,
|
|
756
|
+
publicClient
|
|
693
757
|
}) {
|
|
694
|
-
return new PremintClient(chain,
|
|
758
|
+
return new PremintClient(chain, publicClient, httpClient2);
|
|
695
759
|
}
|
|
696
760
|
|
|
697
|
-
// src/mint/mint-api-client.ts
|
|
698
|
-
function encodeQueryParameters(params) {
|
|
699
|
-
return new URLSearchParams(params).toString();
|
|
700
|
-
}
|
|
701
|
-
var getMintable = async (path, query) => retries(() => {
|
|
702
|
-
return get(
|
|
703
|
-
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
|
|
704
|
-
);
|
|
705
|
-
});
|
|
706
|
-
var getSalesConfigFixedPrice = async ({
|
|
707
|
-
contractAddress,
|
|
708
|
-
tokenId,
|
|
709
|
-
subgraphUrl
|
|
710
|
-
}) => retries(async () => {
|
|
711
|
-
const response = await post(subgraphUrl, {
|
|
712
|
-
query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
|
|
713
|
-
variables: { id: `${contractAddress.toLowerCase()}-${tokenId}` }
|
|
714
|
-
});
|
|
715
|
-
return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
|
|
716
|
-
});
|
|
717
|
-
var MintAPIClient = {
|
|
718
|
-
getMintable,
|
|
719
|
-
getSalesConfigFixedPrice
|
|
720
|
-
};
|
|
721
|
-
|
|
722
761
|
// src/mint/mint-client.ts
|
|
723
762
|
import {
|
|
763
|
+
createPublicClient as createPublicClient2,
|
|
724
764
|
encodeAbiParameters,
|
|
725
765
|
parseAbi,
|
|
726
766
|
parseAbiParameters,
|
|
727
|
-
zeroAddress
|
|
767
|
+
zeroAddress,
|
|
768
|
+
http as http2
|
|
728
769
|
} from "viem";
|
|
729
770
|
import {
|
|
730
771
|
zoraCreator1155ImplABI,
|
|
@@ -742,145 +783,248 @@ var zora721Abi = parseAbi([
|
|
|
742
783
|
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
743
784
|
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
744
785
|
]);
|
|
745
|
-
var MintClient = class
|
|
746
|
-
constructor(chain,
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
apiClient = MintAPIClient;
|
|
750
|
-
}
|
|
751
|
-
this.apiClient = apiClient;
|
|
786
|
+
var MintClient = class {
|
|
787
|
+
constructor(chain, publicClient, httpClient2) {
|
|
788
|
+
this.apiClient = new MintAPIClient(chain.id, httpClient2);
|
|
789
|
+
this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
|
|
752
790
|
}
|
|
791
|
+
/**
|
|
792
|
+
* Gets mintable information for a given token
|
|
793
|
+
* @param param0.tokenContract The contract address of the token to mint.
|
|
794
|
+
* @param param0.tokenId The token id to mint.
|
|
795
|
+
* @returns
|
|
796
|
+
*/
|
|
753
797
|
async getMintable({
|
|
754
798
|
tokenContract,
|
|
755
799
|
tokenId
|
|
756
800
|
}) {
|
|
757
|
-
return this.apiClient.
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
},
|
|
762
|
-
{ token_id: tokenId?.toString() }
|
|
763
|
-
);
|
|
801
|
+
return await this.apiClient.getMintableForToken({
|
|
802
|
+
tokenContract,
|
|
803
|
+
tokenId: tokenId?.toString()
|
|
804
|
+
});
|
|
764
805
|
}
|
|
806
|
+
/**
|
|
807
|
+
* Returns the parameters needed to prepare a transaction mint a token.
|
|
808
|
+
* @param param0.minterAccount The account that will mint the token.
|
|
809
|
+
* @param param0.mintable The mintable token to mint.
|
|
810
|
+
* @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
|
|
811
|
+
* @returns
|
|
812
|
+
*/
|
|
765
813
|
async makePrepareMintTokenParams({
|
|
766
|
-
|
|
767
|
-
|
|
814
|
+
...rest
|
|
815
|
+
}) {
|
|
816
|
+
return makePrepareMintTokenParams({
|
|
817
|
+
...rest,
|
|
818
|
+
apiClient: this.apiClient,
|
|
819
|
+
publicClient: this.publicClient
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
824
|
+
* @param param0.mintable The mintable token to mint.
|
|
825
|
+
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
826
|
+
* @returns
|
|
827
|
+
*/
|
|
828
|
+
async getMintCosts({
|
|
768
829
|
mintable,
|
|
769
|
-
|
|
830
|
+
quantityToMint
|
|
770
831
|
}) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
}
|
|
780
|
-
if (!["zora_create", "zora_create_1155"].includes(
|
|
781
|
-
mintable.mint_context?.mint_context_type
|
|
782
|
-
)) {
|
|
783
|
-
throw new MintError(
|
|
784
|
-
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
const thisPublicClient = this.getPublicClient(publicClient);
|
|
788
|
-
if (mintable.mint_context.mint_context_type === "zora_create_1155") {
|
|
789
|
-
return {
|
|
790
|
-
simulateContractParameters: await this.prepareMintZora1155({
|
|
791
|
-
publicClient: thisPublicClient,
|
|
792
|
-
mintArguments,
|
|
793
|
-
sender: minterAccount,
|
|
794
|
-
mintable
|
|
795
|
-
})
|
|
796
|
-
};
|
|
832
|
+
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
833
|
+
if (mintContextType === "zora_create_1155") {
|
|
834
|
+
return await get1155MintCosts({
|
|
835
|
+
mintable,
|
|
836
|
+
price: BigInt(mintable.cost.native_price.raw),
|
|
837
|
+
publicClient: this.publicClient,
|
|
838
|
+
quantityToMint: BigInt(quantityToMint)
|
|
839
|
+
});
|
|
797
840
|
}
|
|
798
|
-
if (
|
|
799
|
-
return {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
mintable
|
|
805
|
-
})
|
|
806
|
-
};
|
|
841
|
+
if (mintContextType === "zora_create") {
|
|
842
|
+
return await get721MintCosts({
|
|
843
|
+
mintable,
|
|
844
|
+
publicClient: this.publicClient,
|
|
845
|
+
quantityToMint: BigInt(quantityToMint)
|
|
846
|
+
});
|
|
807
847
|
}
|
|
808
|
-
throw new
|
|
848
|
+
throw new MintError(
|
|
849
|
+
`Mintable type ${mintContextType} is currently unsupported.`
|
|
850
|
+
);
|
|
809
851
|
}
|
|
810
|
-
|
|
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");
|
|
936
|
+
}
|
|
937
|
+
const mintValue = (await get721MintCosts({
|
|
811
938
|
mintable,
|
|
812
|
-
sender,
|
|
813
939
|
publicClient,
|
|
814
|
-
mintArguments
|
|
815
|
-
})
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
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 || zeroAddress
|
|
953
|
+
]
|
|
954
|
+
};
|
|
955
|
+
return result;
|
|
956
|
+
}
|
|
957
|
+
async function get1155MintFee({
|
|
958
|
+
collectionAddress,
|
|
959
|
+
publicClient
|
|
960
|
+
}) {
|
|
961
|
+
return await publicClient.readContract({
|
|
962
|
+
abi: zoraCreator1155ImplABI,
|
|
963
|
+
functionName: "mintFee",
|
|
964
|
+
address: collectionAddress
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
async function get1155MintCosts({
|
|
968
|
+
mintable,
|
|
969
|
+
price,
|
|
970
|
+
publicClient,
|
|
971
|
+
quantityToMint
|
|
972
|
+
}) {
|
|
973
|
+
const address = mintable.collection.address;
|
|
974
|
+
const mintFee = await get1155MintFee({
|
|
975
|
+
collectionAddress: address,
|
|
976
|
+
publicClient
|
|
977
|
+
});
|
|
978
|
+
const mintFeeForTokens = mintFee * quantityToMint;
|
|
979
|
+
const tokenPurchaseCost = price * quantityToMint;
|
|
980
|
+
return {
|
|
981
|
+
mintFee: mintFeeForTokens,
|
|
982
|
+
tokenPurchaseCost,
|
|
983
|
+
totalCost: mintFeeForTokens + tokenPurchaseCost
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
async function makePrepareMint1155TokenParams({
|
|
987
|
+
apiClient,
|
|
988
|
+
publicClient,
|
|
989
|
+
minterAccount,
|
|
990
|
+
mintable,
|
|
991
|
+
mintContextType,
|
|
992
|
+
mintArguments
|
|
993
|
+
}) {
|
|
994
|
+
if (mintContextType !== "zora_create_1155") {
|
|
995
|
+
throw new Error("Minted token type must be for 1155");
|
|
849
996
|
}
|
|
850
|
-
|
|
997
|
+
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
998
|
+
const address = mintable.collection.address;
|
|
999
|
+
const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
|
|
1000
|
+
contractAddress: address,
|
|
1001
|
+
tokenId: BigInt(mintable.token_id)
|
|
1002
|
+
});
|
|
1003
|
+
const mintValue = (await get1155MintCosts({
|
|
851
1004
|
mintable,
|
|
1005
|
+
price: tokenFixedPriceMinter?.pricePerToken || BigInt(mintable.cost.native_price.raw),
|
|
852
1006
|
publicClient,
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
value: mintFee + BigInt(mintable.cost.native_price.raw) * BigInt(mintArguments.quantityToMint),
|
|
868
|
-
/* args: mint recipient, quantity to mint, mint comment, mintReferral */
|
|
869
|
-
args: [
|
|
1007
|
+
quantityToMint: mintQuantity
|
|
1008
|
+
})).totalCost;
|
|
1009
|
+
const result = {
|
|
1010
|
+
abi: zoraCreator1155ImplABI,
|
|
1011
|
+
functionName: "mintWithRewards",
|
|
1012
|
+
account: minterAccount,
|
|
1013
|
+
value: mintValue,
|
|
1014
|
+
address,
|
|
1015
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1016
|
+
args: [
|
|
1017
|
+
tokenFixedPriceMinter?.address || zoraCreatorFixedPriceSaleStrategyAddress2[999],
|
|
1018
|
+
BigInt(mintable.token_id),
|
|
1019
|
+
mintQuantity,
|
|
1020
|
+
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
870
1021
|
mintArguments.mintToAddress,
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
function createMintClient({
|
|
880
|
-
chain,
|
|
881
|
-
mintAPIClient
|
|
882
|
-
}) {
|
|
883
|
-
return new MintClient(chain, mintAPIClient);
|
|
1022
|
+
mintArguments.mintComment || ""
|
|
1023
|
+
]),
|
|
1024
|
+
mintArguments.mintReferral || zeroAddress
|
|
1025
|
+
]
|
|
1026
|
+
};
|
|
1027
|
+
return result;
|
|
884
1028
|
}
|
|
885
1029
|
|
|
886
1030
|
// src/create/1155-create-helper.ts
|
|
@@ -904,7 +1048,7 @@ var DEFAULT_SALE_SETTINGS = {
|
|
|
904
1048
|
// 0 Here means no limit
|
|
905
1049
|
maxTokensPerAddress: 0n
|
|
906
1050
|
};
|
|
907
|
-
var PERMISSION_BIT_MINTER =
|
|
1051
|
+
var PERMISSION_BIT_MINTER = 4n;
|
|
908
1052
|
function create1155TokenSetupArgs({
|
|
909
1053
|
nextTokenId,
|
|
910
1054
|
// How many NFTs upon initialization to mint to the creator
|
|
@@ -1148,8 +1292,9 @@ export {
|
|
|
1148
1292
|
createMintClient,
|
|
1149
1293
|
createPremintClient,
|
|
1150
1294
|
encodePremintForAPI,
|
|
1295
|
+
get1155MintCosts,
|
|
1296
|
+
getApiNetworkConfigForChain,
|
|
1151
1297
|
getPremintedLogFromReceipt,
|
|
1152
|
-
getSalesConfigFixedPrice,
|
|
1153
1298
|
getTokenIdFromCreateReceipt,
|
|
1154
1299
|
preminterTypedDataDefinition
|
|
1155
1300
|
};
|