@zoralabs/protocol-sdk 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +12 -0
- package/README.md +23 -32
- package/dist/anvil.d.ts +1 -1
- package/dist/index.cjs +423 -254
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +420 -253
- package/dist/index.js.map +1 -1
- package/dist/premint/contract-types.d.ts +125 -0
- package/dist/premint/contract-types.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +14 -7
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +39 -155
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +28 -34
- package/dist/premint/preminter.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/anvil.ts +1 -1
- package/src/index.ts +2 -0
- package/src/premint/contract-types.ts +109 -0
- package/src/premint/premint-api-client.ts +162 -22
- package/src/premint/premint-client.test.ts +188 -87
- package/src/premint/premint-client.ts +330 -314
- package/src/premint/preminter.test.ts +9 -7
- package/src/premint/preminter.ts +107 -121
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/premint/premint-client.ts
|
|
2
|
-
import { createPublicClient, decodeEventLog, http } from "viem";
|
|
2
|
+
import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
|
|
3
3
|
import {
|
|
4
4
|
zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2,
|
|
5
5
|
zoraCreatorFixedPriceSaleStrategyAddress
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
concat,
|
|
20
20
|
recoverAddress
|
|
21
21
|
} from "viem";
|
|
22
|
+
|
|
23
|
+
// src/premint/contract-types.ts
|
|
22
24
|
var v1Types = {
|
|
23
25
|
CreatorAttribution: [
|
|
24
26
|
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
@@ -68,10 +70,13 @@ var v2Types = {
|
|
|
68
70
|
]
|
|
69
71
|
};
|
|
70
72
|
var PreminterDomain = "Preminter";
|
|
71
|
-
var PremintConfigVersion = {
|
|
72
|
-
V1
|
|
73
|
-
V2
|
|
74
|
-
|
|
73
|
+
var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
|
|
74
|
+
PremintConfigVersion2["V1"] = "1";
|
|
75
|
+
PremintConfigVersion2["V2"] = "2";
|
|
76
|
+
return PremintConfigVersion2;
|
|
77
|
+
})(PremintConfigVersion || {});
|
|
78
|
+
|
|
79
|
+
// src/premint/preminter.ts
|
|
75
80
|
var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
|
|
76
81
|
var premintTypedDataDefinition = ({
|
|
77
82
|
verifyingContract,
|
|
@@ -85,14 +90,14 @@ var premintTypedDataDefinition = ({
|
|
|
85
90
|
version,
|
|
86
91
|
verifyingContract
|
|
87
92
|
};
|
|
88
|
-
if (version ===
|
|
93
|
+
if (version === "1" /* V1 */)
|
|
89
94
|
return {
|
|
90
95
|
domain,
|
|
91
96
|
types: v1Types,
|
|
92
97
|
message: premintConfig,
|
|
93
98
|
primaryType: "CreatorAttribution"
|
|
94
99
|
};
|
|
95
|
-
if (version ===
|
|
100
|
+
if (version === "2" /* V2 */) {
|
|
96
101
|
return {
|
|
97
102
|
domain,
|
|
98
103
|
types: v2Types,
|
|
@@ -111,7 +116,7 @@ async function isAuthorizedToCreatePremint({
|
|
|
111
116
|
signature,
|
|
112
117
|
signer
|
|
113
118
|
}) {
|
|
114
|
-
if (premintConfigVersion ===
|
|
119
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
115
120
|
const [isValidSignature2] = await publicClient.readContract({
|
|
116
121
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
117
122
|
address: getPremintExecutorAddress(),
|
|
@@ -234,14 +239,28 @@ var recoverCreatorFromCreatorAttribution = async ({
|
|
|
234
239
|
signature
|
|
235
240
|
});
|
|
236
241
|
};
|
|
237
|
-
var
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
var supportedPremintVersions = async ({
|
|
243
|
+
tokenContract,
|
|
244
|
+
publicClient
|
|
245
|
+
}) => {
|
|
246
|
+
try {
|
|
247
|
+
return await publicClient.readContract({
|
|
248
|
+
abi: preminterAbi,
|
|
249
|
+
address: getPremintExecutorAddress(),
|
|
250
|
+
functionName: "supportedPremintSignatureVersions",
|
|
251
|
+
args: [tokenContract]
|
|
252
|
+
});
|
|
253
|
+
} catch (e) {
|
|
254
|
+
console.error(e);
|
|
255
|
+
return ["1"];
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var supportsPremintVersion = async ({
|
|
259
|
+
version,
|
|
260
|
+
tokenContract,
|
|
261
|
+
publicClient
|
|
262
|
+
}) => {
|
|
263
|
+
return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
|
|
245
264
|
};
|
|
246
265
|
async function getPremintCollectionAddress({
|
|
247
266
|
collection,
|
|
@@ -254,6 +273,42 @@ async function getPremintCollectionAddress({
|
|
|
254
273
|
args: [collection]
|
|
255
274
|
});
|
|
256
275
|
}
|
|
276
|
+
function markPremintDeleted(premintConfig) {
|
|
277
|
+
return {
|
|
278
|
+
...premintConfig,
|
|
279
|
+
version: premintConfig.version + 1,
|
|
280
|
+
deleted: true
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function applyUpdateToPremint({
|
|
284
|
+
uid,
|
|
285
|
+
version,
|
|
286
|
+
tokenConfig,
|
|
287
|
+
tokenConfigUpdates
|
|
288
|
+
}) {
|
|
289
|
+
const updatedTokenConfig = {
|
|
290
|
+
...tokenConfig,
|
|
291
|
+
...tokenConfigUpdates
|
|
292
|
+
};
|
|
293
|
+
const result = {
|
|
294
|
+
deleted: false,
|
|
295
|
+
uid,
|
|
296
|
+
version: version + 1,
|
|
297
|
+
tokenConfig: updatedTokenConfig
|
|
298
|
+
};
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
function makeNewPremint({
|
|
302
|
+
tokenConfig,
|
|
303
|
+
uid
|
|
304
|
+
}) {
|
|
305
|
+
return {
|
|
306
|
+
deleted: false,
|
|
307
|
+
uid,
|
|
308
|
+
version: 0,
|
|
309
|
+
tokenConfig
|
|
310
|
+
};
|
|
311
|
+
}
|
|
257
312
|
|
|
258
313
|
// src/apis/http-api-base.ts
|
|
259
314
|
var BadResponseError = class extends Error {
|
|
@@ -525,64 +580,22 @@ var getSignature = async ({
|
|
|
525
580
|
uid,
|
|
526
581
|
chain_name,
|
|
527
582
|
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
528
|
-
}) =>
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
)
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
});
|
|
540
|
-
this.getNextUID = async (path) => getNextUID({
|
|
541
|
-
...path,
|
|
542
|
-
chain_name: this.networkConfig.zoraBackendChainName,
|
|
543
|
-
httpClient: this.httpClient
|
|
544
|
-
});
|
|
545
|
-
this.getSignature = async ({
|
|
546
|
-
collection_address,
|
|
547
|
-
uid
|
|
548
|
-
}) => getSignature({
|
|
549
|
-
collection_address,
|
|
550
|
-
uid,
|
|
551
|
-
chain_name: this.networkConfig.zoraBackendChainName,
|
|
552
|
-
httpClient: this.httpClient
|
|
553
|
-
});
|
|
554
|
-
this.httpClient = httpClient2 || httpClient;
|
|
555
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
// src/premint/premint-client.ts
|
|
560
|
-
var DefaultMintArguments = {
|
|
561
|
-
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
562
|
-
maxTokensPerAddress: 0n,
|
|
563
|
-
pricePerToken: 0n,
|
|
564
|
-
mintDuration: BigInt(60 * 60 * 24 * 7),
|
|
565
|
-
// 1 week
|
|
566
|
-
mintStart: 0n,
|
|
567
|
-
royaltyMintSchedule: 0,
|
|
568
|
-
royaltyBPS: 1e3
|
|
569
|
-
// 10%,
|
|
583
|
+
}) => {
|
|
584
|
+
const result = await retries2(
|
|
585
|
+
() => get2(
|
|
586
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
587
|
+
)
|
|
588
|
+
);
|
|
589
|
+
return {
|
|
590
|
+
...result,
|
|
591
|
+
// for now - we stub the backend api to simulate returning v1
|
|
592
|
+
premint_config_version: "1" /* V1 */
|
|
593
|
+
};
|
|
570
594
|
};
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
576
|
-
eventName: "Preminted",
|
|
577
|
-
...data
|
|
578
|
-
});
|
|
579
|
-
if (decodedLog.eventName === "Preminted") {
|
|
580
|
-
return decodedLog.args;
|
|
581
|
-
}
|
|
582
|
-
} catch (err) {
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
595
|
+
var convertCollection = (collection) => ({
|
|
596
|
+
...collection,
|
|
597
|
+
contractAdmin: collection.contractAdmin
|
|
598
|
+
});
|
|
586
599
|
var convertPremintV1 = (premint) => ({
|
|
587
600
|
...premint,
|
|
588
601
|
tokenConfig: {
|
|
@@ -596,10 +609,6 @@ var convertPremintV1 = (premint) => ({
|
|
|
596
609
|
maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
|
|
597
610
|
}
|
|
598
611
|
});
|
|
599
|
-
var convertCollection = (collection) => ({
|
|
600
|
-
...collection,
|
|
601
|
-
contractAdmin: collection.contractAdmin
|
|
602
|
-
});
|
|
603
612
|
var encodePremintV1ForAPI = ({
|
|
604
613
|
tokenConfig,
|
|
605
614
|
...premint
|
|
@@ -632,30 +641,144 @@ var encodePremintForAPI = ({
|
|
|
632
641
|
premintConfig,
|
|
633
642
|
premintConfigVersion
|
|
634
643
|
}) => {
|
|
635
|
-
if (premintConfigVersion ===
|
|
644
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
636
645
|
return encodePremintV1ForAPI(premintConfig);
|
|
637
646
|
}
|
|
638
|
-
if (premintConfigVersion ===
|
|
647
|
+
if (premintConfigVersion === "2" /* V2 */) {
|
|
639
648
|
return encodePremintV2ForAPI(premintConfig);
|
|
640
649
|
}
|
|
641
650
|
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
642
651
|
};
|
|
652
|
+
var PremintAPIClient = class {
|
|
653
|
+
constructor(chainId, httpClient2) {
|
|
654
|
+
this.postSignature = async ({
|
|
655
|
+
collection,
|
|
656
|
+
premintConfigVersion,
|
|
657
|
+
premintConfig,
|
|
658
|
+
signature
|
|
659
|
+
}) => {
|
|
660
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
661
|
+
const data = {
|
|
662
|
+
premint: encodePremintForAPI({
|
|
663
|
+
premintConfig,
|
|
664
|
+
premintConfigVersion
|
|
665
|
+
}),
|
|
666
|
+
signature,
|
|
667
|
+
collection
|
|
668
|
+
};
|
|
669
|
+
return postSignature({
|
|
670
|
+
...data,
|
|
671
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
672
|
+
httpClient: this.httpClient
|
|
673
|
+
});
|
|
674
|
+
} else {
|
|
675
|
+
throw new Error("Unsupported premint config version");
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
679
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
680
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
681
|
+
httpClient: this.httpClient
|
|
682
|
+
})).next_uid;
|
|
683
|
+
this.getSignature = async ({
|
|
684
|
+
collectionAddress,
|
|
685
|
+
uid
|
|
686
|
+
}) => {
|
|
687
|
+
const response = await getSignature({
|
|
688
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
689
|
+
uid,
|
|
690
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
691
|
+
httpClient: this.httpClient
|
|
692
|
+
});
|
|
693
|
+
const premintConfigVersion = response.premint_config_version || "1" /* V1 */;
|
|
694
|
+
let premintConfig;
|
|
695
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
696
|
+
premintConfig = convertPremintV1(response.premint);
|
|
697
|
+
} else {
|
|
698
|
+
throw new Error(
|
|
699
|
+
`Unsupported premint config version: ${premintConfigVersion}`
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
signature: response.signature,
|
|
704
|
+
collection: convertCollection(response.collection),
|
|
705
|
+
premintConfig,
|
|
706
|
+
premintConfigVersion
|
|
707
|
+
};
|
|
708
|
+
};
|
|
709
|
+
this.httpClient = httpClient2 || httpClient;
|
|
710
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
// src/premint/premint-client.ts
|
|
715
|
+
var defaultTokenConfigV1MintArguments = () => ({
|
|
716
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
717
|
+
maxTokensPerAddress: 0n,
|
|
718
|
+
pricePerToken: 0n,
|
|
719
|
+
mintDuration: BigInt(60 * 60 * 24 * 7),
|
|
720
|
+
// 1 week
|
|
721
|
+
mintStart: 0n,
|
|
722
|
+
royaltyMintSchedule: 0,
|
|
723
|
+
royaltyBPS: 1e3
|
|
724
|
+
// 10%,
|
|
725
|
+
});
|
|
726
|
+
var defaultTokenConfigV2MintArguments = () => ({
|
|
727
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
728
|
+
maxTokensPerAddress: 0n,
|
|
729
|
+
pricePerToken: 0n,
|
|
730
|
+
mintDuration: BigInt(60 * 60 * 24 * 7),
|
|
731
|
+
// 1 week
|
|
732
|
+
mintStart: 0n,
|
|
733
|
+
royaltyBPS: 1e3
|
|
734
|
+
// 10%,
|
|
735
|
+
});
|
|
736
|
+
var makeTokenConfigWithDefaults = ({
|
|
737
|
+
premintConfigVersion,
|
|
738
|
+
tokenCreationConfig,
|
|
739
|
+
creatorAccount
|
|
740
|
+
}) => {
|
|
741
|
+
const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
|
|
742
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
743
|
+
return {
|
|
744
|
+
fixedPriceMinter,
|
|
745
|
+
...defaultTokenConfigV1MintArguments(),
|
|
746
|
+
royaltyRecipient: creatorAccount,
|
|
747
|
+
...tokenCreationConfig
|
|
748
|
+
};
|
|
749
|
+
} else if (premintConfigVersion === "2" /* V2 */) {
|
|
750
|
+
return {
|
|
751
|
+
fixedPriceMinter,
|
|
752
|
+
...defaultTokenConfigV2MintArguments(),
|
|
753
|
+
payoutRecipient: creatorAccount,
|
|
754
|
+
createReferral: zeroAddress2,
|
|
755
|
+
...tokenCreationConfig
|
|
756
|
+
};
|
|
757
|
+
} else {
|
|
758
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
function getPremintedLogFromReceipt(receipt) {
|
|
762
|
+
for (const data of receipt.logs) {
|
|
763
|
+
try {
|
|
764
|
+
const decodedLog = decodeEventLog({
|
|
765
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
766
|
+
eventName: "Preminted",
|
|
767
|
+
...data
|
|
768
|
+
});
|
|
769
|
+
if (decodedLog.eventName === "Preminted") {
|
|
770
|
+
return decodedLog.args;
|
|
771
|
+
}
|
|
772
|
+
} catch (err) {
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
643
776
|
var PremintClient = class {
|
|
644
777
|
constructor(chain, publicClient, httpClient2) {
|
|
645
778
|
this.chain = chain;
|
|
646
779
|
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
647
780
|
this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
|
|
648
781
|
}
|
|
649
|
-
/**
|
|
650
|
-
* The fixed price minter address is the same across all chains for our current
|
|
651
|
-
* deployer strategy.
|
|
652
|
-
* Can be overridden as needed by making a parent class.
|
|
653
|
-
*
|
|
654
|
-
* @returns Fixed price sale strategy
|
|
655
|
-
*/
|
|
656
|
-
getFixedPriceMinterAddress() {
|
|
657
|
-
return zoraCreatorFixedPriceSaleStrategyAddress[999];
|
|
658
|
-
}
|
|
659
782
|
getDataFromPremintReceipt(receipt) {
|
|
660
783
|
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
661
784
|
return {
|
|
@@ -688,36 +811,31 @@ var PremintClient = class {
|
|
|
688
811
|
walletClient,
|
|
689
812
|
uid,
|
|
690
813
|
collection,
|
|
691
|
-
|
|
692
|
-
|
|
814
|
+
account,
|
|
815
|
+
tokenConfigUpdates
|
|
693
816
|
}) {
|
|
694
|
-
const
|
|
695
|
-
|
|
817
|
+
const {
|
|
818
|
+
premintConfig,
|
|
819
|
+
collection: collectionCreationConfig,
|
|
820
|
+
premintConfigVersion
|
|
821
|
+
} = await this.apiClient.getSignature({
|
|
822
|
+
collectionAddress: collection,
|
|
696
823
|
uid
|
|
697
824
|
});
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
...convertedPremint.tokenConfig,
|
|
705
|
-
...token
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
};
|
|
825
|
+
const updatedPremint = applyUpdateToPremint({
|
|
826
|
+
uid: premintConfig.uid,
|
|
827
|
+
version: premintConfig.version,
|
|
828
|
+
tokenConfig: premintConfig.tokenConfig,
|
|
829
|
+
tokenConfigUpdates
|
|
830
|
+
});
|
|
709
831
|
return await this.signAndSubmitPremint({
|
|
710
832
|
walletClient,
|
|
711
833
|
account,
|
|
712
|
-
checkSignature:
|
|
834
|
+
checkSignature: true,
|
|
713
835
|
verifyingContract: collection,
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
contractAdmin: signerData.collection.contractAdmin
|
|
718
|
-
},
|
|
719
|
-
premintConfig: signerData.premint,
|
|
720
|
-
premintConfigVersion: PremintConfigVersion.V1
|
|
836
|
+
collection: collectionCreationConfig,
|
|
837
|
+
premintConfig: updatedPremint,
|
|
838
|
+
premintConfigVersion
|
|
721
839
|
});
|
|
722
840
|
}
|
|
723
841
|
/**
|
|
@@ -740,27 +858,23 @@ var PremintClient = class {
|
|
|
740
858
|
account,
|
|
741
859
|
collection
|
|
742
860
|
}) {
|
|
743
|
-
const
|
|
744
|
-
|
|
861
|
+
const {
|
|
862
|
+
premintConfig,
|
|
863
|
+
premintConfigVersion,
|
|
864
|
+
collection: collectionCreationConfig
|
|
865
|
+
} = await this.apiClient.getSignature({
|
|
866
|
+
collectionAddress: collection,
|
|
745
867
|
uid
|
|
746
868
|
});
|
|
747
|
-
const
|
|
748
|
-
...signatureResponse,
|
|
749
|
-
collection: convertCollection(signatureResponse.collection),
|
|
750
|
-
premint: {
|
|
751
|
-
...convertPremintV1(signatureResponse.premint),
|
|
752
|
-
deleted: true
|
|
753
|
-
}
|
|
754
|
-
};
|
|
869
|
+
const deletedPremint = markPremintDeleted(premintConfig);
|
|
755
870
|
return await this.signAndSubmitPremint({
|
|
756
871
|
walletClient,
|
|
757
872
|
account,
|
|
758
873
|
checkSignature: false,
|
|
759
874
|
verifyingContract: collection,
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
premintConfigVersion: PremintConfigVersion.V1
|
|
875
|
+
collection: collectionCreationConfig,
|
|
876
|
+
premintConfig: deletedPremint,
|
|
877
|
+
premintConfigVersion
|
|
764
878
|
});
|
|
765
879
|
}
|
|
766
880
|
/**
|
|
@@ -769,52 +883,14 @@ var PremintClient = class {
|
|
|
769
883
|
* @param premintArguments Arguments to premint
|
|
770
884
|
* @returns
|
|
771
885
|
*/
|
|
772
|
-
async signAndSubmitPremint({
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
collection,
|
|
779
|
-
...premintConfigAndVersion
|
|
780
|
-
}) {
|
|
781
|
-
if (!account) {
|
|
782
|
-
account = walletClient.account;
|
|
783
|
-
}
|
|
784
|
-
if (!account) {
|
|
785
|
-
throw new Error("No account provided");
|
|
786
|
-
}
|
|
787
|
-
const signature = await walletClient.signTypedData({
|
|
788
|
-
account,
|
|
789
|
-
...premintTypedDataDefinition({
|
|
790
|
-
verifyingContract,
|
|
791
|
-
...premintConfigAndVersion,
|
|
792
|
-
chainId: this.chain.id
|
|
793
|
-
})
|
|
886
|
+
async signAndSubmitPremint(params) {
|
|
887
|
+
const { premint, verifyingContract } = await signAndSubmitPremint({
|
|
888
|
+
...params,
|
|
889
|
+
chainId: this.chain.id,
|
|
890
|
+
apiClient: this.apiClient,
|
|
891
|
+
publicClient: this.publicClient
|
|
794
892
|
});
|
|
795
|
-
|
|
796
|
-
const convertedCollection = convertCollection(collection);
|
|
797
|
-
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
798
|
-
collection: convertCollection(collection),
|
|
799
|
-
signature,
|
|
800
|
-
publicClient: this.publicClient,
|
|
801
|
-
signer: typeof account === "string" ? account : account.address,
|
|
802
|
-
collectionAddress: await this.getCollectionAddress(convertedCollection),
|
|
803
|
-
...premintConfigAndVersion
|
|
804
|
-
});
|
|
805
|
-
if (!isAuthorized) {
|
|
806
|
-
throw new Error("Not authorized to create premint");
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) {
|
|
810
|
-
throw new Error("premint config v2 not supported yet");
|
|
811
|
-
}
|
|
812
|
-
const apiData = {
|
|
813
|
-
collection,
|
|
814
|
-
premint: encodePremintV1ForAPI(premintConfigAndVersion.premintConfig),
|
|
815
|
-
signature
|
|
816
|
-
};
|
|
817
|
-
const premint = await this.apiClient.postSignature(apiData);
|
|
893
|
+
const uid = params.premintConfig.uid;
|
|
818
894
|
return {
|
|
819
895
|
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
820
896
|
uid,
|
|
@@ -828,57 +904,53 @@ var PremintClient = class {
|
|
|
828
904
|
* @param settings Settings for the new premint
|
|
829
905
|
* @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
|
|
830
906
|
* @param settings.collection Collection information for the mint
|
|
831
|
-
* @param settings.
|
|
832
|
-
* @param
|
|
833
|
-
* @param settings.
|
|
834
|
-
* @param settings.executionSettings Execution settings for premint options
|
|
835
|
-
* @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
|
|
836
|
-
* @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
907
|
+
* @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
|
|
908
|
+
* @param setings.premintConfigVersion Premint config version to use, defaults to V2
|
|
909
|
+
* @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
837
910
|
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
838
911
|
* @returns premint url, uid, newContractAddress, and premint object
|
|
839
912
|
*/
|
|
840
913
|
async createPremint({
|
|
841
|
-
|
|
914
|
+
creatorAccount,
|
|
842
915
|
collection,
|
|
843
|
-
|
|
916
|
+
tokenCreationConfig,
|
|
917
|
+
premintConfigVersion,
|
|
844
918
|
walletClient,
|
|
845
|
-
|
|
919
|
+
uid,
|
|
846
920
|
checkSignature = false
|
|
847
921
|
}) {
|
|
848
922
|
const newContractAddress = await getPremintCollectionAddress({
|
|
849
923
|
publicClient: this.publicClient,
|
|
850
|
-
collection
|
|
924
|
+
collection
|
|
851
925
|
});
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
royaltyRecipient: account,
|
|
856
|
-
...token
|
|
857
|
-
};
|
|
858
|
-
let uid = executionSettings?.uid;
|
|
859
|
-
if (!uid) {
|
|
860
|
-
const uidResponse = await this.apiClient.getNextUID({
|
|
861
|
-
collection_address: newContractAddress.toLowerCase()
|
|
862
|
-
});
|
|
863
|
-
uid = uidResponse.next_uid;
|
|
926
|
+
let uidToUse = uid;
|
|
927
|
+
if (typeof uidToUse !== "number") {
|
|
928
|
+
uidToUse = await this.apiClient.getNextUID(newContractAddress);
|
|
864
929
|
}
|
|
865
|
-
|
|
866
|
-
|
|
930
|
+
const actualVersion = premintConfigVersion || "1" /* V1 */;
|
|
931
|
+
if (!await supportsPremintVersion({
|
|
932
|
+
version: actualVersion,
|
|
933
|
+
publicClient: this.publicClient,
|
|
934
|
+
tokenContract: newContractAddress
|
|
935
|
+
})) {
|
|
936
|
+
throw new Error(
|
|
937
|
+
`Premint version ${actualVersion} not supported by contract`
|
|
938
|
+
);
|
|
867
939
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
940
|
+
const premintConfig = makeNewPremint({
|
|
941
|
+
tokenConfig: makeTokenConfigWithDefaults({
|
|
942
|
+
premintConfigVersion: actualVersion,
|
|
943
|
+
tokenCreationConfig,
|
|
944
|
+
creatorAccount
|
|
945
|
+
}),
|
|
946
|
+
uid: uidToUse
|
|
947
|
+
});
|
|
875
948
|
return await this.signAndSubmitPremint({
|
|
876
|
-
uid,
|
|
877
949
|
verifyingContract: newContractAddress,
|
|
878
950
|
premintConfig,
|
|
879
|
-
premintConfigVersion:
|
|
951
|
+
premintConfigVersion: actualVersion,
|
|
880
952
|
checkSignature,
|
|
881
|
-
account,
|
|
953
|
+
account: creatorAccount,
|
|
882
954
|
walletClient,
|
|
883
955
|
collection
|
|
884
956
|
});
|
|
@@ -890,12 +962,12 @@ var PremintClient = class {
|
|
|
890
962
|
* @param uid UID for the desired premint
|
|
891
963
|
* @returns PremintSignatureGetResponse of premint data from the API
|
|
892
964
|
*/
|
|
893
|
-
async
|
|
965
|
+
async getPremintSignature({
|
|
894
966
|
address,
|
|
895
967
|
uid
|
|
896
968
|
}) {
|
|
897
969
|
return await this.apiClient.getSignature({
|
|
898
|
-
|
|
970
|
+
collectionAddress: address,
|
|
899
971
|
uid
|
|
900
972
|
});
|
|
901
973
|
}
|
|
@@ -918,16 +990,17 @@ var PremintClient = class {
|
|
|
918
990
|
*/
|
|
919
991
|
async isValidSignature({
|
|
920
992
|
signature,
|
|
921
|
-
|
|
922
|
-
|
|
993
|
+
collection,
|
|
994
|
+
premintConfig,
|
|
995
|
+
premintConfigVersion
|
|
923
996
|
}) {
|
|
924
997
|
const { isAuthorized, recoveredAddress } = await isValidSignature({
|
|
925
998
|
chainId: this.chain.id,
|
|
926
999
|
signature,
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1000
|
+
collection,
|
|
1001
|
+
publicClient: this.publicClient,
|
|
1002
|
+
premintConfig,
|
|
1003
|
+
premintConfigVersion: premintConfigVersion || "1" /* V1 */
|
|
931
1004
|
});
|
|
932
1005
|
return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
|
|
933
1006
|
}
|
|
@@ -936,16 +1009,12 @@ var PremintClient = class {
|
|
|
936
1009
|
address,
|
|
937
1010
|
tokenId
|
|
938
1011
|
}) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
946
|
-
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
947
|
-
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
948
|
-
};
|
|
1012
|
+
return makeUrls({
|
|
1013
|
+
uid,
|
|
1014
|
+
address,
|
|
1015
|
+
tokenId,
|
|
1016
|
+
chain: this.chain
|
|
1017
|
+
});
|
|
949
1018
|
}
|
|
950
1019
|
/**
|
|
951
1020
|
* Execute premint on-chain
|
|
@@ -960,34 +1029,62 @@ var PremintClient = class {
|
|
|
960
1029
|
* @returns receipt, log, zoraURL
|
|
961
1030
|
*/
|
|
962
1031
|
async makeMintParameters({
|
|
963
|
-
|
|
1032
|
+
uid,
|
|
1033
|
+
tokenContract,
|
|
964
1034
|
account,
|
|
965
1035
|
mintArguments
|
|
966
1036
|
}) {
|
|
967
1037
|
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
968
1038
|
throw new Error("Quantity to mint cannot be below 1");
|
|
969
1039
|
}
|
|
970
|
-
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
971
|
-
const args = [
|
|
972
|
-
convertCollection(data.collection),
|
|
973
|
-
convertPremintV1(data.premint),
|
|
974
|
-
data.signature,
|
|
975
|
-
numberToMint,
|
|
976
|
-
mintArguments?.mintComment || ""
|
|
977
|
-
];
|
|
978
1040
|
if (!account) {
|
|
979
1041
|
throw new Error("Wallet not passed in");
|
|
980
1042
|
}
|
|
1043
|
+
const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
|
|
1044
|
+
address: tokenContract,
|
|
1045
|
+
uid
|
|
1046
|
+
});
|
|
1047
|
+
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
981
1048
|
const value = numberToMint * REWARD_PER_TOKEN;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1049
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
1050
|
+
return {
|
|
1051
|
+
account,
|
|
1052
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
1053
|
+
functionName: "premint",
|
|
1054
|
+
value,
|
|
1055
|
+
address: getPremintExecutorAddress(),
|
|
1056
|
+
args: [
|
|
1057
|
+
collection,
|
|
1058
|
+
premintConfig,
|
|
1059
|
+
signature,
|
|
1060
|
+
numberToMint,
|
|
1061
|
+
mintArguments?.mintComment || ""
|
|
1062
|
+
]
|
|
1063
|
+
};
|
|
1064
|
+
} else if (premintConfigVersion === "2" /* V2 */) {
|
|
1065
|
+
const toPost = premintConfig;
|
|
1066
|
+
const accountAddress = typeof account === "string" ? account : account.address;
|
|
1067
|
+
return {
|
|
1068
|
+
account,
|
|
1069
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
1070
|
+
functionName: "premintV2",
|
|
1071
|
+
value,
|
|
1072
|
+
address: getPremintExecutorAddress(),
|
|
1073
|
+
// args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
|
|
1074
|
+
args: [
|
|
1075
|
+
collection,
|
|
1076
|
+
toPost,
|
|
1077
|
+
signature,
|
|
1078
|
+
numberToMint,
|
|
1079
|
+
{
|
|
1080
|
+
mintComment: mintArguments?.mintComment || "",
|
|
1081
|
+
mintRecipient: mintArguments?.mintRecipient || accountAddress,
|
|
1082
|
+
mintReferral: mintArguments?.mintReferral || zeroAddress2
|
|
1083
|
+
}
|
|
1084
|
+
]
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
991
1088
|
}
|
|
992
1089
|
};
|
|
993
1090
|
function createPremintClient({
|
|
@@ -997,13 +1094,81 @@ function createPremintClient({
|
|
|
997
1094
|
}) {
|
|
998
1095
|
return new PremintClient(chain, publicClient, httpClient2);
|
|
999
1096
|
}
|
|
1097
|
+
function makeUrls({
|
|
1098
|
+
uid,
|
|
1099
|
+
address,
|
|
1100
|
+
tokenId,
|
|
1101
|
+
chain
|
|
1102
|
+
}) {
|
|
1103
|
+
if ((!uid || !tokenId) && !address) {
|
|
1104
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
1105
|
+
}
|
|
1106
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
1107
|
+
const network = getApiNetworkConfigForChain(chain.id);
|
|
1108
|
+
return {
|
|
1109
|
+
explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
1110
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
1111
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
async function signAndSubmitPremint({
|
|
1115
|
+
walletClient,
|
|
1116
|
+
verifyingContract,
|
|
1117
|
+
account,
|
|
1118
|
+
checkSignature,
|
|
1119
|
+
collection,
|
|
1120
|
+
chainId,
|
|
1121
|
+
publicClient,
|
|
1122
|
+
apiClient,
|
|
1123
|
+
...premintConfigAndVersion
|
|
1124
|
+
}) {
|
|
1125
|
+
if (!account) {
|
|
1126
|
+
account = walletClient.account;
|
|
1127
|
+
}
|
|
1128
|
+
if (!account) {
|
|
1129
|
+
throw new Error("No account provided");
|
|
1130
|
+
}
|
|
1131
|
+
const signature = await walletClient.signTypedData({
|
|
1132
|
+
account,
|
|
1133
|
+
...premintTypedDataDefinition({
|
|
1134
|
+
verifyingContract,
|
|
1135
|
+
...premintConfigAndVersion,
|
|
1136
|
+
chainId
|
|
1137
|
+
})
|
|
1138
|
+
});
|
|
1139
|
+
if (checkSignature) {
|
|
1140
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
1141
|
+
collection,
|
|
1142
|
+
signature,
|
|
1143
|
+
publicClient,
|
|
1144
|
+
signer: typeof account === "string" ? account : account.address,
|
|
1145
|
+
collectionAddress: await getPremintCollectionAddress({
|
|
1146
|
+
collection,
|
|
1147
|
+
publicClient
|
|
1148
|
+
}),
|
|
1149
|
+
...premintConfigAndVersion
|
|
1150
|
+
});
|
|
1151
|
+
if (!isAuthorized) {
|
|
1152
|
+
throw new Error("Not authorized to create premint");
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
const premint = await apiClient.postSignature({
|
|
1156
|
+
collection,
|
|
1157
|
+
signature,
|
|
1158
|
+
...premintConfigAndVersion
|
|
1159
|
+
});
|
|
1160
|
+
return { premint, verifyingContract };
|
|
1161
|
+
}
|
|
1162
|
+
function getDefaultFixedPriceMinterAddress() {
|
|
1163
|
+
return zoraCreatorFixedPriceSaleStrategyAddress[999];
|
|
1164
|
+
}
|
|
1000
1165
|
|
|
1001
1166
|
// src/mint/mint-client.ts
|
|
1002
1167
|
import {
|
|
1003
1168
|
createPublicClient as createPublicClient2,
|
|
1004
1169
|
encodeAbiParameters,
|
|
1005
1170
|
parseAbiParameters,
|
|
1006
|
-
zeroAddress as
|
|
1171
|
+
zeroAddress as zeroAddress3,
|
|
1007
1172
|
http as http2
|
|
1008
1173
|
} from "viem";
|
|
1009
1174
|
import {
|
|
@@ -1092,7 +1257,7 @@ async function makePrepareMint721TokenParams({
|
|
|
1092
1257
|
mintArguments.mintToAddress,
|
|
1093
1258
|
BigInt(mintArguments.quantityToMint),
|
|
1094
1259
|
mintArguments.mintComment || "",
|
|
1095
|
-
mintArguments.mintReferral ||
|
|
1260
|
+
mintArguments.mintReferral || zeroAddress3
|
|
1096
1261
|
]
|
|
1097
1262
|
};
|
|
1098
1263
|
return result;
|
|
@@ -1136,7 +1301,7 @@ async function makePrepareMint1155TokenParams({
|
|
|
1136
1301
|
mintArguments.mintToAddress,
|
|
1137
1302
|
mintArguments.mintComment || ""
|
|
1138
1303
|
]),
|
|
1139
|
-
mintArguments.mintReferral ||
|
|
1304
|
+
mintArguments.mintReferral || zeroAddress3
|
|
1140
1305
|
]
|
|
1141
1306
|
};
|
|
1142
1307
|
return result;
|
|
@@ -1149,11 +1314,11 @@ import {
|
|
|
1149
1314
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
|
|
1150
1315
|
zoraCreatorFixedPriceSaleStrategyABI
|
|
1151
1316
|
} from "@zoralabs/protocol-deployments";
|
|
1152
|
-
import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as
|
|
1317
|
+
import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
|
|
1153
1318
|
var SALE_END_FOREVER = 18446744073709551615n;
|
|
1154
1319
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
1155
1320
|
var DEFAULT_SALE_SETTINGS = {
|
|
1156
|
-
fundsRecipient:
|
|
1321
|
+
fundsRecipient: zeroAddress4,
|
|
1157
1322
|
// Free Mint
|
|
1158
1323
|
pricePerToken: 0n,
|
|
1159
1324
|
// Sale start time – defaults to beginning of unix time
|
|
@@ -1395,22 +1560,19 @@ function create1155CreatorClient({
|
|
|
1395
1560
|
}
|
|
1396
1561
|
export {
|
|
1397
1562
|
DEFAULT_SALE_SETTINGS,
|
|
1398
|
-
DefaultMintArguments,
|
|
1399
1563
|
Errors,
|
|
1400
1564
|
MintAPIClient,
|
|
1401
1565
|
PremintAPIClient,
|
|
1402
1566
|
PremintConfigVersion,
|
|
1403
1567
|
PreminterDomain,
|
|
1404
1568
|
ZORA_API_BASE,
|
|
1405
|
-
|
|
1406
|
-
convertPremintV1,
|
|
1569
|
+
applyUpdateToPremint,
|
|
1407
1570
|
create1155CreatorClient,
|
|
1408
1571
|
create1155TokenSetupArgs,
|
|
1409
1572
|
createMintClient,
|
|
1410
1573
|
createPremintClient,
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
encodePremintV2ForAPI,
|
|
1574
|
+
defaultTokenConfigV1MintArguments,
|
|
1575
|
+
defaultTokenConfigV2MintArguments,
|
|
1414
1576
|
getApiNetworkConfigForChain,
|
|
1415
1577
|
getMintCosts,
|
|
1416
1578
|
getPremintCollectionAddress,
|
|
@@ -1419,11 +1581,16 @@ export {
|
|
|
1419
1581
|
getTokenIdFromCreateReceipt,
|
|
1420
1582
|
isAuthorizedToCreatePremint,
|
|
1421
1583
|
isValidSignature,
|
|
1584
|
+
makeNewPremint,
|
|
1585
|
+
markPremintDeleted,
|
|
1422
1586
|
migratePremintConfigToV2,
|
|
1423
1587
|
premintTypedDataDefinition,
|
|
1424
1588
|
recoverCreatorFromCreatorAttribution,
|
|
1425
1589
|
recoverPremintSigner,
|
|
1590
|
+
supportedPremintVersions,
|
|
1426
1591
|
supportsPremintVersion,
|
|
1427
|
-
tryRecoverPremintSigner
|
|
1592
|
+
tryRecoverPremintSigner,
|
|
1593
|
+
v1Types,
|
|
1594
|
+
v2Types
|
|
1428
1595
|
};
|
|
1429
1596
|
//# sourceMappingURL=index.js.map
|