@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.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,125 @@ 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!) {
|
|
291
|
+
zoraCreateToken(id: $id) {
|
|
292
|
+
id
|
|
293
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
294
|
+
type
|
|
295
|
+
fixedPrice {
|
|
296
|
+
address
|
|
297
|
+
pricePerToken
|
|
298
|
+
saleEnd
|
|
299
|
+
saleStart
|
|
300
|
+
maxTokensPerAddress
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}`,
|
|
305
|
+
variables: {
|
|
306
|
+
id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
const fixedPrice = response.data?.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPrice;
|
|
310
|
+
return {
|
|
311
|
+
address: fixedPrice.address,
|
|
312
|
+
pricePerToken: BigInt(fixedPrice.pricePerToken)
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
async getMintableForToken({
|
|
317
|
+
tokenContract,
|
|
318
|
+
tokenId
|
|
319
|
+
}) {
|
|
320
|
+
return await this.getMintable(
|
|
321
|
+
{
|
|
322
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
323
|
+
collection_address: tokenContract
|
|
324
|
+
},
|
|
325
|
+
{ token_id: tokenId?.toString() }
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// src/premint/premint-api-client.ts
|
|
331
|
+
var postSignature = async ({
|
|
332
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
333
|
+
...data
|
|
334
|
+
}) => retries2(
|
|
335
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
336
|
+
);
|
|
337
|
+
var getNextUID = async ({
|
|
338
|
+
chain_name,
|
|
339
|
+
collection_address,
|
|
340
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
341
|
+
}) => retries2(
|
|
342
|
+
() => get2(
|
|
343
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
|
|
344
|
+
)
|
|
345
|
+
);
|
|
346
|
+
var getSignature = async ({
|
|
347
|
+
collection_address,
|
|
348
|
+
uid,
|
|
349
|
+
chain_name,
|
|
350
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
351
|
+
}) => retries2(
|
|
352
|
+
() => get2(
|
|
353
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
var PremintAPIClient = class {
|
|
357
|
+
constructor(chainId, httpClient2) {
|
|
358
|
+
this.postSignature = async (data) => postSignature({
|
|
359
|
+
...data,
|
|
360
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
361
|
+
httpClient: this.httpClient
|
|
362
|
+
});
|
|
363
|
+
this.getNextUID = async (path) => getNextUID({
|
|
364
|
+
...path,
|
|
365
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
366
|
+
httpClient: this.httpClient
|
|
367
|
+
});
|
|
368
|
+
this.getSignature = async ({
|
|
369
|
+
collection_address,
|
|
370
|
+
uid
|
|
371
|
+
}) => getSignature({
|
|
372
|
+
collection_address,
|
|
373
|
+
uid,
|
|
374
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
375
|
+
httpClient: this.httpClient
|
|
376
|
+
});
|
|
377
|
+
this.httpClient = httpClient2 || httpClient;
|
|
378
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
298
379
|
}
|
|
299
380
|
};
|
|
300
381
|
|
|
@@ -313,7 +394,7 @@ var DefaultMintArguments = {
|
|
|
313
394
|
function getPremintedLogFromReceipt(receipt) {
|
|
314
395
|
for (const data of receipt.logs) {
|
|
315
396
|
try {
|
|
316
|
-
const decodedLog = (0,
|
|
397
|
+
const decodedLog = (0, import_viem2.decodeEventLog)({
|
|
317
398
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
318
399
|
eventName: "Preminted",
|
|
319
400
|
...data
|
|
@@ -356,13 +437,11 @@ var encodePremintForAPI = ({
|
|
|
356
437
|
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
357
438
|
}
|
|
358
439
|
});
|
|
359
|
-
var PremintClient = class
|
|
360
|
-
constructor(chain,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
this.apiClient = apiClient;
|
|
440
|
+
var PremintClient = class {
|
|
441
|
+
constructor(chain, publicClient, httpClient2) {
|
|
442
|
+
this.chain = chain;
|
|
443
|
+
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
444
|
+
this.publicClient = publicClient || (0, import_viem2.createPublicClient)({ chain, transport: (0, import_viem2.http)() });
|
|
366
445
|
}
|
|
367
446
|
/**
|
|
368
447
|
* The premint executor address is deployed to the same address across all chains.
|
|
@@ -419,7 +498,6 @@ var PremintClient = class extends ClientBase {
|
|
|
419
498
|
account
|
|
420
499
|
}) {
|
|
421
500
|
const signatureResponse = await this.apiClient.getSignature({
|
|
422
|
-
chain_name: this.network.zoraBackendChainName,
|
|
423
501
|
collection_address: collection.toLowerCase(),
|
|
424
502
|
uid
|
|
425
503
|
});
|
|
@@ -439,7 +517,6 @@ var PremintClient = class extends ClientBase {
|
|
|
439
517
|
account,
|
|
440
518
|
checkSignature: false,
|
|
441
519
|
verifyingContract: collection,
|
|
442
|
-
publicClient: this.getPublicClient(),
|
|
443
520
|
uid,
|
|
444
521
|
collection: {
|
|
445
522
|
...signerData.collection,
|
|
@@ -466,11 +543,9 @@ var PremintClient = class extends ClientBase {
|
|
|
466
543
|
walletClient,
|
|
467
544
|
uid,
|
|
468
545
|
account,
|
|
469
|
-
collection
|
|
470
|
-
publicClient
|
|
546
|
+
collection
|
|
471
547
|
}) {
|
|
472
548
|
const signatureResponse = await this.apiClient.getSignature({
|
|
473
|
-
chain_name: this.network.zoraBackendChainName,
|
|
474
549
|
collection_address: collection.toLowerCase(),
|
|
475
550
|
uid
|
|
476
551
|
});
|
|
@@ -487,7 +562,6 @@ var PremintClient = class extends ClientBase {
|
|
|
487
562
|
account,
|
|
488
563
|
checkSignature: false,
|
|
489
564
|
verifyingContract: collection,
|
|
490
|
-
publicClient: this.getPublicClient(publicClient),
|
|
491
565
|
uid,
|
|
492
566
|
collection: signerData.collection,
|
|
493
567
|
premintConfig: signerData.premint
|
|
@@ -501,7 +575,6 @@ var PremintClient = class extends ClientBase {
|
|
|
501
575
|
*/
|
|
502
576
|
async signAndSubmitPremint({
|
|
503
577
|
walletClient,
|
|
504
|
-
publicClient,
|
|
505
578
|
verifyingContract,
|
|
506
579
|
premintConfig,
|
|
507
580
|
uid,
|
|
@@ -524,7 +597,7 @@ var PremintClient = class extends ClientBase {
|
|
|
524
597
|
})
|
|
525
598
|
});
|
|
526
599
|
if (checkSignature) {
|
|
527
|
-
const [isValidSignature] = await publicClient.readContract({
|
|
600
|
+
const [isValidSignature] = await this.publicClient.readContract({
|
|
528
601
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
529
602
|
address: this.getExecutorAddress(),
|
|
530
603
|
functionName: "isValidSignature",
|
|
@@ -537,7 +610,6 @@ var PremintClient = class extends ClientBase {
|
|
|
537
610
|
const apiData = {
|
|
538
611
|
collection,
|
|
539
612
|
premint: encodePremintForAPI(premintConfig),
|
|
540
|
-
chain_name: this.network.zoraBackendChainName,
|
|
541
613
|
signature
|
|
542
614
|
};
|
|
543
615
|
const premint = await this.apiClient.postSignature(apiData);
|
|
@@ -567,13 +639,11 @@ var PremintClient = class extends ClientBase {
|
|
|
567
639
|
account,
|
|
568
640
|
collection,
|
|
569
641
|
token,
|
|
570
|
-
publicClient,
|
|
571
642
|
walletClient,
|
|
572
643
|
executionSettings,
|
|
573
644
|
checkSignature = false
|
|
574
645
|
}) {
|
|
575
|
-
|
|
576
|
-
const newContractAddress = await publicClient.readContract({
|
|
646
|
+
const newContractAddress = await this.publicClient.readContract({
|
|
577
647
|
address: this.getExecutorAddress(),
|
|
578
648
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
579
649
|
functionName: "getContractAddress",
|
|
@@ -588,7 +658,6 @@ var PremintClient = class extends ClientBase {
|
|
|
588
658
|
let uid = executionSettings?.uid;
|
|
589
659
|
if (!uid) {
|
|
590
660
|
const uidResponse = await this.apiClient.getNextUID({
|
|
591
|
-
chain_name: this.network.zoraBackendChainName,
|
|
592
661
|
collection_address: newContractAddress.toLowerCase()
|
|
593
662
|
});
|
|
594
663
|
uid = uidResponse.next_uid;
|
|
@@ -609,7 +678,6 @@ var PremintClient = class extends ClientBase {
|
|
|
609
678
|
premintConfig,
|
|
610
679
|
checkSignature,
|
|
611
680
|
account,
|
|
612
|
-
publicClient,
|
|
613
681
|
walletClient,
|
|
614
682
|
collection
|
|
615
683
|
});
|
|
@@ -626,7 +694,6 @@ var PremintClient = class extends ClientBase {
|
|
|
626
694
|
uid
|
|
627
695
|
}) {
|
|
628
696
|
return await this.apiClient.getSignature({
|
|
629
|
-
chain_name: this.network.zoraBackendChainName,
|
|
630
697
|
collection_address: address,
|
|
631
698
|
uid
|
|
632
699
|
});
|
|
@@ -638,11 +705,9 @@ var PremintClient = class extends ClientBase {
|
|
|
638
705
|
* @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
|
|
639
706
|
*/
|
|
640
707
|
async isValidSignature({
|
|
641
|
-
data
|
|
642
|
-
publicClient
|
|
708
|
+
data
|
|
643
709
|
}) {
|
|
644
|
-
|
|
645
|
-
const [isValid, contractAddress, recoveredSigner] = await publicClient.readContract({
|
|
710
|
+
const [isValid, contractAddress, recoveredSigner] = await this.publicClient.readContract({
|
|
646
711
|
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
647
712
|
address: this.getExecutorAddress(),
|
|
648
713
|
functionName: "isValidSignature",
|
|
@@ -663,10 +728,11 @@ var PremintClient = class extends ClientBase {
|
|
|
663
728
|
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
664
729
|
}
|
|
665
730
|
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
731
|
+
const network = getApiNetworkConfigForChain(this.chain.id);
|
|
666
732
|
return {
|
|
667
733
|
explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
668
|
-
zoraCollect: `https://${
|
|
669
|
-
zoraManage: `https://${
|
|
734
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
735
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
670
736
|
};
|
|
671
737
|
}
|
|
672
738
|
/**
|
|
@@ -681,7 +747,7 @@ var PremintClient = class extends ClientBase {
|
|
|
681
747
|
* @param settings.publicClient Optional public client for preflight checks.
|
|
682
748
|
* @returns receipt, log, zoraURL
|
|
683
749
|
*/
|
|
684
|
-
async
|
|
750
|
+
async makeMintParameters({
|
|
685
751
|
data,
|
|
686
752
|
account,
|
|
687
753
|
mintArguments
|
|
@@ -710,45 +776,19 @@ var PremintClient = class extends ClientBase {
|
|
|
710
776
|
address: targetAddress,
|
|
711
777
|
args
|
|
712
778
|
};
|
|
713
|
-
return
|
|
714
|
-
request
|
|
715
|
-
};
|
|
779
|
+
return request;
|
|
716
780
|
}
|
|
717
781
|
};
|
|
718
782
|
function createPremintClient({
|
|
719
783
|
chain,
|
|
720
|
-
|
|
784
|
+
httpClient: httpClient2,
|
|
785
|
+
publicClient
|
|
721
786
|
}) {
|
|
722
|
-
return new PremintClient(chain,
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// src/mint/mint-api-client.ts
|
|
726
|
-
function encodeQueryParameters(params) {
|
|
727
|
-
return new URLSearchParams(params).toString();
|
|
787
|
+
return new PremintClient(chain, publicClient, httpClient2);
|
|
728
788
|
}
|
|
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
789
|
|
|
750
790
|
// src/mint/mint-client.ts
|
|
751
|
-
var
|
|
791
|
+
var import_viem3 = require("viem");
|
|
752
792
|
var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
|
|
753
793
|
var MintError = class extends Error {
|
|
754
794
|
};
|
|
@@ -758,158 +798,261 @@ var Errors = {
|
|
|
758
798
|
MintError,
|
|
759
799
|
MintInactiveError
|
|
760
800
|
};
|
|
761
|
-
var zora721Abi = (0,
|
|
801
|
+
var zora721Abi = (0, import_viem3.parseAbi)([
|
|
762
802
|
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
763
803
|
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
764
804
|
]);
|
|
765
|
-
var MintClient = class
|
|
766
|
-
constructor(chain,
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
apiClient = MintAPIClient;
|
|
770
|
-
}
|
|
771
|
-
this.apiClient = apiClient;
|
|
805
|
+
var MintClient = class {
|
|
806
|
+
constructor(chain, publicClient, httpClient2) {
|
|
807
|
+
this.apiClient = new MintAPIClient(chain.id, httpClient2);
|
|
808
|
+
this.publicClient = publicClient || (0, import_viem3.createPublicClient)({ chain, transport: (0, import_viem3.http)() });
|
|
772
809
|
}
|
|
810
|
+
/**
|
|
811
|
+
* Gets mintable information for a given token
|
|
812
|
+
* @param param0.tokenContract The contract address of the token to mint.
|
|
813
|
+
* @param param0.tokenId The token id to mint.
|
|
814
|
+
* @returns
|
|
815
|
+
*/
|
|
773
816
|
async getMintable({
|
|
774
817
|
tokenContract,
|
|
775
818
|
tokenId
|
|
776
819
|
}) {
|
|
777
|
-
return this.apiClient.
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
},
|
|
782
|
-
{ token_id: tokenId?.toString() }
|
|
783
|
-
);
|
|
820
|
+
return await this.apiClient.getMintableForToken({
|
|
821
|
+
tokenContract,
|
|
822
|
+
tokenId: tokenId?.toString()
|
|
823
|
+
});
|
|
784
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* Returns the parameters needed to prepare a transaction mint a token.
|
|
827
|
+
* @param param0.minterAccount The account that will mint the token.
|
|
828
|
+
* @param param0.mintable The mintable token to mint.
|
|
829
|
+
* @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
|
|
830
|
+
* @returns
|
|
831
|
+
*/
|
|
785
832
|
async makePrepareMintTokenParams({
|
|
786
|
-
|
|
787
|
-
|
|
833
|
+
...rest
|
|
834
|
+
}) {
|
|
835
|
+
return makePrepareMintTokenParams({
|
|
836
|
+
...rest,
|
|
837
|
+
apiClient: this.apiClient,
|
|
838
|
+
publicClient: this.publicClient
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
843
|
+
* @param param0.mintable The mintable token to mint.
|
|
844
|
+
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
845
|
+
* @returns
|
|
846
|
+
*/
|
|
847
|
+
async getMintCosts({
|
|
788
848
|
mintable,
|
|
789
|
-
|
|
849
|
+
quantityToMint
|
|
790
850
|
}) {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
-
};
|
|
851
|
+
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
852
|
+
if (mintContextType === "zora_create_1155") {
|
|
853
|
+
return await get1155MintCosts({
|
|
854
|
+
mintable,
|
|
855
|
+
price: BigInt(mintable.cost.native_price.raw),
|
|
856
|
+
publicClient: this.publicClient,
|
|
857
|
+
quantityToMint: BigInt(quantityToMint)
|
|
858
|
+
});
|
|
817
859
|
}
|
|
818
|
-
if (
|
|
819
|
-
return {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
mintable
|
|
825
|
-
})
|
|
826
|
-
};
|
|
860
|
+
if (mintContextType === "zora_create") {
|
|
861
|
+
return await get721MintCosts({
|
|
862
|
+
mintable,
|
|
863
|
+
publicClient: this.publicClient,
|
|
864
|
+
quantityToMint: BigInt(quantityToMint)
|
|
865
|
+
});
|
|
827
866
|
}
|
|
828
|
-
throw new
|
|
867
|
+
throw new MintError(
|
|
868
|
+
`Mintable type ${mintContextType} is currently unsupported.`
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
function createMintClient({
|
|
873
|
+
chain,
|
|
874
|
+
publicClient,
|
|
875
|
+
httpClient: httpClient2
|
|
876
|
+
}) {
|
|
877
|
+
return new MintClient(chain, publicClient, httpClient2);
|
|
878
|
+
}
|
|
879
|
+
function validateMintableAndGetContextType(mintable) {
|
|
880
|
+
if (!mintable) {
|
|
881
|
+
throw new MintError("No mintable found");
|
|
882
|
+
}
|
|
883
|
+
if (!mintable.is_active) {
|
|
884
|
+
throw new MintInactiveError("Minting token is inactive");
|
|
885
|
+
}
|
|
886
|
+
if (!mintable.mint_context) {
|
|
887
|
+
throw new MintError("No minting context data from zora API");
|
|
888
|
+
}
|
|
889
|
+
if (!["zora_create", "zora_create_1155"].includes(
|
|
890
|
+
mintable.mint_context?.mint_context_type
|
|
891
|
+
)) {
|
|
892
|
+
throw new MintError(
|
|
893
|
+
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
return mintable.mint_context.mint_context_type;
|
|
897
|
+
}
|
|
898
|
+
async function makePrepareMintTokenParams({
|
|
899
|
+
publicClient,
|
|
900
|
+
mintable,
|
|
901
|
+
apiClient,
|
|
902
|
+
...rest
|
|
903
|
+
}) {
|
|
904
|
+
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
905
|
+
const thisPublicClient = publicClient;
|
|
906
|
+
if (mintContextType === "zora_create_1155") {
|
|
907
|
+
return makePrepareMint1155TokenParams({
|
|
908
|
+
apiClient,
|
|
909
|
+
publicClient: thisPublicClient,
|
|
910
|
+
mintable,
|
|
911
|
+
mintContextType,
|
|
912
|
+
...rest
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
if (mintContextType === "zora_create") {
|
|
916
|
+
return makePrepareMint721TokenParams({
|
|
917
|
+
publicClient: thisPublicClient,
|
|
918
|
+
mintable,
|
|
919
|
+
mintContextType,
|
|
920
|
+
...rest
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
throw new MintError(
|
|
924
|
+
`Mintable type ${mintContextType} is currently unsupported.`
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
async function get721MintCosts({
|
|
928
|
+
mintable,
|
|
929
|
+
publicClient,
|
|
930
|
+
quantityToMint
|
|
931
|
+
}) {
|
|
932
|
+
const address = mintable.collection.address;
|
|
933
|
+
const [_, mintFee] = await publicClient.readContract({
|
|
934
|
+
abi: zora721Abi,
|
|
935
|
+
address,
|
|
936
|
+
functionName: "zoraFeeForAmount",
|
|
937
|
+
args: [BigInt(quantityToMint)]
|
|
938
|
+
});
|
|
939
|
+
const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
940
|
+
return {
|
|
941
|
+
mintFee,
|
|
942
|
+
tokenPurchaseCost,
|
|
943
|
+
totalCost: mintFee + tokenPurchaseCost
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
async function makePrepareMint721TokenParams({
|
|
947
|
+
publicClient,
|
|
948
|
+
minterAccount,
|
|
949
|
+
mintable,
|
|
950
|
+
mintContextType,
|
|
951
|
+
mintArguments
|
|
952
|
+
}) {
|
|
953
|
+
if (mintContextType !== "zora_create") {
|
|
954
|
+
throw new Error("Minted token type must be for 1155");
|
|
829
955
|
}
|
|
830
|
-
|
|
956
|
+
const mintValue = (await get721MintCosts({
|
|
831
957
|
mintable,
|
|
832
|
-
sender,
|
|
833
958
|
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
|
-
|
|
959
|
+
quantityToMint: BigInt(mintArguments.quantityToMint)
|
|
960
|
+
})).totalCost;
|
|
961
|
+
const result = {
|
|
962
|
+
abi: zora721Abi,
|
|
963
|
+
address: mintable.contract_address,
|
|
964
|
+
account: minterAccount,
|
|
965
|
+
functionName: "mintWithRewards",
|
|
966
|
+
value: mintValue,
|
|
967
|
+
args: [
|
|
968
|
+
mintArguments.mintToAddress,
|
|
969
|
+
BigInt(mintArguments.quantityToMint),
|
|
970
|
+
mintArguments.mintComment || "",
|
|
971
|
+
mintArguments.mintReferral || import_viem3.zeroAddress
|
|
972
|
+
]
|
|
973
|
+
};
|
|
974
|
+
return result;
|
|
975
|
+
}
|
|
976
|
+
async function get1155MintFee({
|
|
977
|
+
collectionAddress,
|
|
978
|
+
publicClient
|
|
979
|
+
}) {
|
|
980
|
+
return await publicClient.readContract({
|
|
981
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
982
|
+
functionName: "mintFee",
|
|
983
|
+
address: collectionAddress
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
async function get1155MintCosts({
|
|
987
|
+
mintable,
|
|
988
|
+
price,
|
|
989
|
+
publicClient,
|
|
990
|
+
quantityToMint
|
|
991
|
+
}) {
|
|
992
|
+
const address = mintable.collection.address;
|
|
993
|
+
const mintFee = await get1155MintFee({
|
|
994
|
+
collectionAddress: address,
|
|
995
|
+
publicClient
|
|
996
|
+
});
|
|
997
|
+
const mintFeeForTokens = mintFee * quantityToMint;
|
|
998
|
+
const tokenPurchaseCost = price * quantityToMint;
|
|
999
|
+
return {
|
|
1000
|
+
mintFee: mintFeeForTokens,
|
|
1001
|
+
tokenPurchaseCost,
|
|
1002
|
+
totalCost: mintFeeForTokens + tokenPurchaseCost
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
async function makePrepareMint1155TokenParams({
|
|
1006
|
+
apiClient,
|
|
1007
|
+
publicClient,
|
|
1008
|
+
minterAccount,
|
|
1009
|
+
mintable,
|
|
1010
|
+
mintContextType,
|
|
1011
|
+
mintArguments
|
|
1012
|
+
}) {
|
|
1013
|
+
if (mintContextType !== "zora_create_1155") {
|
|
1014
|
+
throw new Error("Minted token type must be for 1155");
|
|
869
1015
|
}
|
|
870
|
-
|
|
1016
|
+
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
1017
|
+
const address = mintable.collection.address;
|
|
1018
|
+
const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
|
|
1019
|
+
contractAddress: address,
|
|
1020
|
+
tokenId: BigInt(mintable.token_id)
|
|
1021
|
+
});
|
|
1022
|
+
const mintValue = (await get1155MintCosts({
|
|
871
1023
|
mintable,
|
|
1024
|
+
price: tokenFixedPriceMinter?.pricePerToken || BigInt(mintable.cost.native_price.raw),
|
|
872
1025
|
publicClient,
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
value: mintFee + BigInt(mintable.cost.native_price.raw) * BigInt(mintArguments.quantityToMint),
|
|
888
|
-
/* args: mint recipient, quantity to mint, mint comment, mintReferral */
|
|
889
|
-
args: [
|
|
1026
|
+
quantityToMint: mintQuantity
|
|
1027
|
+
})).totalCost;
|
|
1028
|
+
const result = {
|
|
1029
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
1030
|
+
functionName: "mintWithRewards",
|
|
1031
|
+
account: minterAccount,
|
|
1032
|
+
value: mintValue,
|
|
1033
|
+
address,
|
|
1034
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1035
|
+
args: [
|
|
1036
|
+
tokenFixedPriceMinter?.address || import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999],
|
|
1037
|
+
BigInt(mintable.token_id),
|
|
1038
|
+
mintQuantity,
|
|
1039
|
+
(0, import_viem3.encodeAbiParameters)((0, import_viem3.parseAbiParameters)("address, string"), [
|
|
890
1040
|
mintArguments.mintToAddress,
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
function createMintClient({
|
|
900
|
-
chain,
|
|
901
|
-
mintAPIClient
|
|
902
|
-
}) {
|
|
903
|
-
return new MintClient(chain, mintAPIClient);
|
|
1041
|
+
mintArguments.mintComment || ""
|
|
1042
|
+
]),
|
|
1043
|
+
mintArguments.mintReferral || import_viem3.zeroAddress
|
|
1044
|
+
]
|
|
1045
|
+
};
|
|
1046
|
+
return result;
|
|
904
1047
|
}
|
|
905
1048
|
|
|
906
1049
|
// src/create/1155-create-helper.ts
|
|
907
1050
|
var import_protocol_deployments3 = require("@zoralabs/protocol-deployments");
|
|
908
|
-
var
|
|
1051
|
+
var import_viem4 = require("viem");
|
|
909
1052
|
var SALE_END_FOREVER = 18446744073709551615n;
|
|
910
1053
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
911
1054
|
var DEFAULT_SALE_SETTINGS = {
|
|
912
|
-
fundsRecipient:
|
|
1055
|
+
fundsRecipient: import_viem4.zeroAddress,
|
|
913
1056
|
// Free Mint
|
|
914
1057
|
pricePerToken: 0n,
|
|
915
1058
|
// Sale start time – defaults to beginning of unix time
|
|
@@ -919,7 +1062,7 @@ var DEFAULT_SALE_SETTINGS = {
|
|
|
919
1062
|
// 0 Here means no limit
|
|
920
1063
|
maxTokensPerAddress: 0n
|
|
921
1064
|
};
|
|
922
|
-
var PERMISSION_BIT_MINTER =
|
|
1065
|
+
var PERMISSION_BIT_MINTER = 4n;
|
|
923
1066
|
function create1155TokenSetupArgs({
|
|
924
1067
|
nextTokenId,
|
|
925
1068
|
// How many NFTs upon initialization to mint to the creator
|
|
@@ -948,32 +1091,32 @@ function create1155TokenSetupArgs({
|
|
|
948
1091
|
...salesConfig
|
|
949
1092
|
};
|
|
950
1093
|
const setupActions = [
|
|
951
|
-
(0,
|
|
1094
|
+
(0, import_viem4.encodeFunctionData)({
|
|
952
1095
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
953
1096
|
functionName: "assumeLastTokenIdMatches",
|
|
954
1097
|
args: [nextTokenId - 1n]
|
|
955
1098
|
}),
|
|
956
|
-
createReferral ? (0,
|
|
1099
|
+
createReferral ? (0, import_viem4.encodeFunctionData)({
|
|
957
1100
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
958
1101
|
functionName: "setupNewTokenWithCreateReferral",
|
|
959
1102
|
args: [tokenMetadataURI, maxSupply, createReferral]
|
|
960
|
-
}) : (0,
|
|
1103
|
+
}) : (0, import_viem4.encodeFunctionData)({
|
|
961
1104
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
962
1105
|
functionName: "setupNewToken",
|
|
963
1106
|
args: [tokenMetadataURI, maxSupply]
|
|
964
1107
|
}),
|
|
965
|
-
(0,
|
|
1108
|
+
(0, import_viem4.encodeFunctionData)({
|
|
966
1109
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
967
1110
|
functionName: "addPermission",
|
|
968
1111
|
args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
|
|
969
1112
|
}),
|
|
970
|
-
(0,
|
|
1113
|
+
(0, import_viem4.encodeFunctionData)({
|
|
971
1114
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
972
1115
|
functionName: "callSale",
|
|
973
1116
|
args: [
|
|
974
1117
|
nextTokenId,
|
|
975
1118
|
fixedPriceMinterAddress,
|
|
976
|
-
(0,
|
|
1119
|
+
(0, import_viem4.encodeFunctionData)({
|
|
977
1120
|
abi: import_protocol_deployments3.zoraCreatorFixedPriceSaleStrategyABI,
|
|
978
1121
|
functionName: "setSale",
|
|
979
1122
|
args: [nextTokenId, salesConfigWithDefaults]
|
|
@@ -983,7 +1126,7 @@ function create1155TokenSetupArgs({
|
|
|
983
1126
|
];
|
|
984
1127
|
if (mintToCreatorCount) {
|
|
985
1128
|
setupActions.push(
|
|
986
|
-
(0,
|
|
1129
|
+
(0, import_viem4.encodeFunctionData)({
|
|
987
1130
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
988
1131
|
functionName: "adminMint",
|
|
989
1132
|
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
@@ -992,7 +1135,7 @@ function create1155TokenSetupArgs({
|
|
|
992
1135
|
}
|
|
993
1136
|
if (royaltySettings) {
|
|
994
1137
|
setupActions.push(
|
|
995
|
-
(0,
|
|
1138
|
+
(0, import_viem4.encodeFunctionData)({
|
|
996
1139
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
997
1140
|
functionName: "updateRoyaltiesForToken",
|
|
998
1141
|
args: [
|
|
@@ -1011,7 +1154,7 @@ function create1155TokenSetupArgs({
|
|
|
1011
1154
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
1012
1155
|
for (const data of receipt.logs) {
|
|
1013
1156
|
try {
|
|
1014
|
-
const decodedLog = (0,
|
|
1157
|
+
const decodedLog = (0, import_viem4.decodeEventLog)({
|
|
1015
1158
|
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
1016
1159
|
eventName: "SetupNewToken",
|
|
1017
1160
|
...data
|
|
@@ -1164,8 +1307,9 @@ function create1155CreatorClient({
|
|
|
1164
1307
|
createMintClient,
|
|
1165
1308
|
createPremintClient,
|
|
1166
1309
|
encodePremintForAPI,
|
|
1310
|
+
get1155MintCosts,
|
|
1311
|
+
getApiNetworkConfigForChain,
|
|
1167
1312
|
getPremintedLogFromReceipt,
|
|
1168
|
-
getSalesConfigFixedPrice,
|
|
1169
1313
|
getTokenIdFromCreateReceipt,
|
|
1170
1314
|
preminterTypedDataDefinition
|
|
1171
1315
|
});
|