@zoralabs/protocol-sdk 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +12 -0
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +2023 -431
- 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 +2001 -412
- package/dist/index.js.map +1 -1
- package/dist/ipfs/arweave.d.ts +3 -0
- package/dist/ipfs/arweave.d.ts.map +1 -0
- package/dist/ipfs/gateway.d.ts +4 -0
- package/dist/ipfs/gateway.d.ts.map +1 -0
- package/dist/ipfs/index.d.ts +4 -0
- package/dist/ipfs/index.d.ts.map +1 -0
- package/dist/ipfs/ipfs.d.ts +5 -0
- package/dist/ipfs/ipfs.d.ts.map +1 -0
- package/dist/ipfs/mimeTypes.d.ts +25 -0
- package/dist/ipfs/mimeTypes.d.ts.map +1 -0
- package/dist/ipfs/text-metadata.d.ts +5 -0
- package/dist/ipfs/text-metadata.d.ts.map +1 -0
- package/dist/ipfs/token-metadata.d.ts +14 -0
- package/dist/ipfs/token-metadata.d.ts.map +1 -0
- package/dist/ipfs/types.d.ts +49 -0
- package/dist/ipfs/types.d.ts.map +1 -0
- package/dist/mint/mint-client.d.ts +28 -4071
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +38 -0
- package/dist/mint/mint-queries.d.ts.map +1 -0
- package/dist/mint/mint-transactions.d.ts +20 -0
- package/dist/mint/mint-transactions.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +14 -7
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +55 -0
- package/dist/mint/subgraph-queries.d.ts.map +1 -0
- package/dist/mint/types.d.ts +117 -19
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/mint/utils.d.ts +2 -0
- package/dist/mint/utils.d.ts.map +1 -0
- package/dist/mints/mints-contracts.d.ts +3 -4494
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/premint/conversions.d.ts +12 -15
- package/dist/premint/conversions.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +14 -11
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +17 -6
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +1 -1
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/sdk.d.ts +4 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +10 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/constants.ts +0 -36
- package/src/create/1155-create-helper.test.ts +9 -7
- package/src/index.ts +2 -0
- package/src/ipfs/arweave.ts +5 -0
- package/src/ipfs/gateway.ts +48 -0
- package/src/ipfs/index.ts +7 -0
- package/src/ipfs/ipfs.ts +82 -0
- package/src/ipfs/mimeTypes.ts +141 -0
- package/src/ipfs/text-metadata.ts +128 -0
- package/src/ipfs/token-metadata.ts +99 -0
- package/src/ipfs/types.ts +54 -0
- package/src/mint/mint-client.test.ts +96 -47
- package/src/mint/mint-client.ts +75 -343
- package/src/mint/mint-queries.ts +320 -0
- package/src/mint/mint-transactions.ts +253 -0
- package/src/mint/subgraph-mint-getter.ts +216 -123
- package/src/mint/subgraph-queries.ts +170 -0
- package/src/mint/types.ts +140 -23
- package/src/mint/utils.ts +14 -0
- package/src/premint/conversions.ts +26 -2
- package/src/premint/premint-api-client.ts +48 -16
- package/src/premint/premint-client.test.ts +29 -23
- package/src/premint/premint-client.ts +73 -37
- package/src/premint/preminter.ts +2 -3
- package/src/sdk.ts +7 -4
- package/src/types.ts +18 -0
- package/src/utils.ts +29 -28
- package/test-integration/setup-test-contracts.ts +96 -0
- package/test-integration/premint-client.test.ts +0 -148
package/dist/index.cjs
CHANGED
|
@@ -9,11 +9,11 @@ var __export = (target, all) => {
|
|
|
9
9
|
for (var name in all)
|
|
10
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
11
|
};
|
|
12
|
-
var __copyProps = (to,
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
12
|
+
var __copyProps = (to, from2, except, desc) => {
|
|
13
|
+
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from2))
|
|
15
15
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () =>
|
|
16
|
+
__defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
@@ -39,12 +39,14 @@ __export(src_exports, {
|
|
|
39
39
|
SubgraphMintGetter: () => SubgraphMintGetter,
|
|
40
40
|
ZORA_API_BASE: () => ZORA_API_BASE,
|
|
41
41
|
applyUpdateToPremint: () => applyUpdateToPremint,
|
|
42
|
+
buildPremintMintCall: () => buildPremintMintCall,
|
|
42
43
|
collectOnchain: () => collectOnchain,
|
|
43
44
|
collectPremint: () => collectPremint,
|
|
44
45
|
collectPremintV2WithMintsParams: () => collectPremintV2WithMintsParams,
|
|
45
46
|
collectWithMintsParams: () => collectWithMintsParams,
|
|
46
47
|
convertCollectionFromApi: () => convertCollectionFromApi,
|
|
47
48
|
convertGetPremintApiResponse: () => convertGetPremintApiResponse,
|
|
49
|
+
convertGetPremintOfCollectionApiResponse: () => convertGetPremintOfCollectionApiResponse,
|
|
48
50
|
convertPremintFromApi: () => convertPremintFromApi,
|
|
49
51
|
createCollectorClient: () => createCollectorClient,
|
|
50
52
|
createCreatorClient: () => createCreatorClient,
|
|
@@ -56,13 +58,12 @@ __export(src_exports, {
|
|
|
56
58
|
encodeCollectOnManager: () => encodeCollectOnManager,
|
|
57
59
|
encodePostSignatureInput: () => encodePostSignatureInput,
|
|
58
60
|
encodePremintForAPI: () => encodePremintForAPI,
|
|
61
|
+
generateTextNftMetadataFiles: () => generateTextNftMetadataFiles,
|
|
59
62
|
getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
|
|
60
63
|
getDataFromPremintReceipt: () => getDataFromPremintReceipt,
|
|
61
64
|
getDefaultFixedPriceMinterAddress: () => getDefaultFixedPriceMinterAddress,
|
|
62
|
-
getMintCosts: () => getMintCosts,
|
|
63
65
|
getMintsAccountBalanceWithPriceQuery: () => getMintsAccountBalanceWithPriceQuery,
|
|
64
66
|
getMintsEthPrice: () => getMintsEthPrice,
|
|
65
|
-
getNecessaryErc20Approval: () => getNecessaryErc20Approval,
|
|
66
67
|
getPremintCollectionAddress: () => getPremintCollectionAddress,
|
|
67
68
|
getPremintExecutorAddress: () => getPremintExecutorAddress,
|
|
68
69
|
getPremintMintCosts: () => getPremintMintCosts,
|
|
@@ -77,20 +78,19 @@ __export(src_exports, {
|
|
|
77
78
|
isPremintConfigV2: () => isPremintConfigV2,
|
|
78
79
|
isValidSignature: () => isValidSignature,
|
|
79
80
|
makeCallWithEthSafeTransferData: () => makeCallWithEthSafeTransferData,
|
|
81
|
+
makeMediaTokenMetadata: () => makeMediaTokenMetadata,
|
|
80
82
|
makeMintRewardsRecipient: () => makeMintRewardsRecipient,
|
|
81
83
|
makeNewPremint: () => makeNewPremint,
|
|
82
84
|
makePermitToCollectPremintOrNonPremint: () => makePermitToCollectPremintOrNonPremint,
|
|
83
85
|
makePermitTransferBatchAndTypeData: () => makePermitTransferBatchAndTypeData,
|
|
84
86
|
makePermitTransferTypeData: () => makePermitTransferTypeData,
|
|
85
|
-
|
|
87
|
+
makeTextTokenMetadata: () => makeTextTokenMetadata,
|
|
86
88
|
makeUrls: () => makeUrls,
|
|
87
89
|
migratePremintConfigToV2: () => migratePremintConfigToV2,
|
|
88
90
|
mintWithEthParams: () => mintWithEthParams,
|
|
89
91
|
mintsBalanceOfAccountParams: () => mintsBalanceOfAccountParams,
|
|
90
|
-
parseMintCosts: () => parseMintCosts,
|
|
91
92
|
recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
|
|
92
93
|
recoverPremintSigner: () => recoverPremintSigner,
|
|
93
|
-
requestErc20ApprovalForMint: () => requestErc20ApprovalForMint,
|
|
94
94
|
selectMintsToCollectWithFromQueryResult: () => selectMintsToCollectWithFromQueryResult,
|
|
95
95
|
sumBalances: () => sumBalances,
|
|
96
96
|
supportedPremintVersions: () => supportedPremintVersions,
|
|
@@ -118,48 +118,13 @@ var import_viem = require("viem");
|
|
|
118
118
|
var ZORA_API_BASE = "https://api.zora.co/";
|
|
119
119
|
var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
120
120
|
var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
|
|
121
|
-
function getSubgraph(name,
|
|
122
|
-
return `${SUBGRAPH_CONFIG_BASE}/${name}/${
|
|
121
|
+
function getSubgraph(name, version2) {
|
|
122
|
+
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version2}/gn`;
|
|
123
123
|
}
|
|
124
124
|
var zora721Abi = (0, import_viem.parseAbi)([
|
|
125
125
|
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
126
126
|
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
127
127
|
]);
|
|
128
|
-
var NFT_SALE_QUERY = `
|
|
129
|
-
fragment SaleStrategy on SalesStrategyConfig {
|
|
130
|
-
type
|
|
131
|
-
fixedPrice {
|
|
132
|
-
address
|
|
133
|
-
pricePerToken
|
|
134
|
-
saleEnd
|
|
135
|
-
saleStart
|
|
136
|
-
maxTokensPerAddress
|
|
137
|
-
}
|
|
138
|
-
erc20Minter {
|
|
139
|
-
address
|
|
140
|
-
pricePerToken
|
|
141
|
-
currency
|
|
142
|
-
saleEnd
|
|
143
|
-
saleStart
|
|
144
|
-
maxTokensPerAddress
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
query ($id: ID!) {
|
|
149
|
-
zoraCreateToken(id: $id) {
|
|
150
|
-
id
|
|
151
|
-
contract {
|
|
152
|
-
mintFeePerQuantity
|
|
153
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
154
|
-
...SaleStrategy
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
158
|
-
...SaleStrategy
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
`;
|
|
163
128
|
|
|
164
129
|
// src/apis/chain-constants.ts
|
|
165
130
|
var REWARD_PER_TOKEN = (0, import_viem2.parseEther)("0.000777");
|
|
@@ -286,10 +251,22 @@ var convertPremintFromApi = (premint) => {
|
|
|
286
251
|
}
|
|
287
252
|
};
|
|
288
253
|
var convertGetPremintApiResponse = (response) => ({
|
|
289
|
-
...convertPremintFromApi(response.premint),
|
|
290
254
|
collection: convertCollectionFromApi(response.collection),
|
|
291
255
|
collectionAddress: response.collection_address,
|
|
292
|
-
signature: response.signature
|
|
256
|
+
signature: response.signature,
|
|
257
|
+
signer: response.signer,
|
|
258
|
+
premint: convertPremintFromApi(response.premint)
|
|
259
|
+
});
|
|
260
|
+
var convertGetPremintOfCollectionApiResponse = (response) => ({
|
|
261
|
+
collection: convertCollectionFromApi({
|
|
262
|
+
contractAdmin: response.contract_admin,
|
|
263
|
+
contractName: response.contract_name,
|
|
264
|
+
contractURI: response.contract_uri
|
|
265
|
+
}),
|
|
266
|
+
premints: response.premints.map((premint) => ({
|
|
267
|
+
premint: convertPremintFromApi(premint),
|
|
268
|
+
signature: premint.signature
|
|
269
|
+
}))
|
|
293
270
|
});
|
|
294
271
|
var encodePremintV1ForAPI = ({
|
|
295
272
|
tokenConfig,
|
|
@@ -443,7 +420,7 @@ function migratePremintConfigToV2({
|
|
|
443
420
|
};
|
|
444
421
|
}
|
|
445
422
|
var recoverCreatorFromCreatorAttribution = async ({
|
|
446
|
-
creatorAttribution: { version, domainName, structHash, signature },
|
|
423
|
+
creatorAttribution: { version: version2, domainName, structHash, signature },
|
|
447
424
|
chainId,
|
|
448
425
|
tokenContract
|
|
449
426
|
}) => {
|
|
@@ -452,7 +429,7 @@ var recoverCreatorFromCreatorAttribution = async ({
|
|
|
452
429
|
chainId,
|
|
453
430
|
name: domainName,
|
|
454
431
|
verifyingContract: tokenContract,
|
|
455
|
-
version
|
|
432
|
+
version: version2
|
|
456
433
|
},
|
|
457
434
|
types: {
|
|
458
435
|
EIP712Domain: [
|
|
@@ -488,11 +465,11 @@ var supportedPremintVersions = async ({
|
|
|
488
465
|
});
|
|
489
466
|
};
|
|
490
467
|
var supportsPremintVersion = async ({
|
|
491
|
-
version,
|
|
468
|
+
version: version2,
|
|
492
469
|
tokenContract,
|
|
493
470
|
publicClient
|
|
494
471
|
}) => {
|
|
495
|
-
return (await supportedPremintVersions({ tokenContract, publicClient })).includes(
|
|
472
|
+
return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version2);
|
|
496
473
|
};
|
|
497
474
|
async function getPremintCollectionAddress({
|
|
498
475
|
publicClient,
|
|
@@ -516,7 +493,7 @@ async function getPremintCollectionAddress({
|
|
|
516
493
|
}
|
|
517
494
|
function applyUpdateToPremint({
|
|
518
495
|
uid,
|
|
519
|
-
version,
|
|
496
|
+
version: version2,
|
|
520
497
|
tokenConfig,
|
|
521
498
|
tokenConfigUpdates
|
|
522
499
|
}) {
|
|
@@ -527,7 +504,7 @@ function applyUpdateToPremint({
|
|
|
527
504
|
const result = {
|
|
528
505
|
deleted: false,
|
|
529
506
|
uid,
|
|
530
|
-
version:
|
|
507
|
+
version: version2 + 1,
|
|
531
508
|
tokenConfig: updatedTokenConfig
|
|
532
509
|
};
|
|
533
510
|
return result;
|
|
@@ -578,7 +555,7 @@ async function getPremintPricePerToken({
|
|
|
578
555
|
uid,
|
|
579
556
|
premintGetter
|
|
580
557
|
}) {
|
|
581
|
-
const premintConfigWithVersion = await premintGetter.
|
|
558
|
+
const { premint: premintConfigWithVersion } = await premintGetter.get({
|
|
582
559
|
collectionAddress: collection,
|
|
583
560
|
uid
|
|
584
561
|
});
|
|
@@ -717,6 +694,144 @@ var httpClient = {
|
|
|
717
694
|
retries
|
|
718
695
|
};
|
|
719
696
|
|
|
697
|
+
// src/mint/types.ts
|
|
698
|
+
var isOnChainMint = (mint2) => mint2.mintType !== "premint";
|
|
699
|
+
var is1155Mint = (mint2) => mint2.mintType === "1155";
|
|
700
|
+
function isErc20SaleStrategy(salesConfig) {
|
|
701
|
+
return salesConfig.saleType === "erc20";
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/utils.ts
|
|
705
|
+
var makeContractParameters = (args) => args;
|
|
706
|
+
function mintRecipientOrAccount({
|
|
707
|
+
mintRecipient,
|
|
708
|
+
minterAccount
|
|
709
|
+
}) {
|
|
710
|
+
return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
711
|
+
}
|
|
712
|
+
async function querySubgraphWithRetries({
|
|
713
|
+
httpClient: httpClient2,
|
|
714
|
+
subgraphUrl,
|
|
715
|
+
query,
|
|
716
|
+
variables
|
|
717
|
+
}) {
|
|
718
|
+
const { retries: retries2, post: post2 } = httpClient2;
|
|
719
|
+
const result = await retries2(async () => {
|
|
720
|
+
return await post2(subgraphUrl, {
|
|
721
|
+
query,
|
|
722
|
+
variables
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
return result?.data;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/mint/subgraph-queries.ts
|
|
729
|
+
var NFT_SALE_STRATEGY_FRAGMENT = `
|
|
730
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
731
|
+
type
|
|
732
|
+
fixedPrice {
|
|
733
|
+
address
|
|
734
|
+
pricePerToken
|
|
735
|
+
saleEnd
|
|
736
|
+
saleStart
|
|
737
|
+
maxTokensPerAddress
|
|
738
|
+
}
|
|
739
|
+
erc20Minter {
|
|
740
|
+
address
|
|
741
|
+
pricePerToken
|
|
742
|
+
currency
|
|
743
|
+
saleEnd
|
|
744
|
+
saleStart
|
|
745
|
+
maxTokensPerAddress
|
|
746
|
+
}
|
|
747
|
+
}`;
|
|
748
|
+
var TOKEN_FRAGMENT = `
|
|
749
|
+
fragment Token on ZoraCreateToken {
|
|
750
|
+
creator
|
|
751
|
+
tokenId
|
|
752
|
+
uri
|
|
753
|
+
totalMinted
|
|
754
|
+
maxSupply
|
|
755
|
+
tokenStandard
|
|
756
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
757
|
+
...SaleStrategy
|
|
758
|
+
}
|
|
759
|
+
contract {
|
|
760
|
+
address
|
|
761
|
+
mintFeePerQuantity
|
|
762
|
+
contractVersion
|
|
763
|
+
contractURI
|
|
764
|
+
name
|
|
765
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
766
|
+
...SaleStrategy
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}`;
|
|
770
|
+
var FRAGMENTS = `
|
|
771
|
+
${NFT_SALE_STRATEGY_FRAGMENT}
|
|
772
|
+
${TOKEN_FRAGMENT}
|
|
773
|
+
`;
|
|
774
|
+
function buildNftTokenSalesQuery({
|
|
775
|
+
tokenId,
|
|
776
|
+
tokenAddress
|
|
777
|
+
}) {
|
|
778
|
+
return {
|
|
779
|
+
query: `
|
|
780
|
+
${FRAGMENTS}
|
|
781
|
+
query ($id: ID!) {
|
|
782
|
+
zoraCreateToken(id: $id) {
|
|
783
|
+
...Token
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
`,
|
|
787
|
+
variables: {
|
|
788
|
+
id: tokenId !== void 0 ? (
|
|
789
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
790
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
791
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
792
|
+
},
|
|
793
|
+
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
function buildContractTokensQuery({
|
|
797
|
+
tokenAddress
|
|
798
|
+
}) {
|
|
799
|
+
return {
|
|
800
|
+
query: `
|
|
801
|
+
${FRAGMENTS}
|
|
802
|
+
query ($contract: Bytes!) {
|
|
803
|
+
zoraCreateTokens(
|
|
804
|
+
where: {address: $contract}
|
|
805
|
+
) {
|
|
806
|
+
...Token
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
`,
|
|
810
|
+
variables: {
|
|
811
|
+
contract: tokenAddress.toLowerCase()
|
|
812
|
+
},
|
|
813
|
+
parseResponseData: (responseData) => responseData?.zoraCreateTokens
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function buildPremintsOfContractQuery({
|
|
817
|
+
tokenAddress
|
|
818
|
+
}) {
|
|
819
|
+
return {
|
|
820
|
+
query: `
|
|
821
|
+
query ($contractAddress: Bytes!) {
|
|
822
|
+
premints(where:{contractAddress:$contractAddress}) {
|
|
823
|
+
uid
|
|
824
|
+
tokenId
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
`,
|
|
828
|
+
variables: {
|
|
829
|
+
contractAddress: tokenAddress.toLowerCase()
|
|
830
|
+
},
|
|
831
|
+
parseResponseData: (responseData) => responseData?.premints
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
|
|
720
835
|
// src/mint/subgraph-mint-getter.ts
|
|
721
836
|
var getApiNetworkConfigForChain = (chainId) => {
|
|
722
837
|
if (!networkConfigByChain[chainId]) {
|
|
@@ -724,92 +839,171 @@ var getApiNetworkConfigForChain = (chainId) => {
|
|
|
724
839
|
}
|
|
725
840
|
return networkConfigByChain[chainId];
|
|
726
841
|
};
|
|
842
|
+
function parseSalesConfig(targetStrategy) {
|
|
843
|
+
if (targetStrategy.type === "FIXED_PRICE")
|
|
844
|
+
return {
|
|
845
|
+
saleType: "fixedPrice",
|
|
846
|
+
...targetStrategy.fixedPrice,
|
|
847
|
+
maxTokensPerAddress: BigInt(
|
|
848
|
+
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
849
|
+
),
|
|
850
|
+
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
|
|
851
|
+
};
|
|
852
|
+
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
853
|
+
return {
|
|
854
|
+
saleType: "erc20",
|
|
855
|
+
...targetStrategy.erc20Minter,
|
|
856
|
+
maxTokensPerAddress: BigInt(
|
|
857
|
+
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
858
|
+
),
|
|
859
|
+
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
throw new Error("Unknown saleType");
|
|
863
|
+
}
|
|
864
|
+
function getSaleEnd(a) {
|
|
865
|
+
return BigInt(
|
|
866
|
+
a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
function getTargetStrategy({
|
|
870
|
+
tokenId,
|
|
871
|
+
preferredSaleType,
|
|
872
|
+
token
|
|
873
|
+
}) {
|
|
874
|
+
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
875
|
+
const saleStrategies = allStrategies.sort(
|
|
876
|
+
(a, b) => getSaleEnd(a) > getSaleEnd(b) ? 1 : -1
|
|
877
|
+
);
|
|
878
|
+
let targetStrategy;
|
|
879
|
+
if (!preferredSaleType) {
|
|
880
|
+
targetStrategy = saleStrategies[0];
|
|
881
|
+
if (!targetStrategy) {
|
|
882
|
+
throw new Error("Cannot find sale strategy");
|
|
883
|
+
}
|
|
884
|
+
} else {
|
|
885
|
+
const mappedSaleType = preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
886
|
+
targetStrategy = saleStrategies.find(
|
|
887
|
+
(strategy) => strategy.type === mappedSaleType
|
|
888
|
+
);
|
|
889
|
+
if (!targetStrategy) {
|
|
890
|
+
const targetStrategy2 = saleStrategies.find(
|
|
891
|
+
(strategy) => strategy.type === "FIXED_PRICE" || strategy.type === "ERC_20_MINTER"
|
|
892
|
+
);
|
|
893
|
+
if (!targetStrategy2)
|
|
894
|
+
throw new Error("Cannot find valid sale strategy");
|
|
895
|
+
return targetStrategy2;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return targetStrategy;
|
|
899
|
+
}
|
|
727
900
|
var SubgraphMintGetter = class {
|
|
728
901
|
constructor(chainId, httpClient2) {
|
|
902
|
+
this.getMintable = async ({
|
|
903
|
+
tokenAddress,
|
|
904
|
+
tokenId,
|
|
905
|
+
preferredSaleType: saleType
|
|
906
|
+
}) => {
|
|
907
|
+
const token = await this.querySubgraphWithRetries(
|
|
908
|
+
buildNftTokenSalesQuery({
|
|
909
|
+
tokenId,
|
|
910
|
+
tokenAddress
|
|
911
|
+
})
|
|
912
|
+
);
|
|
913
|
+
if (!token) {
|
|
914
|
+
throw new Error("Cannot find token");
|
|
915
|
+
}
|
|
916
|
+
return parseTokenQueryResult({
|
|
917
|
+
token,
|
|
918
|
+
tokenId,
|
|
919
|
+
preferredSaleType: saleType
|
|
920
|
+
});
|
|
921
|
+
};
|
|
729
922
|
this.httpClient = httpClient2 || httpClient;
|
|
730
923
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
731
924
|
}
|
|
732
|
-
async
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
925
|
+
async querySubgraphWithRetries({
|
|
926
|
+
query,
|
|
927
|
+
variables,
|
|
928
|
+
parseResponseData
|
|
736
929
|
}) {
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
id: tokenId !== void 0 ? (
|
|
743
|
-
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
744
|
-
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
745
|
-
) : `${tokenAddress.toLowerCase()}-0`
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
const token = response.data?.zoraCreateToken;
|
|
749
|
-
if (!token) {
|
|
750
|
-
throw new Error("Cannot find a token to mint");
|
|
751
|
-
}
|
|
752
|
-
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
753
|
-
const saleStrategies = allStrategies.sort(
|
|
754
|
-
(a, b) => BigInt(
|
|
755
|
-
a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
|
|
756
|
-
) > BigInt(
|
|
757
|
-
b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
|
|
758
|
-
) ? 1 : -1
|
|
759
|
-
);
|
|
760
|
-
let targetStrategy;
|
|
761
|
-
if (!saleType) {
|
|
762
|
-
targetStrategy = saleStrategies[0];
|
|
763
|
-
if (!targetStrategy) {
|
|
764
|
-
throw new Error("Cannot find sale strategy");
|
|
765
|
-
}
|
|
766
|
-
} else {
|
|
767
|
-
const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
768
|
-
targetStrategy = saleStrategies.find(
|
|
769
|
-
(strategy) => strategy.type === mappedSaleType
|
|
770
|
-
);
|
|
771
|
-
if (!targetStrategy) {
|
|
772
|
-
throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
if (targetStrategy.type === "FIXED_PRICE") {
|
|
776
|
-
return {
|
|
777
|
-
salesConfig: {
|
|
778
|
-
saleType: "fixedPrice",
|
|
779
|
-
...targetStrategy.fixedPrice,
|
|
780
|
-
maxTokensPerAddress: BigInt(
|
|
781
|
-
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
782
|
-
),
|
|
783
|
-
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
|
|
784
|
-
},
|
|
785
|
-
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
789
|
-
return {
|
|
790
|
-
salesConfig: {
|
|
791
|
-
saleType: "erc20",
|
|
792
|
-
...targetStrategy.erc20Minter,
|
|
793
|
-
maxTokensPerAddress: BigInt(
|
|
794
|
-
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
795
|
-
),
|
|
796
|
-
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
|
|
797
|
-
},
|
|
798
|
-
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
throw new Error("Invalid saleType");
|
|
930
|
+
const responseData = await querySubgraphWithRetries({
|
|
931
|
+
httpClient: this.httpClient,
|
|
932
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
933
|
+
query,
|
|
934
|
+
variables
|
|
802
935
|
});
|
|
936
|
+
return parseResponseData(responseData);
|
|
937
|
+
}
|
|
938
|
+
async getContractMintable({
|
|
939
|
+
tokenAddress,
|
|
940
|
+
preferredSaleType
|
|
941
|
+
}) {
|
|
942
|
+
const tokens = await this.querySubgraphWithRetries(
|
|
943
|
+
buildContractTokensQuery({
|
|
944
|
+
tokenAddress
|
|
945
|
+
})
|
|
946
|
+
);
|
|
947
|
+
if (!tokens)
|
|
948
|
+
return [];
|
|
949
|
+
return tokens.filter((x) => x.tokenId !== "0").map(
|
|
950
|
+
(token) => parseTokenQueryResult({
|
|
951
|
+
token,
|
|
952
|
+
tokenId: token.tokenId,
|
|
953
|
+
preferredSaleType
|
|
954
|
+
})
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
async getContractPremintTokenIds({
|
|
958
|
+
tokenAddress
|
|
959
|
+
}) {
|
|
960
|
+
const premints = await this.querySubgraphWithRetries(
|
|
961
|
+
buildPremintsOfContractQuery({
|
|
962
|
+
tokenAddress
|
|
963
|
+
})
|
|
964
|
+
);
|
|
965
|
+
return premints?.map((premint) => ({
|
|
966
|
+
tokenId: BigInt(premint.tokenId),
|
|
967
|
+
uid: +premint.uid
|
|
968
|
+
})) || [];
|
|
803
969
|
}
|
|
804
970
|
};
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
mintRecipient,
|
|
810
|
-
minterAccount
|
|
971
|
+
function parseTokenQueryResult({
|
|
972
|
+
token,
|
|
973
|
+
tokenId,
|
|
974
|
+
preferredSaleType
|
|
811
975
|
}) {
|
|
812
|
-
|
|
976
|
+
const targetStrategy = getTargetStrategy({
|
|
977
|
+
tokenId,
|
|
978
|
+
preferredSaleType,
|
|
979
|
+
token
|
|
980
|
+
});
|
|
981
|
+
const tokenInfo = parseTokenInfo(token);
|
|
982
|
+
const salesConfig = parseSalesConfig(targetStrategy);
|
|
983
|
+
if (isErc20SaleStrategy(salesConfig)) {
|
|
984
|
+
tokenInfo.mintFeePerQuantity = 0n;
|
|
985
|
+
}
|
|
986
|
+
return {
|
|
987
|
+
...tokenInfo,
|
|
988
|
+
salesConfig
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
function parseTokenInfo(token) {
|
|
992
|
+
return {
|
|
993
|
+
contract: {
|
|
994
|
+
address: token.contract.address,
|
|
995
|
+
name: token.contract.name,
|
|
996
|
+
URI: token.contract.contractURI
|
|
997
|
+
},
|
|
998
|
+
tokenURI: token.uri,
|
|
999
|
+
tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
|
|
1000
|
+
mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
|
|
1001
|
+
creator: token.creator,
|
|
1002
|
+
totalMinted: BigInt(token.totalMinted),
|
|
1003
|
+
maxSupply: BigInt(token.maxSupply),
|
|
1004
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
|
|
1005
|
+
contractVersion: token.contract.contractVersion
|
|
1006
|
+
};
|
|
813
1007
|
}
|
|
814
1008
|
|
|
815
1009
|
// src/premint/premint-client.ts
|
|
@@ -967,7 +1161,7 @@ var PremintClient = class {
|
|
|
967
1161
|
* @returns PremintSignatureGetResponse of premint data from the API
|
|
968
1162
|
*/
|
|
969
1163
|
async getPremint({ address, uid }) {
|
|
970
|
-
return await this.apiClient.
|
|
1164
|
+
return await this.apiClient.get({
|
|
971
1165
|
collectionAddress: address,
|
|
972
1166
|
uid
|
|
973
1167
|
});
|
|
@@ -1096,13 +1290,19 @@ function makePremintReturn({
|
|
|
1096
1290
|
premintConfigVersion
|
|
1097
1291
|
});
|
|
1098
1292
|
};
|
|
1293
|
+
const urls = makeUrls({
|
|
1294
|
+
chainId,
|
|
1295
|
+
address: collectionAddress,
|
|
1296
|
+
uid: premintConfig.uid
|
|
1297
|
+
});
|
|
1099
1298
|
return {
|
|
1100
1299
|
premintConfig,
|
|
1101
1300
|
premintConfigVersion,
|
|
1102
1301
|
typedDataDefinition,
|
|
1103
1302
|
collectionAddress,
|
|
1104
1303
|
signAndSubmit,
|
|
1105
|
-
submit
|
|
1304
|
+
submit,
|
|
1305
|
+
urls
|
|
1106
1306
|
};
|
|
1107
1307
|
}
|
|
1108
1308
|
async function signPremint({
|
|
@@ -1202,10 +1402,9 @@ async function updatePremint({
|
|
|
1202
1402
|
chainId
|
|
1203
1403
|
}) {
|
|
1204
1404
|
const {
|
|
1205
|
-
premintConfig,
|
|
1206
|
-
collection: collectionCreationConfig
|
|
1207
|
-
|
|
1208
|
-
} = await apiClient.getSignature({
|
|
1405
|
+
premint: { premintConfig, premintConfigVersion },
|
|
1406
|
+
collection: collectionCreationConfig
|
|
1407
|
+
} = await apiClient.get({
|
|
1209
1408
|
collectionAddress: collection,
|
|
1210
1409
|
uid
|
|
1211
1410
|
});
|
|
@@ -1233,11 +1432,10 @@ async function deletePremint({
|
|
|
1233
1432
|
chainId
|
|
1234
1433
|
}) {
|
|
1235
1434
|
const {
|
|
1236
|
-
premintConfig,
|
|
1237
|
-
premintConfigVersion,
|
|
1435
|
+
premint: { premintConfig, premintConfigVersion },
|
|
1238
1436
|
collection: collectionCreationConfig,
|
|
1239
1437
|
collectionAddress
|
|
1240
|
-
} = await apiClient.
|
|
1438
|
+
} = await apiClient.get({
|
|
1241
1439
|
collectionAddress: collection,
|
|
1242
1440
|
uid
|
|
1243
1441
|
});
|
|
@@ -1271,26 +1469,39 @@ async function collectPremint({
|
|
|
1271
1469
|
if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
|
|
1272
1470
|
throw new Error("Quantity to mint cannot be below 1");
|
|
1273
1471
|
}
|
|
1274
|
-
const {
|
|
1275
|
-
premintConfig,
|
|
1276
|
-
premintConfigVersion,
|
|
1277
|
-
collection,
|
|
1278
|
-
collectionAddress,
|
|
1279
|
-
signature
|
|
1280
|
-
} = await premintGetter.getSignature({
|
|
1472
|
+
const premint = await premintGetter.get({
|
|
1281
1473
|
collectionAddress: tokenContract,
|
|
1282
1474
|
uid
|
|
1283
1475
|
});
|
|
1284
|
-
const
|
|
1285
|
-
if (premintConfigVersion === import_protocol_deployments4.PremintConfigVersion.V3) {
|
|
1286
|
-
throw new Error("PremintV3 not supported in premint SDK");
|
|
1287
|
-
}
|
|
1288
|
-
const value = (await getPremintMintCosts({
|
|
1476
|
+
const mintFee = await getPremintMintFee({
|
|
1289
1477
|
tokenContract,
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1478
|
+
publicClient
|
|
1479
|
+
});
|
|
1480
|
+
return buildPremintMintCall({
|
|
1481
|
+
mintArguments: {
|
|
1482
|
+
minterAccount,
|
|
1483
|
+
quantityToMint,
|
|
1484
|
+
firstMinter,
|
|
1485
|
+
mintComment,
|
|
1486
|
+
mintRecipient,
|
|
1487
|
+
mintReferral
|
|
1488
|
+
},
|
|
1489
|
+
mintFee,
|
|
1490
|
+
premint
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
var buildPremintMintCall = ({
|
|
1494
|
+
mintArguments: {
|
|
1495
|
+
minterAccount,
|
|
1496
|
+
mintComment = "",
|
|
1497
|
+
mintRecipient,
|
|
1498
|
+
mintReferral,
|
|
1499
|
+
firstMinter,
|
|
1500
|
+
quantityToMint
|
|
1501
|
+
},
|
|
1502
|
+
premint: { collection, collectionAddress, premint, signature },
|
|
1503
|
+
mintFee
|
|
1504
|
+
}) => {
|
|
1294
1505
|
const mintArgumentsContract = {
|
|
1295
1506
|
mintComment,
|
|
1296
1507
|
mintRecipient: mintRecipientOrAccount({
|
|
@@ -1304,6 +1515,10 @@ async function collectPremint({
|
|
|
1304
1515
|
const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
|
|
1305
1516
|
const collectionAddressToSubmit = collection ? import_viem4.zeroAddress : collectionAddress;
|
|
1306
1517
|
const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
1518
|
+
if (premint.premintConfigVersion === import_protocol_deployments4.PremintConfigVersion.V3) {
|
|
1519
|
+
throw new Error("PremintV3 not supported in premint SDK");
|
|
1520
|
+
}
|
|
1521
|
+
const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
|
|
1307
1522
|
return makeContractParameters({
|
|
1308
1523
|
account: minterAccount,
|
|
1309
1524
|
abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
|
|
@@ -1313,18 +1528,15 @@ async function collectPremint({
|
|
|
1313
1528
|
args: [
|
|
1314
1529
|
collectionOrEmpty,
|
|
1315
1530
|
collectionAddressToSubmit,
|
|
1316
|
-
(0, import_protocol_deployments3.encodePremintConfig)(
|
|
1317
|
-
premintConfig,
|
|
1318
|
-
premintConfigVersion
|
|
1319
|
-
}),
|
|
1531
|
+
(0, import_protocol_deployments3.encodePremintConfig)(premint),
|
|
1320
1532
|
signature,
|
|
1321
|
-
|
|
1533
|
+
BigInt(quantityToMint),
|
|
1322
1534
|
mintArgumentsContract,
|
|
1323
1535
|
firstMinterToSubmit,
|
|
1324
1536
|
import_viem4.zeroAddress
|
|
1325
1537
|
]
|
|
1326
1538
|
});
|
|
1327
|
-
}
|
|
1539
|
+
};
|
|
1328
1540
|
function makeUrls({
|
|
1329
1541
|
uid,
|
|
1330
1542
|
address,
|
|
@@ -1383,6 +1595,19 @@ var getSignature = async ({
|
|
|
1383
1595
|
);
|
|
1384
1596
|
return convertGetPremintApiResponse(result);
|
|
1385
1597
|
};
|
|
1598
|
+
var getOfCollection = async ({
|
|
1599
|
+
collectionAddress,
|
|
1600
|
+
chainId,
|
|
1601
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
1602
|
+
}) => {
|
|
1603
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
1604
|
+
const result = await retries2(
|
|
1605
|
+
() => get2(
|
|
1606
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
|
|
1607
|
+
)
|
|
1608
|
+
);
|
|
1609
|
+
return convertGetPremintOfCollectionApiResponse(result);
|
|
1610
|
+
};
|
|
1386
1611
|
var PremintAPIClient = class {
|
|
1387
1612
|
constructor(chainId, httpClient2) {
|
|
1388
1613
|
this.postSignature = ({
|
|
@@ -1404,10 +1629,7 @@ var PremintAPIClient = class {
|
|
|
1404
1629
|
chainId: this.chainId,
|
|
1405
1630
|
httpClient: this.httpClient
|
|
1406
1631
|
})).next_uid;
|
|
1407
|
-
this.
|
|
1408
|
-
collectionAddress,
|
|
1409
|
-
uid
|
|
1410
|
-
}) => {
|
|
1632
|
+
this.get = async ({ collectionAddress, uid }) => {
|
|
1411
1633
|
return getSignature({
|
|
1412
1634
|
collectionAddress,
|
|
1413
1635
|
uid,
|
|
@@ -1415,170 +1637,102 @@ var PremintAPIClient = class {
|
|
|
1415
1637
|
httpClient: this.httpClient
|
|
1416
1638
|
});
|
|
1417
1639
|
};
|
|
1640
|
+
this.getOfCollection = async ({
|
|
1641
|
+
collectionAddress
|
|
1642
|
+
}) => {
|
|
1643
|
+
return getOfCollection({
|
|
1644
|
+
collectionAddress,
|
|
1645
|
+
chainId: this.chainId,
|
|
1646
|
+
httpClient: this.httpClient
|
|
1647
|
+
});
|
|
1648
|
+
};
|
|
1418
1649
|
this.chainId = chainId;
|
|
1419
1650
|
this.httpClient = httpClient2 || httpClient;
|
|
1420
1651
|
}
|
|
1421
1652
|
};
|
|
1422
1653
|
|
|
1423
|
-
// src/mint/mint-
|
|
1654
|
+
// src/mint/mint-transactions.ts
|
|
1424
1655
|
var import_viem5 = require("viem");
|
|
1425
1656
|
var import_protocol_deployments6 = require("@zoralabs/protocol-deployments");
|
|
1426
1657
|
|
|
1427
|
-
// src/mint/
|
|
1428
|
-
var
|
|
1429
|
-
var
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
var MintInactiveError = class extends Error {
|
|
1438
|
-
};
|
|
1439
|
-
var Errors = {
|
|
1440
|
-
MintError,
|
|
1441
|
-
MintInactiveError
|
|
1658
|
+
// src/mint/utils.ts
|
|
1659
|
+
var semver = __toESM(require("semver"), 1);
|
|
1660
|
+
var contractSupportsNewMintFunction = (contractVersion) => {
|
|
1661
|
+
if (!contractVersion) {
|
|
1662
|
+
return false;
|
|
1663
|
+
}
|
|
1664
|
+
const semVerContractVersion = semver.coerce(contractVersion)?.raw;
|
|
1665
|
+
if (!semVerContractVersion)
|
|
1666
|
+
return false;
|
|
1667
|
+
return semver.gte(semVerContractVersion, "2.9.0");
|
|
1442
1668
|
};
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
mintGetter
|
|
1449
|
-
}) {
|
|
1450
|
-
this.chainId = chainId;
|
|
1451
|
-
this.publicClient = publicClient;
|
|
1452
|
-
this.mintGetter = mintGetter;
|
|
1453
|
-
this.premintGetter = premintGetter;
|
|
1454
|
-
}
|
|
1455
|
-
/**
|
|
1456
|
-
* Returns the parameters needed to prepare a transaction mint a token.
|
|
1457
|
-
* Works with premint, onchain 1155, and onchain 721.
|
|
1458
|
-
*
|
|
1459
|
-
* @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
|
|
1460
|
-
* @returns Parameters for simulating/executing the mint transaction
|
|
1461
|
-
*/
|
|
1462
|
-
async mint(parameters) {
|
|
1463
|
-
return mint({
|
|
1464
|
-
parameters,
|
|
1465
|
-
chainId: this.chainId,
|
|
1466
|
-
publicClient: this.publicClient,
|
|
1467
|
-
mintGetter: this.mintGetter,
|
|
1468
|
-
premintGetter: this.premintGetter
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
1473
|
-
* @param parameters - Parameters for the mint {@link GetMintCostsParameters}
|
|
1474
|
-
* @returns Costs to mint the quantity of tokens specified
|
|
1475
|
-
*/
|
|
1476
|
-
async getMintCosts(parameters) {
|
|
1477
|
-
return getMintCosts({
|
|
1478
|
-
...parameters,
|
|
1479
|
-
mintGetter: this.mintGetter,
|
|
1480
|
-
premintGetter: this.premintGetter,
|
|
1481
|
-
publicClient: this.publicClient
|
|
1482
|
-
});
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1485
|
-
function isPremintCollect(parameters) {
|
|
1486
|
-
return parameters.mintType === "premint";
|
|
1487
|
-
}
|
|
1488
|
-
function is721Collect(parameters) {
|
|
1489
|
-
return parameters.mintType === "721";
|
|
1490
|
-
}
|
|
1491
|
-
async function mint({
|
|
1492
|
-
parameters,
|
|
1493
|
-
chainId,
|
|
1494
|
-
publicClient,
|
|
1495
|
-
mintGetter,
|
|
1496
|
-
premintGetter
|
|
1669
|
+
|
|
1670
|
+
// src/mint/mint-transactions.ts
|
|
1671
|
+
function makeOnchainMintCall({
|
|
1672
|
+
token,
|
|
1673
|
+
mintParams
|
|
1497
1674
|
}) {
|
|
1498
|
-
if (
|
|
1499
|
-
return {
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
})
|
|
1505
|
-
};
|
|
1675
|
+
if (token.mintType === "721") {
|
|
1676
|
+
return makePrepareMint721TokenParams({
|
|
1677
|
+
salesConfigAndTokenInfo: token,
|
|
1678
|
+
tokenContract: token.contract.address,
|
|
1679
|
+
...mintParams
|
|
1680
|
+
});
|
|
1506
1681
|
}
|
|
1507
|
-
return {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
})
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
function requestErc20ApprovalForMint({
|
|
1516
|
-
account,
|
|
1517
|
-
tokenAddress,
|
|
1518
|
-
quantityErc20,
|
|
1519
|
-
erc20MinterAddress: erc20MinterAddress2
|
|
1520
|
-
}) {
|
|
1521
|
-
return makeContractParameters({
|
|
1522
|
-
abi: import_viem5.erc20Abi,
|
|
1523
|
-
address: tokenAddress,
|
|
1524
|
-
account,
|
|
1525
|
-
functionName: "approve",
|
|
1526
|
-
args: [erc20MinterAddress2, quantityErc20]
|
|
1682
|
+
return makePrepareMint1155TokenParams({
|
|
1683
|
+
salesConfigAndTokenInfo: token,
|
|
1684
|
+
tokenContract: token.contract.address,
|
|
1685
|
+
tokenId: token.tokenId,
|
|
1686
|
+
...mintParams
|
|
1527
1687
|
});
|
|
1528
1688
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1689
|
+
function makePrepareMint1155TokenParams({
|
|
1690
|
+
tokenContract,
|
|
1691
|
+
tokenId,
|
|
1692
|
+
salesConfigAndTokenInfo,
|
|
1693
|
+
minterAccount,
|
|
1694
|
+
mintComment,
|
|
1695
|
+
mintReferral,
|
|
1696
|
+
mintRecipient,
|
|
1697
|
+
quantityToMint
|
|
1535
1698
|
}) {
|
|
1536
|
-
const
|
|
1537
|
-
const
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
erc20MinterAddress: destination,
|
|
1550
|
-
account,
|
|
1551
|
-
tokenAddress,
|
|
1552
|
-
quantityErc20: quantityErc20 - allowance
|
|
1699
|
+
const mintQuantity = BigInt(quantityToMint || 1);
|
|
1700
|
+
const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
|
|
1701
|
+
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
1702
|
+
if (saleType === "fixedPrice") {
|
|
1703
|
+
return makeEthMintCall({
|
|
1704
|
+
mintComment,
|
|
1705
|
+
minterAccount,
|
|
1706
|
+
mintQuantity,
|
|
1707
|
+
mintReferral,
|
|
1708
|
+
mintTo,
|
|
1709
|
+
salesConfigAndTokenInfo,
|
|
1710
|
+
tokenContract,
|
|
1711
|
+
tokenId
|
|
1553
1712
|
});
|
|
1554
1713
|
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
...parameters
|
|
1714
|
+
if (saleType === "erc20") {
|
|
1715
|
+
return makeContractParameters({
|
|
1716
|
+
abi: import_protocol_deployments6.erc20MinterABI,
|
|
1717
|
+
functionName: "mint",
|
|
1718
|
+
account: minterAccount,
|
|
1719
|
+
address: salesConfigAndTokenInfo.salesConfig.address,
|
|
1720
|
+
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
1721
|
+
args: [
|
|
1722
|
+
mintTo,
|
|
1723
|
+
mintQuantity,
|
|
1724
|
+
tokenContract,
|
|
1725
|
+
BigInt(tokenId),
|
|
1726
|
+
salesConfigAndTokenInfo.salesConfig.pricePerToken * mintQuantity,
|
|
1727
|
+
salesConfigAndTokenInfo.salesConfig.currency,
|
|
1728
|
+
mintReferral || import_viem5.zeroAddress,
|
|
1729
|
+
mintComment || ""
|
|
1730
|
+
]
|
|
1573
1731
|
});
|
|
1574
1732
|
}
|
|
1575
|
-
|
|
1576
|
-
salesConfigAndTokenInfo,
|
|
1577
|
-
chainId,
|
|
1578
|
-
...parameters
|
|
1579
|
-
});
|
|
1733
|
+
throw new Error("Unsupported sale type");
|
|
1580
1734
|
}
|
|
1581
|
-
|
|
1735
|
+
function makePrepareMint721TokenParams({
|
|
1582
1736
|
salesConfigAndTokenInfo,
|
|
1583
1737
|
minterAccount,
|
|
1584
1738
|
tokenContract,
|
|
@@ -1589,7 +1743,8 @@ async function makePrepareMint721TokenParams({
|
|
|
1589
1743
|
}) {
|
|
1590
1744
|
const actualQuantityToMint = BigInt(quantityToMint || 1);
|
|
1591
1745
|
const mintValue = parseMintCosts({
|
|
1592
|
-
salesConfigAndTokenInfo,
|
|
1746
|
+
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
1747
|
+
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
1593
1748
|
quantityToMint: actualQuantityToMint
|
|
1594
1749
|
}).totalCostEth;
|
|
1595
1750
|
return makeContractParameters({
|
|
@@ -1606,15 +1761,65 @@ async function makePrepareMint721TokenParams({
|
|
|
1606
1761
|
]
|
|
1607
1762
|
});
|
|
1608
1763
|
}
|
|
1609
|
-
function
|
|
1764
|
+
function makeEthMintCall({
|
|
1765
|
+
tokenContract,
|
|
1766
|
+
tokenId,
|
|
1610
1767
|
salesConfigAndTokenInfo,
|
|
1768
|
+
minterAccount,
|
|
1769
|
+
mintComment,
|
|
1770
|
+
mintReferral,
|
|
1771
|
+
mintQuantity,
|
|
1772
|
+
mintTo
|
|
1773
|
+
}) {
|
|
1774
|
+
const mintValue = parseMintCosts({
|
|
1775
|
+
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
1776
|
+
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
1777
|
+
quantityToMint: mintQuantity
|
|
1778
|
+
}).totalCostEth;
|
|
1779
|
+
const minterArguments = (0, import_viem5.encodeAbiParameters)(
|
|
1780
|
+
(0, import_viem5.parseAbiParameters)("address, string"),
|
|
1781
|
+
[mintTo, mintComment || ""]
|
|
1782
|
+
);
|
|
1783
|
+
if (contractSupportsNewMintFunction(salesConfigAndTokenInfo.contractVersion)) {
|
|
1784
|
+
return makeContractParameters({
|
|
1785
|
+
abi: import_protocol_deployments6.zoraCreator1155ImplABI,
|
|
1786
|
+
functionName: "mint",
|
|
1787
|
+
account: minterAccount,
|
|
1788
|
+
value: mintValue,
|
|
1789
|
+
address: tokenContract,
|
|
1790
|
+
args: [
|
|
1791
|
+
salesConfigAndTokenInfo.salesConfig.address,
|
|
1792
|
+
BigInt(tokenId),
|
|
1793
|
+
mintQuantity,
|
|
1794
|
+
mintReferral ? [mintReferral] : [],
|
|
1795
|
+
minterArguments
|
|
1796
|
+
]
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
return makeContractParameters({
|
|
1800
|
+
abi: import_protocol_deployments6.zoraCreator1155ImplABI,
|
|
1801
|
+
functionName: "mintWithRewards",
|
|
1802
|
+
account: minterAccount,
|
|
1803
|
+
value: mintValue,
|
|
1804
|
+
address: tokenContract,
|
|
1805
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1806
|
+
args: [
|
|
1807
|
+
salesConfigAndTokenInfo.salesConfig.address,
|
|
1808
|
+
BigInt(tokenId),
|
|
1809
|
+
mintQuantity,
|
|
1810
|
+
minterArguments,
|
|
1811
|
+
mintReferral || import_viem5.zeroAddress
|
|
1812
|
+
]
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
function parseMintCosts({
|
|
1816
|
+
salesConfig,
|
|
1817
|
+
mintFeePerQuantity,
|
|
1611
1818
|
quantityToMint
|
|
1612
1819
|
}) {
|
|
1613
|
-
const mintFeeForTokens =
|
|
1614
|
-
const tokenPurchaseCost = BigInt(
|
|
1615
|
-
const totalPurchaseCostCurrency = isErc20SaleStrategy(
|
|
1616
|
-
salesConfigAndTokenInfo.salesConfig
|
|
1617
|
-
) ? salesConfigAndTokenInfo.salesConfig.currency : void 0;
|
|
1820
|
+
const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
|
|
1821
|
+
const tokenPurchaseCost = BigInt(salesConfig.pricePerToken) * quantityToMint;
|
|
1822
|
+
const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig) ? salesConfig.currency : void 0;
|
|
1618
1823
|
const totalPurchaseCostEth = totalPurchaseCostCurrency ? 0n : tokenPurchaseCost;
|
|
1619
1824
|
return {
|
|
1620
1825
|
mintFee: mintFeeForTokens,
|
|
@@ -1623,93 +1828,337 @@ function parseMintCosts({
|
|
|
1623
1828
|
totalCostEth: mintFeeForTokens + totalPurchaseCostEth
|
|
1624
1829
|
};
|
|
1625
1830
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1831
|
+
|
|
1832
|
+
// src/mint/mint-queries.ts
|
|
1833
|
+
var import_viem6 = require("viem");
|
|
1834
|
+
async function getMint({
|
|
1835
|
+
params,
|
|
1836
|
+
mintGetter,
|
|
1837
|
+
premintGetter,
|
|
1838
|
+
publicClient
|
|
1839
|
+
}) {
|
|
1840
|
+
const { tokenContract } = params;
|
|
1841
|
+
if (isOnChainMint(params)) {
|
|
1842
|
+
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
1843
|
+
const result = await mintGetter.getMintable({
|
|
1844
|
+
tokenId,
|
|
1845
|
+
tokenAddress: tokenContract,
|
|
1846
|
+
preferredSaleType: params.preferredSaleType
|
|
1847
|
+
});
|
|
1848
|
+
return toMintableReturn(result);
|
|
1849
|
+
}
|
|
1850
|
+
const premint = await premintGetter.get({
|
|
1851
|
+
collectionAddress: tokenContract,
|
|
1852
|
+
uid: params.uid
|
|
1853
|
+
});
|
|
1854
|
+
const mintFee = await getPremintMintFee({
|
|
1855
|
+
publicClient,
|
|
1856
|
+
tokenContract
|
|
1857
|
+
});
|
|
1858
|
+
return toPremintMintReturn({ premint, mintFee });
|
|
1859
|
+
}
|
|
1860
|
+
async function getPremintsOfCollectionWithTokenIds({
|
|
1861
|
+
premintGetter,
|
|
1862
|
+
mintGetter,
|
|
1863
|
+
tokenContract
|
|
1864
|
+
}) {
|
|
1865
|
+
const { collection, premints } = await premintGetter.getOfCollection({
|
|
1866
|
+
collectionAddress: tokenContract
|
|
1867
|
+
});
|
|
1868
|
+
const premintUidsAndTokenIds = await mintGetter.getContractPremintTokenIds({
|
|
1869
|
+
tokenAddress: tokenContract
|
|
1870
|
+
});
|
|
1871
|
+
const premintsWithTokenId = premints.map((premint) => ({
|
|
1872
|
+
...premint,
|
|
1873
|
+
tokenId: premintUidsAndTokenIds.find(
|
|
1874
|
+
({ uid }) => uid === premint.premint.premintConfig.uid
|
|
1875
|
+
)?.tokenId
|
|
1876
|
+
}));
|
|
1877
|
+
return {
|
|
1878
|
+
collection,
|
|
1879
|
+
premints: premintsWithTokenId
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
async function getMintsOfContract({
|
|
1883
|
+
params,
|
|
1884
|
+
mintGetter,
|
|
1885
|
+
premintGetter,
|
|
1886
|
+
publicClient
|
|
1887
|
+
}) {
|
|
1888
|
+
const onchainMints = (await mintGetter.getContractMintable({
|
|
1889
|
+
tokenAddress: params.tokenContract
|
|
1890
|
+
})).map(toMintableReturn);
|
|
1891
|
+
const offchainMints = await getPremintsOfContractMintable({
|
|
1892
|
+
mintGetter,
|
|
1893
|
+
premintGetter,
|
|
1894
|
+
publicClient,
|
|
1895
|
+
params: {
|
|
1896
|
+
tokenContract: params.tokenContract
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
const tokens = [...onchainMints, ...offchainMints];
|
|
1900
|
+
return {
|
|
1901
|
+
tokens,
|
|
1902
|
+
contract: tokens[0]?.token.contract
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
async function getMintCosts({
|
|
1906
|
+
params,
|
|
1907
|
+
mintGetter,
|
|
1908
|
+
premintGetter,
|
|
1909
|
+
publicClient
|
|
1910
|
+
}) {
|
|
1911
|
+
const { quantityMinted: quantityToMint, collection } = params;
|
|
1628
1912
|
if (isOnChainMint(params)) {
|
|
1629
1913
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
1630
|
-
const salesConfigAndTokenInfo = await
|
|
1914
|
+
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
1631
1915
|
tokenId,
|
|
1632
1916
|
tokenAddress: collection
|
|
1633
1917
|
});
|
|
1634
1918
|
return parseMintCosts({
|
|
1635
|
-
salesConfigAndTokenInfo,
|
|
1919
|
+
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
1920
|
+
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
1636
1921
|
quantityToMint: BigInt(quantityToMint)
|
|
1637
1922
|
});
|
|
1638
1923
|
}
|
|
1639
1924
|
return getPremintMintCostsWithUnknownTokenPrice({
|
|
1640
|
-
premintGetter
|
|
1925
|
+
premintGetter,
|
|
1641
1926
|
publicClient,
|
|
1642
1927
|
quantityToMint: BigInt(quantityToMint),
|
|
1643
1928
|
uid: params.uid,
|
|
1644
1929
|
tokenContract: collection
|
|
1645
1930
|
});
|
|
1646
1931
|
}
|
|
1647
|
-
function
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
mintComment,
|
|
1653
|
-
mintReferral,
|
|
1654
|
-
mintRecipient,
|
|
1655
|
-
quantityToMint,
|
|
1656
|
-
chainId
|
|
1932
|
+
async function getPremintsOfContractMintable({
|
|
1933
|
+
mintGetter,
|
|
1934
|
+
premintGetter,
|
|
1935
|
+
publicClient,
|
|
1936
|
+
params
|
|
1657
1937
|
}) {
|
|
1658
|
-
const
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
return makeContractParameters({
|
|
1687
|
-
abi: import_protocol_deployments6.erc20MinterABI,
|
|
1688
|
-
functionName: "mint",
|
|
1689
|
-
account: minterAccount,
|
|
1690
|
-
address: salesConfigAndTokenInfo?.salesConfig.address || import_protocol_deployments6.erc20MinterAddress[chainId],
|
|
1691
|
-
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
1692
|
-
args: [
|
|
1693
|
-
mintTo,
|
|
1694
|
-
mintQuantity,
|
|
1695
|
-
tokenContract,
|
|
1696
|
-
BigInt(tokenId),
|
|
1697
|
-
salesConfigAndTokenInfo.salesConfig.pricePerToken * mintQuantity,
|
|
1698
|
-
salesConfigAndTokenInfo.salesConfig.currency,
|
|
1699
|
-
mintReferral || import_viem5.zeroAddress,
|
|
1700
|
-
mintComment || ""
|
|
1701
|
-
]
|
|
1938
|
+
const { premints, collection } = await getPremintsOfCollectionWithTokenIds({
|
|
1939
|
+
mintGetter,
|
|
1940
|
+
premintGetter,
|
|
1941
|
+
tokenContract: params.tokenContract
|
|
1942
|
+
});
|
|
1943
|
+
const offChainPremints = premints.filter(
|
|
1944
|
+
(premint) => (
|
|
1945
|
+
// if premint's uid is not in the list of uids from the subgraph, it is offchain
|
|
1946
|
+
typeof premint.tokenId === "undefined"
|
|
1947
|
+
)
|
|
1948
|
+
);
|
|
1949
|
+
if (offChainPremints.length === 0)
|
|
1950
|
+
return [];
|
|
1951
|
+
const mintFee = await getPremintMintFee({
|
|
1952
|
+
publicClient,
|
|
1953
|
+
tokenContract: params.tokenContract
|
|
1954
|
+
});
|
|
1955
|
+
return offChainPremints.map((premint) => {
|
|
1956
|
+
return toPremintMintReturn({
|
|
1957
|
+
premint: {
|
|
1958
|
+
premint: premint.premint,
|
|
1959
|
+
// todo: fix when api returns signer
|
|
1960
|
+
signer: import_viem6.zeroAddress,
|
|
1961
|
+
collection,
|
|
1962
|
+
collectionAddress: params.tokenContract,
|
|
1963
|
+
signature: premint.signature
|
|
1964
|
+
},
|
|
1965
|
+
mintFee
|
|
1702
1966
|
});
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
function parsePremint({
|
|
1970
|
+
premint,
|
|
1971
|
+
mintFee
|
|
1972
|
+
}) {
|
|
1973
|
+
if (isPremintConfigV1(premint.premint) || isPremintConfigV2(premint.premint)) {
|
|
1974
|
+
return {
|
|
1975
|
+
creator: premint.signer,
|
|
1976
|
+
maxSupply: premint.premint.premintConfig.tokenConfig.maxSupply,
|
|
1977
|
+
mintFeePerQuantity: mintFee,
|
|
1978
|
+
mintType: "premint",
|
|
1979
|
+
uid: premint.premint.premintConfig.uid,
|
|
1980
|
+
contract: {
|
|
1981
|
+
address: premint.collectionAddress,
|
|
1982
|
+
name: premint.collection.contractName,
|
|
1983
|
+
URI: premint.collection.contractURI
|
|
1984
|
+
},
|
|
1985
|
+
tokenURI: premint.premint.premintConfig.tokenConfig.tokenURI,
|
|
1986
|
+
totalMinted: 0n,
|
|
1987
|
+
salesConfig: {
|
|
1988
|
+
duration: premint.premint.premintConfig.tokenConfig.mintDuration,
|
|
1989
|
+
maxTokensPerAddress: premint.premint.premintConfig.tokenConfig.maxTokensPerAddress,
|
|
1990
|
+
pricePerToken: premint.premint.premintConfig.tokenConfig.pricePerToken,
|
|
1991
|
+
saleType: "premint"
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1703
1994
|
}
|
|
1704
|
-
throw new
|
|
1995
|
+
throw new Error("Invalid premint config version");
|
|
1705
1996
|
}
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1997
|
+
var makeOnchainPrepareMint = (result) => (params) => ({
|
|
1998
|
+
parameters: makeOnchainMintCall({ token: result, mintParams: params }),
|
|
1999
|
+
erc20Approval: getRequiredErc20Approvals(params, result),
|
|
2000
|
+
costs: parseMintCosts({
|
|
2001
|
+
salesConfig: result.salesConfig,
|
|
2002
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
2003
|
+
mintFeePerQuantity: result.mintFeePerQuantity
|
|
2004
|
+
})
|
|
2005
|
+
});
|
|
2006
|
+
function toMintableReturn(result) {
|
|
2007
|
+
return { token: result, prepareMint: makeOnchainPrepareMint(result) };
|
|
2008
|
+
}
|
|
2009
|
+
var makePremintPrepareMint = (mintable, mintFee, premint) => (params) => ({
|
|
2010
|
+
parameters: buildPremintMintCall({
|
|
2011
|
+
mintArguments: params,
|
|
2012
|
+
mintFee,
|
|
2013
|
+
premint
|
|
2014
|
+
}),
|
|
2015
|
+
costs: parseMintCosts({
|
|
2016
|
+
mintFeePerQuantity: mintFee,
|
|
2017
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
2018
|
+
salesConfig: mintable.salesConfig
|
|
2019
|
+
})
|
|
2020
|
+
});
|
|
2021
|
+
function toPremintMintReturn({
|
|
2022
|
+
premint,
|
|
2023
|
+
mintFee
|
|
2024
|
+
}) {
|
|
2025
|
+
const mintable = parsePremint({ premint, mintFee });
|
|
2026
|
+
return {
|
|
2027
|
+
token: mintable,
|
|
2028
|
+
prepareMint: makePremintPrepareMint(mintable, mintFee, premint)
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function getRequiredErc20Approvals(params, result) {
|
|
2032
|
+
if (result.salesConfig.saleType !== "erc20")
|
|
2033
|
+
return void 0;
|
|
2034
|
+
return {
|
|
2035
|
+
quantity: result.salesConfig.pricePerToken * BigInt(params.quantityToMint),
|
|
2036
|
+
approveTo: result.salesConfig.address,
|
|
2037
|
+
erc20: result.salesConfig.currency
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
// src/mint/mint-client.ts
|
|
2042
|
+
var MintError = class extends Error {
|
|
2043
|
+
};
|
|
2044
|
+
var MintInactiveError = class extends Error {
|
|
2045
|
+
};
|
|
2046
|
+
var Errors = {
|
|
2047
|
+
MintError,
|
|
2048
|
+
MintInactiveError
|
|
2049
|
+
};
|
|
2050
|
+
var MintClient = class {
|
|
2051
|
+
constructor({
|
|
2052
|
+
publicClient,
|
|
2053
|
+
premintGetter,
|
|
2054
|
+
mintGetter
|
|
2055
|
+
}) {
|
|
2056
|
+
this.publicClient = publicClient;
|
|
2057
|
+
this.mintGetter = mintGetter;
|
|
2058
|
+
this.premintGetter = premintGetter;
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Returns the parameters needed to prepare a transaction mint a token.
|
|
2062
|
+
* Works with premint, onchain 1155, and onchain 721.
|
|
2063
|
+
*
|
|
2064
|
+
* @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
|
|
2065
|
+
* @returns Parameters for simulating/executing the mint transaction, any necessary erc20 approval, and costs to mint
|
|
2066
|
+
*/
|
|
2067
|
+
async mint(parameters) {
|
|
2068
|
+
return mint({
|
|
2069
|
+
parameters,
|
|
2070
|
+
publicClient: this.publicClient,
|
|
2071
|
+
mintGetter: this.mintGetter,
|
|
2072
|
+
premintGetter: this.premintGetter
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Gets an 1155, 721, or premint, and returns both information about it, and a function
|
|
2077
|
+
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
2078
|
+
* @param parameters - Token to get {@link GetMintParameters}
|
|
2079
|
+
* @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
|
|
2080
|
+
*/
|
|
2081
|
+
async get(parameters) {
|
|
2082
|
+
return getMint({
|
|
2083
|
+
params: parameters,
|
|
2084
|
+
mintGetter: this.mintGetter,
|
|
2085
|
+
premintGetter: this.premintGetter,
|
|
2086
|
+
publicClient: this.publicClient
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Gets onchain and premint tokens of an 1155 contract. For each token returns both information about it, and a function
|
|
2091
|
+
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
2092
|
+
* @param parameters - Contract address to get tokens for {@link GetMintsOfContractParameters}
|
|
2093
|
+
* @Returns Array of tokens, each containing information about the token and a function to build a mint transaction.
|
|
2094
|
+
*/
|
|
2095
|
+
async getOfContract(params) {
|
|
2096
|
+
return getMintsOfContract({
|
|
2097
|
+
params,
|
|
2098
|
+
mintGetter: this.mintGetter,
|
|
2099
|
+
premintGetter: this.premintGetter,
|
|
2100
|
+
publicClient: this.publicClient
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
2105
|
+
* @param parameters - Parameters for the mint {@link GetMintCostsParameters}
|
|
2106
|
+
* @returns Costs to mint the quantity of tokens specified
|
|
2107
|
+
*/
|
|
2108
|
+
async getMintCosts(parameters) {
|
|
2109
|
+
return getMintCosts({
|
|
2110
|
+
params: parameters,
|
|
2111
|
+
mintGetter: this.mintGetter,
|
|
2112
|
+
premintGetter: this.premintGetter,
|
|
2113
|
+
publicClient: this.publicClient
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
async function mint({
|
|
2118
|
+
parameters,
|
|
2119
|
+
publicClient,
|
|
2120
|
+
mintGetter,
|
|
2121
|
+
premintGetter
|
|
2122
|
+
}) {
|
|
2123
|
+
const { prepareMint } = await getMint({
|
|
2124
|
+
params: parameters,
|
|
2125
|
+
mintGetter,
|
|
2126
|
+
premintGetter,
|
|
2127
|
+
publicClient
|
|
2128
|
+
});
|
|
2129
|
+
return prepareMint({
|
|
2130
|
+
minterAccount: parameters.minterAccount,
|
|
2131
|
+
quantityToMint: parameters.quantityToMint,
|
|
2132
|
+
firstMinter: parameters.firstMinter,
|
|
2133
|
+
mintComment: parameters.mintComment,
|
|
2134
|
+
mintRecipient: parameters.mintRecipient,
|
|
2135
|
+
mintReferral: parameters.mintReferral
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
async function collectOnchain({
|
|
2139
|
+
chainId,
|
|
2140
|
+
mintGetter,
|
|
2141
|
+
...parameters
|
|
2142
|
+
}) {
|
|
2143
|
+
const { tokenContract, preferredSaleType: saleType } = parameters;
|
|
2144
|
+
const tokenId = is1155Mint(parameters) ? parameters.tokenId : void 0;
|
|
2145
|
+
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
2146
|
+
tokenId,
|
|
2147
|
+
tokenAddress: tokenContract,
|
|
2148
|
+
preferredSaleType: saleType
|
|
2149
|
+
});
|
|
2150
|
+
return makeOnchainMintCall({
|
|
2151
|
+
mintParams: parameters,
|
|
2152
|
+
token: salesConfigAndTokenInfo
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
// src/create/1155-create-helper.ts
|
|
2157
|
+
var import_protocol_deployments9 = require("@zoralabs/protocol-deployments");
|
|
2158
|
+
var import_viem8 = require("viem");
|
|
2159
|
+
|
|
2160
|
+
// src/create/contract-setup.ts
|
|
2161
|
+
var import_protocol_deployments7 = require("@zoralabs/protocol-deployments");
|
|
1713
2162
|
function new1155ContractVersion(chainId) {
|
|
1714
2163
|
const address = import_protocol_deployments7.contracts1155.addresses[chainId];
|
|
1715
2164
|
if (!address) {
|
|
@@ -1763,15 +2212,15 @@ async function getContractInfo({
|
|
|
1763
2212
|
|
|
1764
2213
|
// src/create/token-setup.ts
|
|
1765
2214
|
var import_protocol_deployments8 = require("@zoralabs/protocol-deployments");
|
|
1766
|
-
var
|
|
1767
|
-
var
|
|
2215
|
+
var import_viem7 = require("viem");
|
|
2216
|
+
var semver2 = __toESM(require("semver"), 1);
|
|
1768
2217
|
var PERMISSION_BITS = {
|
|
1769
2218
|
MINTER: 2n ** 2n
|
|
1770
2219
|
};
|
|
1771
2220
|
var saleSettingsOrDefault = (saleSettings) => {
|
|
1772
2221
|
const SALE_END_FOREVER = 18446744073709551615n;
|
|
1773
2222
|
const DEFAULT_SALE_SETTINGS = {
|
|
1774
|
-
currency:
|
|
2223
|
+
currency: import_viem7.zeroAddress,
|
|
1775
2224
|
// Free Mint
|
|
1776
2225
|
pricePerToken: 0n,
|
|
1777
2226
|
// Sale start time – defaults to beginning of unix time
|
|
@@ -1788,10 +2237,10 @@ var saleSettingsOrDefault = (saleSettings) => {
|
|
|
1788
2237
|
};
|
|
1789
2238
|
function applyNew1155Defaults(props, ownerAddress) {
|
|
1790
2239
|
const { payoutRecipient: fundsRecipient } = props;
|
|
1791
|
-
const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !==
|
|
2240
|
+
const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== import_viem7.zeroAddress ? fundsRecipient : ownerAddress;
|
|
1792
2241
|
return {
|
|
1793
2242
|
payoutRecipient: fundsRecipientOrOwner,
|
|
1794
|
-
createReferral: props.createReferral ||
|
|
2243
|
+
createReferral: props.createReferral || import_viem7.zeroAddress,
|
|
1795
2244
|
maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
|
|
1796
2245
|
royaltyBPS: props.royaltyBPS || 1e3,
|
|
1797
2246
|
salesConfig: saleSettingsOrDefault(props.salesConfig),
|
|
@@ -1808,15 +2257,15 @@ function setupErc20Minter({
|
|
|
1808
2257
|
maxTokensPerAddress: mintLimit,
|
|
1809
2258
|
fundsRecipient
|
|
1810
2259
|
}) {
|
|
1811
|
-
const
|
|
1812
|
-
if (!
|
|
2260
|
+
const erc20MinterAddress = import_protocol_deployments8.erc20MinterAddress[chainId];
|
|
2261
|
+
if (!erc20MinterAddress)
|
|
1813
2262
|
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
1814
|
-
const erc20MinterApproval = (0,
|
|
2263
|
+
const erc20MinterApproval = (0, import_viem7.encodeFunctionData)({
|
|
1815
2264
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1816
2265
|
functionName: "addPermission",
|
|
1817
|
-
args: [BigInt(nextTokenId),
|
|
2266
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
|
|
1818
2267
|
});
|
|
1819
|
-
const saleData = (0,
|
|
2268
|
+
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
1820
2269
|
abi: import_protocol_deployments8.erc20MinterABI,
|
|
1821
2270
|
functionName: "setSale",
|
|
1822
2271
|
args: [
|
|
@@ -1831,13 +2280,13 @@ function setupErc20Minter({
|
|
|
1831
2280
|
}
|
|
1832
2281
|
]
|
|
1833
2282
|
});
|
|
1834
|
-
const callSale = (0,
|
|
2283
|
+
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
1835
2284
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1836
2285
|
functionName: "callSale",
|
|
1837
|
-
args: [BigInt(nextTokenId),
|
|
2286
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
|
|
1838
2287
|
});
|
|
1839
2288
|
return {
|
|
1840
|
-
minter:
|
|
2289
|
+
minter: erc20MinterAddress,
|
|
1841
2290
|
setupActions: [erc20MinterApproval, callSale]
|
|
1842
2291
|
};
|
|
1843
2292
|
}
|
|
@@ -1851,7 +2300,7 @@ function setupFixedPriceMinter({
|
|
|
1851
2300
|
fundsRecipient
|
|
1852
2301
|
}) {
|
|
1853
2302
|
const fixedPriceStrategyAddress = import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyAddress[chainId];
|
|
1854
|
-
const fixedPriceApproval = (0,
|
|
2303
|
+
const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
|
|
1855
2304
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1856
2305
|
functionName: "addPermission",
|
|
1857
2306
|
args: [
|
|
@@ -1860,7 +2309,7 @@ function setupFixedPriceMinter({
|
|
|
1860
2309
|
PERMISSION_BITS.MINTER
|
|
1861
2310
|
]
|
|
1862
2311
|
});
|
|
1863
|
-
const saleData = (0,
|
|
2312
|
+
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
1864
2313
|
abi: import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyABI,
|
|
1865
2314
|
functionName: "setSale",
|
|
1866
2315
|
args: [
|
|
@@ -1874,7 +2323,7 @@ function setupFixedPriceMinter({
|
|
|
1874
2323
|
}
|
|
1875
2324
|
]
|
|
1876
2325
|
});
|
|
1877
|
-
const callSale = (0,
|
|
2326
|
+
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
1878
2327
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1879
2328
|
functionName: "callSale",
|
|
1880
2329
|
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
|
|
@@ -1888,7 +2337,7 @@ function setupMinters({ salesConfig, ...rest }) {
|
|
|
1888
2337
|
if (!salesConfig)
|
|
1889
2338
|
throw new Error("No sales config for token");
|
|
1890
2339
|
const { currency: currencyAddress } = salesConfig;
|
|
1891
|
-
if (currencyAddress ===
|
|
2340
|
+
if (currencyAddress === import_viem7.zeroAddress) {
|
|
1892
2341
|
return setupFixedPriceMinter({
|
|
1893
2342
|
...salesConfig,
|
|
1894
2343
|
...rest
|
|
@@ -1903,22 +2352,22 @@ function setupMinters({ salesConfig, ...rest }) {
|
|
|
1903
2352
|
function buildSetupNewToken({
|
|
1904
2353
|
tokenURI,
|
|
1905
2354
|
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
1906
|
-
createReferral =
|
|
2355
|
+
createReferral = import_viem7.zeroAddress,
|
|
1907
2356
|
contractVersion
|
|
1908
2357
|
}) {
|
|
1909
2358
|
if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
|
|
1910
|
-
return (0,
|
|
2359
|
+
return (0, import_viem7.encodeFunctionData)({
|
|
1911
2360
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1912
2361
|
functionName: "setupNewTokenWithCreateReferral",
|
|
1913
2362
|
args: [tokenURI, BigInt(maxSupply), createReferral]
|
|
1914
2363
|
});
|
|
1915
2364
|
}
|
|
1916
|
-
if (createReferral !==
|
|
2365
|
+
if (createReferral !== import_viem7.zeroAddress) {
|
|
1917
2366
|
throw new Error(
|
|
1918
2367
|
"Contract does not support create referral, but one was provided"
|
|
1919
2368
|
);
|
|
1920
2369
|
}
|
|
1921
|
-
return (0,
|
|
2370
|
+
return (0, import_viem7.encodeFunctionData)({
|
|
1922
2371
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1923
2372
|
functionName: "setupNewToken",
|
|
1924
2373
|
args: [tokenURI, BigInt(maxSupply)]
|
|
@@ -1929,8 +2378,8 @@ function setupRoyaltyConfig({
|
|
|
1929
2378
|
royaltyRecipient,
|
|
1930
2379
|
nextTokenId
|
|
1931
2380
|
}) {
|
|
1932
|
-
if (royaltyBPS > 0 && royaltyRecipient !=
|
|
1933
|
-
return (0,
|
|
2381
|
+
if (royaltyBPS > 0 && royaltyRecipient != import_viem7.zeroAddress) {
|
|
2382
|
+
return (0, import_viem7.encodeFunctionData)({
|
|
1934
2383
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1935
2384
|
functionName: "updateRoyaltiesForToken",
|
|
1936
2385
|
args: [
|
|
@@ -1953,10 +2402,10 @@ function makeAdminMintCall({
|
|
|
1953
2402
|
if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
|
|
1954
2403
|
return null;
|
|
1955
2404
|
}
|
|
1956
|
-
return (0,
|
|
2405
|
+
return (0, import_viem7.encodeFunctionData)({
|
|
1957
2406
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1958
2407
|
functionName: "adminMint",
|
|
1959
|
-
args: [ownerAddress, nextTokenId, BigInt(mintQuantity),
|
|
2408
|
+
args: [ownerAddress, nextTokenId, BigInt(mintQuantity), import_viem7.zeroAddress]
|
|
1960
2409
|
});
|
|
1961
2410
|
}
|
|
1962
2411
|
function constructCreate1155TokenCalls(props) {
|
|
@@ -1971,7 +2420,7 @@ function constructCreate1155TokenCalls(props) {
|
|
|
1971
2420
|
props,
|
|
1972
2421
|
ownerAddress
|
|
1973
2422
|
);
|
|
1974
|
-
const verifyTokenIdExpected = (0,
|
|
2423
|
+
const verifyTokenIdExpected = (0, import_viem7.encodeFunctionData)({
|
|
1975
2424
|
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
1976
2425
|
functionName: "assumeLastTokenIdMatches",
|
|
1977
2426
|
args: [nextTokenId - 1n]
|
|
@@ -2015,13 +2464,13 @@ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
|
|
|
2015
2464
|
if (!contractStandard || !contractVersion) {
|
|
2016
2465
|
return false;
|
|
2017
2466
|
}
|
|
2018
|
-
const semVerContractVersion =
|
|
2467
|
+
const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
|
|
2019
2468
|
if (!semVerContractVersion)
|
|
2020
2469
|
return false;
|
|
2021
2470
|
if (contractStandard === "ERC1155") {
|
|
2022
|
-
return
|
|
2471
|
+
return semver2.gte(semVerContractVersion, "1.3.5");
|
|
2023
2472
|
} else {
|
|
2024
|
-
return
|
|
2473
|
+
return semver2.gte(semVerContractVersion, "14.0.0");
|
|
2025
2474
|
}
|
|
2026
2475
|
};
|
|
2027
2476
|
|
|
@@ -2030,7 +2479,7 @@ var ROYALTY_BPS_DEFAULT = 1e3;
|
|
|
2030
2479
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
2031
2480
|
for (const data of receipt.logs) {
|
|
2032
2481
|
try {
|
|
2033
|
-
const decodedLog = (0,
|
|
2482
|
+
const decodedLog = (0, import_viem8.decodeEventLog)({
|
|
2034
2483
|
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
2035
2484
|
eventName: "SetupNewToken",
|
|
2036
2485
|
...data
|
|
@@ -2212,7 +2661,7 @@ var sumBalances = (mintAccountBalances) => {
|
|
|
2212
2661
|
|
|
2213
2662
|
// src/mints/mints-contracts.ts
|
|
2214
2663
|
var import_protocol_deployments10 = require("@zoralabs/protocol-deployments");
|
|
2215
|
-
var
|
|
2664
|
+
var import_viem9 = require("viem");
|
|
2216
2665
|
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
2217
2666
|
var mintWithEthParams = ({
|
|
2218
2667
|
quantity,
|
|
@@ -2247,7 +2696,7 @@ var encodeCollectOnManager = ({
|
|
|
2247
2696
|
minter,
|
|
2248
2697
|
zoraCreator1155TokenId,
|
|
2249
2698
|
mintArguments
|
|
2250
|
-
}) => (0,
|
|
2699
|
+
}) => (0, import_viem9.encodeFunctionData)({
|
|
2251
2700
|
abi: import_protocol_deployments10.zoraMintsManagerImplConfig.abi,
|
|
2252
2701
|
functionName: "collect",
|
|
2253
2702
|
args: [
|
|
@@ -2367,8 +2816,8 @@ var encodePremintOnManager = ({
|
|
|
2367
2816
|
premintConfig,
|
|
2368
2817
|
premintSignature,
|
|
2369
2818
|
mintArguments,
|
|
2370
|
-
signerContract =
|
|
2371
|
-
}) => (0,
|
|
2819
|
+
signerContract = import_viem9.zeroAddress
|
|
2820
|
+
}) => (0, import_viem9.encodeFunctionData)({
|
|
2372
2821
|
abi: import_protocol_deployments10.zoraMintsManagerImplConfig.abi,
|
|
2373
2822
|
functionName: "collectPremintV2",
|
|
2374
2823
|
args: [
|
|
@@ -2435,7 +2884,7 @@ function decodeCallFailedError(error) {
|
|
|
2435
2884
|
if (error.data?.errorName !== "CallFailed")
|
|
2436
2885
|
throw new Error("Not a CallFailed error");
|
|
2437
2886
|
const internalErrorData = error.data?.args?.[0];
|
|
2438
|
-
return (0,
|
|
2887
|
+
return (0, import_viem9.decodeErrorResult)({
|
|
2439
2888
|
abi: import_protocol_deployments10.zoraMintsManagerImplABI,
|
|
2440
2889
|
data: internalErrorData
|
|
2441
2890
|
});
|
|
@@ -2443,12 +2892,12 @@ function decodeCallFailedError(error) {
|
|
|
2443
2892
|
|
|
2444
2893
|
// src/mints/mints-eth-unwrapper-and-caller.ts
|
|
2445
2894
|
var import_protocol_deployments11 = require("@zoralabs/protocol-deployments");
|
|
2446
|
-
var
|
|
2895
|
+
var import_viem10 = require("viem");
|
|
2447
2896
|
var makeCallWithEthSafeTransferData = ({
|
|
2448
2897
|
address: addressToCall,
|
|
2449
2898
|
call: functionToCall,
|
|
2450
2899
|
value: valueToSend
|
|
2451
|
-
}) => (0,
|
|
2900
|
+
}) => (0, import_viem10.encodeFunctionData)({
|
|
2452
2901
|
abi: import_protocol_deployments11.iUnwrapAndForwardActionABI,
|
|
2453
2902
|
functionName: "callWithEth",
|
|
2454
2903
|
args: [addressToCall, functionToCall, valueToSend]
|
|
@@ -2457,13 +2906,13 @@ var unwrapAndForwardEthPermitAndTypedDataDefinition = ({
|
|
|
2457
2906
|
chainId,
|
|
2458
2907
|
tokenIds,
|
|
2459
2908
|
quantities,
|
|
2460
|
-
from,
|
|
2909
|
+
from: from2,
|
|
2461
2910
|
callWithEth,
|
|
2462
2911
|
safeTransferData,
|
|
2463
2912
|
deadline,
|
|
2464
2913
|
nonce
|
|
2465
2914
|
}) => makePermitTransferBatchAndTypeData({
|
|
2466
|
-
mintsOwner:
|
|
2915
|
+
mintsOwner: from2,
|
|
2467
2916
|
chainId,
|
|
2468
2917
|
deadline,
|
|
2469
2918
|
tokenIds,
|
|
@@ -2495,21 +2944,1164 @@ function createCollectorClient(params) {
|
|
|
2495
2944
|
const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
|
|
2496
2945
|
const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
|
|
2497
2946
|
const mintClient = new MintClient({
|
|
2498
|
-
chainId: params.chainId,
|
|
2499
2947
|
publicClient: params.publicClient,
|
|
2500
2948
|
premintGetter: premintGetterToUse,
|
|
2501
2949
|
mintGetter: mintGetterToUse
|
|
2502
2950
|
});
|
|
2503
2951
|
return {
|
|
2504
|
-
getPremint: (p) => premintGetterToUse.
|
|
2952
|
+
getPremint: (p) => premintGetterToUse.get({
|
|
2505
2953
|
collectionAddress: p.address,
|
|
2506
2954
|
uid: p.uid
|
|
2507
2955
|
}),
|
|
2508
2956
|
getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
|
|
2957
|
+
getToken: (p) => mintClient.get(p),
|
|
2958
|
+
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
2509
2959
|
mint: (p) => mintClient.mint(p),
|
|
2510
2960
|
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
2511
2961
|
};
|
|
2512
2962
|
}
|
|
2963
|
+
|
|
2964
|
+
// src/ipfs/arweave.ts
|
|
2965
|
+
function isArweaveURL(url) {
|
|
2966
|
+
return url && typeof url === "string" ? url.startsWith("ar://") : false;
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
// ../../node_modules/multiformats/esm/vendor/varint.js
|
|
2970
|
+
var encode_1 = encode;
|
|
2971
|
+
var MSB = 128;
|
|
2972
|
+
var REST = 127;
|
|
2973
|
+
var MSBALL = ~REST;
|
|
2974
|
+
var INT = Math.pow(2, 31);
|
|
2975
|
+
function encode(num, out, offset) {
|
|
2976
|
+
out = out || [];
|
|
2977
|
+
offset = offset || 0;
|
|
2978
|
+
var oldOffset = offset;
|
|
2979
|
+
while (num >= INT) {
|
|
2980
|
+
out[offset++] = num & 255 | MSB;
|
|
2981
|
+
num /= 128;
|
|
2982
|
+
}
|
|
2983
|
+
while (num & MSBALL) {
|
|
2984
|
+
out[offset++] = num & 255 | MSB;
|
|
2985
|
+
num >>>= 7;
|
|
2986
|
+
}
|
|
2987
|
+
out[offset] = num | 0;
|
|
2988
|
+
encode.bytes = offset - oldOffset + 1;
|
|
2989
|
+
return out;
|
|
2990
|
+
}
|
|
2991
|
+
var decode = read;
|
|
2992
|
+
var MSB$1 = 128;
|
|
2993
|
+
var REST$1 = 127;
|
|
2994
|
+
function read(buf, offset) {
|
|
2995
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
2996
|
+
do {
|
|
2997
|
+
if (counter >= l) {
|
|
2998
|
+
read.bytes = 0;
|
|
2999
|
+
throw new RangeError("Could not decode varint");
|
|
3000
|
+
}
|
|
3001
|
+
b = buf[counter++];
|
|
3002
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
3003
|
+
shift += 7;
|
|
3004
|
+
} while (b >= MSB$1);
|
|
3005
|
+
read.bytes = counter - offset;
|
|
3006
|
+
return res;
|
|
3007
|
+
}
|
|
3008
|
+
var N1 = Math.pow(2, 7);
|
|
3009
|
+
var N2 = Math.pow(2, 14);
|
|
3010
|
+
var N3 = Math.pow(2, 21);
|
|
3011
|
+
var N4 = Math.pow(2, 28);
|
|
3012
|
+
var N5 = Math.pow(2, 35);
|
|
3013
|
+
var N6 = Math.pow(2, 42);
|
|
3014
|
+
var N7 = Math.pow(2, 49);
|
|
3015
|
+
var N8 = Math.pow(2, 56);
|
|
3016
|
+
var N9 = Math.pow(2, 63);
|
|
3017
|
+
var length = function(value) {
|
|
3018
|
+
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
|
|
3019
|
+
};
|
|
3020
|
+
var varint = {
|
|
3021
|
+
encode: encode_1,
|
|
3022
|
+
decode,
|
|
3023
|
+
encodingLength: length
|
|
3024
|
+
};
|
|
3025
|
+
var _brrp_varint = varint;
|
|
3026
|
+
var varint_default = _brrp_varint;
|
|
3027
|
+
|
|
3028
|
+
// ../../node_modules/multiformats/esm/src/varint.js
|
|
3029
|
+
var decode2 = (data, offset = 0) => {
|
|
3030
|
+
const code = varint_default.decode(data, offset);
|
|
3031
|
+
return [
|
|
3032
|
+
code,
|
|
3033
|
+
varint_default.decode.bytes
|
|
3034
|
+
];
|
|
3035
|
+
};
|
|
3036
|
+
var encodeTo = (int, target, offset = 0) => {
|
|
3037
|
+
varint_default.encode(int, target, offset);
|
|
3038
|
+
return target;
|
|
3039
|
+
};
|
|
3040
|
+
var encodingLength = (int) => {
|
|
3041
|
+
return varint_default.encodingLength(int);
|
|
3042
|
+
};
|
|
3043
|
+
|
|
3044
|
+
// ../../node_modules/multiformats/esm/src/bytes.js
|
|
3045
|
+
var empty = new Uint8Array(0);
|
|
3046
|
+
var equals = (aa, bb) => {
|
|
3047
|
+
if (aa === bb)
|
|
3048
|
+
return true;
|
|
3049
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
3050
|
+
return false;
|
|
3051
|
+
}
|
|
3052
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
3053
|
+
if (aa[ii] !== bb[ii]) {
|
|
3054
|
+
return false;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
return true;
|
|
3058
|
+
};
|
|
3059
|
+
var coerce3 = (o) => {
|
|
3060
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
3061
|
+
return o;
|
|
3062
|
+
if (o instanceof ArrayBuffer)
|
|
3063
|
+
return new Uint8Array(o);
|
|
3064
|
+
if (ArrayBuffer.isView(o)) {
|
|
3065
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
3066
|
+
}
|
|
3067
|
+
throw new Error("Unknown type, must be binary type");
|
|
3068
|
+
};
|
|
3069
|
+
|
|
3070
|
+
// ../../node_modules/multiformats/esm/src/hashes/digest.js
|
|
3071
|
+
var create = (code, digest) => {
|
|
3072
|
+
const size = digest.byteLength;
|
|
3073
|
+
const sizeOffset = encodingLength(code);
|
|
3074
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
3075
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
3076
|
+
encodeTo(code, bytes, 0);
|
|
3077
|
+
encodeTo(size, bytes, sizeOffset);
|
|
3078
|
+
bytes.set(digest, digestOffset);
|
|
3079
|
+
return new Digest(code, size, digest, bytes);
|
|
3080
|
+
};
|
|
3081
|
+
var decode3 = (multihash) => {
|
|
3082
|
+
const bytes = coerce3(multihash);
|
|
3083
|
+
const [code, sizeOffset] = decode2(bytes);
|
|
3084
|
+
const [size, digestOffset] = decode2(bytes.subarray(sizeOffset));
|
|
3085
|
+
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
3086
|
+
if (digest.byteLength !== size) {
|
|
3087
|
+
throw new Error("Incorrect length");
|
|
3088
|
+
}
|
|
3089
|
+
return new Digest(code, size, digest, bytes);
|
|
3090
|
+
};
|
|
3091
|
+
var equals2 = (a, b) => {
|
|
3092
|
+
if (a === b) {
|
|
3093
|
+
return true;
|
|
3094
|
+
} else {
|
|
3095
|
+
return a.code === b.code && a.size === b.size && equals(a.bytes, b.bytes);
|
|
3096
|
+
}
|
|
3097
|
+
};
|
|
3098
|
+
var Digest = class {
|
|
3099
|
+
constructor(code, size, digest, bytes) {
|
|
3100
|
+
this.code = code;
|
|
3101
|
+
this.size = size;
|
|
3102
|
+
this.digest = digest;
|
|
3103
|
+
this.bytes = bytes;
|
|
3104
|
+
}
|
|
3105
|
+
};
|
|
3106
|
+
|
|
3107
|
+
// ../../node_modules/multiformats/esm/vendor/base-x.js
|
|
3108
|
+
function base2(ALPHABET, name) {
|
|
3109
|
+
if (ALPHABET.length >= 255) {
|
|
3110
|
+
throw new TypeError("Alphabet too long");
|
|
3111
|
+
}
|
|
3112
|
+
var BASE_MAP = new Uint8Array(256);
|
|
3113
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3114
|
+
BASE_MAP[j] = 255;
|
|
3115
|
+
}
|
|
3116
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3117
|
+
var x = ALPHABET.charAt(i);
|
|
3118
|
+
var xc = x.charCodeAt(0);
|
|
3119
|
+
if (BASE_MAP[xc] !== 255) {
|
|
3120
|
+
throw new TypeError(x + " is ambiguous");
|
|
3121
|
+
}
|
|
3122
|
+
BASE_MAP[xc] = i;
|
|
3123
|
+
}
|
|
3124
|
+
var BASE = ALPHABET.length;
|
|
3125
|
+
var LEADER = ALPHABET.charAt(0);
|
|
3126
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
3127
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
3128
|
+
function encode3(source) {
|
|
3129
|
+
if (source instanceof Uint8Array)
|
|
3130
|
+
;
|
|
3131
|
+
else if (ArrayBuffer.isView(source)) {
|
|
3132
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
3133
|
+
} else if (Array.isArray(source)) {
|
|
3134
|
+
source = Uint8Array.from(source);
|
|
3135
|
+
}
|
|
3136
|
+
if (!(source instanceof Uint8Array)) {
|
|
3137
|
+
throw new TypeError("Expected Uint8Array");
|
|
3138
|
+
}
|
|
3139
|
+
if (source.length === 0) {
|
|
3140
|
+
return "";
|
|
3141
|
+
}
|
|
3142
|
+
var zeroes = 0;
|
|
3143
|
+
var length2 = 0;
|
|
3144
|
+
var pbegin = 0;
|
|
3145
|
+
var pend = source.length;
|
|
3146
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3147
|
+
pbegin++;
|
|
3148
|
+
zeroes++;
|
|
3149
|
+
}
|
|
3150
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
3151
|
+
var b58 = new Uint8Array(size);
|
|
3152
|
+
while (pbegin !== pend) {
|
|
3153
|
+
var carry = source[pbegin];
|
|
3154
|
+
var i2 = 0;
|
|
3155
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
3156
|
+
carry += 256 * b58[it1] >>> 0;
|
|
3157
|
+
b58[it1] = carry % BASE >>> 0;
|
|
3158
|
+
carry = carry / BASE >>> 0;
|
|
3159
|
+
}
|
|
3160
|
+
if (carry !== 0) {
|
|
3161
|
+
throw new Error("Non-zero carry");
|
|
3162
|
+
}
|
|
3163
|
+
length2 = i2;
|
|
3164
|
+
pbegin++;
|
|
3165
|
+
}
|
|
3166
|
+
var it2 = size - length2;
|
|
3167
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
3168
|
+
it2++;
|
|
3169
|
+
}
|
|
3170
|
+
var str = LEADER.repeat(zeroes);
|
|
3171
|
+
for (; it2 < size; ++it2) {
|
|
3172
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
3173
|
+
}
|
|
3174
|
+
return str;
|
|
3175
|
+
}
|
|
3176
|
+
function decodeUnsafe(source) {
|
|
3177
|
+
if (typeof source !== "string") {
|
|
3178
|
+
throw new TypeError("Expected String");
|
|
3179
|
+
}
|
|
3180
|
+
if (source.length === 0) {
|
|
3181
|
+
return new Uint8Array();
|
|
3182
|
+
}
|
|
3183
|
+
var psz = 0;
|
|
3184
|
+
if (source[psz] === " ") {
|
|
3185
|
+
return;
|
|
3186
|
+
}
|
|
3187
|
+
var zeroes = 0;
|
|
3188
|
+
var length2 = 0;
|
|
3189
|
+
while (source[psz] === LEADER) {
|
|
3190
|
+
zeroes++;
|
|
3191
|
+
psz++;
|
|
3192
|
+
}
|
|
3193
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
3194
|
+
var b256 = new Uint8Array(size);
|
|
3195
|
+
while (source[psz]) {
|
|
3196
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
3197
|
+
if (carry === 255) {
|
|
3198
|
+
return;
|
|
3199
|
+
}
|
|
3200
|
+
var i2 = 0;
|
|
3201
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
3202
|
+
carry += BASE * b256[it3] >>> 0;
|
|
3203
|
+
b256[it3] = carry % 256 >>> 0;
|
|
3204
|
+
carry = carry / 256 >>> 0;
|
|
3205
|
+
}
|
|
3206
|
+
if (carry !== 0) {
|
|
3207
|
+
throw new Error("Non-zero carry");
|
|
3208
|
+
}
|
|
3209
|
+
length2 = i2;
|
|
3210
|
+
psz++;
|
|
3211
|
+
}
|
|
3212
|
+
if (source[psz] === " ") {
|
|
3213
|
+
return;
|
|
3214
|
+
}
|
|
3215
|
+
var it4 = size - length2;
|
|
3216
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
3217
|
+
it4++;
|
|
3218
|
+
}
|
|
3219
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3220
|
+
var j2 = zeroes;
|
|
3221
|
+
while (it4 !== size) {
|
|
3222
|
+
vch[j2++] = b256[it4++];
|
|
3223
|
+
}
|
|
3224
|
+
return vch;
|
|
3225
|
+
}
|
|
3226
|
+
function decode5(string) {
|
|
3227
|
+
var buffer = decodeUnsafe(string);
|
|
3228
|
+
if (buffer) {
|
|
3229
|
+
return buffer;
|
|
3230
|
+
}
|
|
3231
|
+
throw new Error(`Non-${name} character`);
|
|
3232
|
+
}
|
|
3233
|
+
return {
|
|
3234
|
+
encode: encode3,
|
|
3235
|
+
decodeUnsafe,
|
|
3236
|
+
decode: decode5
|
|
3237
|
+
};
|
|
3238
|
+
}
|
|
3239
|
+
var src = base2;
|
|
3240
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
3241
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
3242
|
+
|
|
3243
|
+
// ../../node_modules/multiformats/esm/src/bases/base.js
|
|
3244
|
+
var Encoder = class {
|
|
3245
|
+
constructor(name, prefix, baseEncode) {
|
|
3246
|
+
this.name = name;
|
|
3247
|
+
this.prefix = prefix;
|
|
3248
|
+
this.baseEncode = baseEncode;
|
|
3249
|
+
}
|
|
3250
|
+
encode(bytes) {
|
|
3251
|
+
if (bytes instanceof Uint8Array) {
|
|
3252
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
3253
|
+
} else {
|
|
3254
|
+
throw Error("Unknown type, must be binary type");
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
};
|
|
3258
|
+
var Decoder = class {
|
|
3259
|
+
constructor(name, prefix, baseDecode) {
|
|
3260
|
+
this.name = name;
|
|
3261
|
+
this.prefix = prefix;
|
|
3262
|
+
if (prefix.codePointAt(0) === void 0) {
|
|
3263
|
+
throw new Error("Invalid prefix character");
|
|
3264
|
+
}
|
|
3265
|
+
this.prefixCodePoint = prefix.codePointAt(0);
|
|
3266
|
+
this.baseDecode = baseDecode;
|
|
3267
|
+
}
|
|
3268
|
+
decode(text) {
|
|
3269
|
+
if (typeof text === "string") {
|
|
3270
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
3271
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
3272
|
+
}
|
|
3273
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
3274
|
+
} else {
|
|
3275
|
+
throw Error("Can only multibase decode strings");
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
or(decoder) {
|
|
3279
|
+
return or(this, decoder);
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
var ComposedDecoder = class {
|
|
3283
|
+
constructor(decoders) {
|
|
3284
|
+
this.decoders = decoders;
|
|
3285
|
+
}
|
|
3286
|
+
or(decoder) {
|
|
3287
|
+
return or(this, decoder);
|
|
3288
|
+
}
|
|
3289
|
+
decode(input) {
|
|
3290
|
+
const prefix = input[0];
|
|
3291
|
+
const decoder = this.decoders[prefix];
|
|
3292
|
+
if (decoder) {
|
|
3293
|
+
return decoder.decode(input);
|
|
3294
|
+
} else {
|
|
3295
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
};
|
|
3299
|
+
var or = (left, right) => new ComposedDecoder({
|
|
3300
|
+
...left.decoders || { [left.prefix]: left },
|
|
3301
|
+
...right.decoders || { [right.prefix]: right }
|
|
3302
|
+
});
|
|
3303
|
+
var Codec = class {
|
|
3304
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
3305
|
+
this.name = name;
|
|
3306
|
+
this.prefix = prefix;
|
|
3307
|
+
this.baseEncode = baseEncode;
|
|
3308
|
+
this.baseDecode = baseDecode;
|
|
3309
|
+
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
3310
|
+
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
3311
|
+
}
|
|
3312
|
+
encode(input) {
|
|
3313
|
+
return this.encoder.encode(input);
|
|
3314
|
+
}
|
|
3315
|
+
decode(input) {
|
|
3316
|
+
return this.decoder.decode(input);
|
|
3317
|
+
}
|
|
3318
|
+
};
|
|
3319
|
+
var from = ({ name, prefix, encode: encode3, decode: decode5 }) => new Codec(name, prefix, encode3, decode5);
|
|
3320
|
+
var baseX = ({ prefix, name, alphabet }) => {
|
|
3321
|
+
const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
|
|
3322
|
+
return from({
|
|
3323
|
+
prefix,
|
|
3324
|
+
name,
|
|
3325
|
+
encode: encode3,
|
|
3326
|
+
decode: (text) => coerce3(decode5(text))
|
|
3327
|
+
});
|
|
3328
|
+
};
|
|
3329
|
+
var decode4 = (string, alphabet, bitsPerChar, name) => {
|
|
3330
|
+
const codes = {};
|
|
3331
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
3332
|
+
codes[alphabet[i]] = i;
|
|
3333
|
+
}
|
|
3334
|
+
let end = string.length;
|
|
3335
|
+
while (string[end - 1] === "=") {
|
|
3336
|
+
--end;
|
|
3337
|
+
}
|
|
3338
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
3339
|
+
let bits = 0;
|
|
3340
|
+
let buffer = 0;
|
|
3341
|
+
let written = 0;
|
|
3342
|
+
for (let i = 0; i < end; ++i) {
|
|
3343
|
+
const value = codes[string[i]];
|
|
3344
|
+
if (value === void 0) {
|
|
3345
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
3346
|
+
}
|
|
3347
|
+
buffer = buffer << bitsPerChar | value;
|
|
3348
|
+
bits += bitsPerChar;
|
|
3349
|
+
if (bits >= 8) {
|
|
3350
|
+
bits -= 8;
|
|
3351
|
+
out[written++] = 255 & buffer >> bits;
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
if (bits >= bitsPerChar || 255 & buffer << 8 - bits) {
|
|
3355
|
+
throw new SyntaxError("Unexpected end of data");
|
|
3356
|
+
}
|
|
3357
|
+
return out;
|
|
3358
|
+
};
|
|
3359
|
+
var encode2 = (data, alphabet, bitsPerChar) => {
|
|
3360
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
3361
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
3362
|
+
let out = "";
|
|
3363
|
+
let bits = 0;
|
|
3364
|
+
let buffer = 0;
|
|
3365
|
+
for (let i = 0; i < data.length; ++i) {
|
|
3366
|
+
buffer = buffer << 8 | data[i];
|
|
3367
|
+
bits += 8;
|
|
3368
|
+
while (bits > bitsPerChar) {
|
|
3369
|
+
bits -= bitsPerChar;
|
|
3370
|
+
out += alphabet[mask & buffer >> bits];
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
if (bits) {
|
|
3374
|
+
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
3375
|
+
}
|
|
3376
|
+
if (pad) {
|
|
3377
|
+
while (out.length * bitsPerChar & 7) {
|
|
3378
|
+
out += "=";
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
return out;
|
|
3382
|
+
};
|
|
3383
|
+
var rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
|
|
3384
|
+
return from({
|
|
3385
|
+
prefix,
|
|
3386
|
+
name,
|
|
3387
|
+
encode(input) {
|
|
3388
|
+
return encode2(input, alphabet, bitsPerChar);
|
|
3389
|
+
},
|
|
3390
|
+
decode(input) {
|
|
3391
|
+
return decode4(input, alphabet, bitsPerChar, name);
|
|
3392
|
+
}
|
|
3393
|
+
});
|
|
3394
|
+
};
|
|
3395
|
+
|
|
3396
|
+
// ../../node_modules/multiformats/esm/src/bases/base58.js
|
|
3397
|
+
var base58btc = baseX({
|
|
3398
|
+
name: "base58btc",
|
|
3399
|
+
prefix: "z",
|
|
3400
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
3401
|
+
});
|
|
3402
|
+
var base58flickr = baseX({
|
|
3403
|
+
name: "base58flickr",
|
|
3404
|
+
prefix: "Z",
|
|
3405
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
3406
|
+
});
|
|
3407
|
+
|
|
3408
|
+
// ../../node_modules/multiformats/esm/src/bases/base32.js
|
|
3409
|
+
var base32 = rfc4648({
|
|
3410
|
+
prefix: "b",
|
|
3411
|
+
name: "base32",
|
|
3412
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
3413
|
+
bitsPerChar: 5
|
|
3414
|
+
});
|
|
3415
|
+
var base32upper = rfc4648({
|
|
3416
|
+
prefix: "B",
|
|
3417
|
+
name: "base32upper",
|
|
3418
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
3419
|
+
bitsPerChar: 5
|
|
3420
|
+
});
|
|
3421
|
+
var base32pad = rfc4648({
|
|
3422
|
+
prefix: "c",
|
|
3423
|
+
name: "base32pad",
|
|
3424
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
3425
|
+
bitsPerChar: 5
|
|
3426
|
+
});
|
|
3427
|
+
var base32padupper = rfc4648({
|
|
3428
|
+
prefix: "C",
|
|
3429
|
+
name: "base32padupper",
|
|
3430
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
3431
|
+
bitsPerChar: 5
|
|
3432
|
+
});
|
|
3433
|
+
var base32hex = rfc4648({
|
|
3434
|
+
prefix: "v",
|
|
3435
|
+
name: "base32hex",
|
|
3436
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
3437
|
+
bitsPerChar: 5
|
|
3438
|
+
});
|
|
3439
|
+
var base32hexupper = rfc4648({
|
|
3440
|
+
prefix: "V",
|
|
3441
|
+
name: "base32hexupper",
|
|
3442
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
3443
|
+
bitsPerChar: 5
|
|
3444
|
+
});
|
|
3445
|
+
var base32hexpad = rfc4648({
|
|
3446
|
+
prefix: "t",
|
|
3447
|
+
name: "base32hexpad",
|
|
3448
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
3449
|
+
bitsPerChar: 5
|
|
3450
|
+
});
|
|
3451
|
+
var base32hexpadupper = rfc4648({
|
|
3452
|
+
prefix: "T",
|
|
3453
|
+
name: "base32hexpadupper",
|
|
3454
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
3455
|
+
bitsPerChar: 5
|
|
3456
|
+
});
|
|
3457
|
+
var base32z = rfc4648({
|
|
3458
|
+
prefix: "h",
|
|
3459
|
+
name: "base32z",
|
|
3460
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
3461
|
+
bitsPerChar: 5
|
|
3462
|
+
});
|
|
3463
|
+
|
|
3464
|
+
// ../../node_modules/multiformats/esm/src/cid.js
|
|
3465
|
+
var CID = class _CID {
|
|
3466
|
+
constructor(version2, code, multihash, bytes) {
|
|
3467
|
+
this.code = code;
|
|
3468
|
+
this.version = version2;
|
|
3469
|
+
this.multihash = multihash;
|
|
3470
|
+
this.bytes = bytes;
|
|
3471
|
+
this.byteOffset = bytes.byteOffset;
|
|
3472
|
+
this.byteLength = bytes.byteLength;
|
|
3473
|
+
this.asCID = this;
|
|
3474
|
+
this._baseCache = /* @__PURE__ */ new Map();
|
|
3475
|
+
Object.defineProperties(this, {
|
|
3476
|
+
byteOffset: hidden,
|
|
3477
|
+
byteLength: hidden,
|
|
3478
|
+
code: readonly,
|
|
3479
|
+
version: readonly,
|
|
3480
|
+
multihash: readonly,
|
|
3481
|
+
bytes: readonly,
|
|
3482
|
+
_baseCache: hidden,
|
|
3483
|
+
asCID: hidden
|
|
3484
|
+
});
|
|
3485
|
+
}
|
|
3486
|
+
toV0() {
|
|
3487
|
+
switch (this.version) {
|
|
3488
|
+
case 0: {
|
|
3489
|
+
return this;
|
|
3490
|
+
}
|
|
3491
|
+
default: {
|
|
3492
|
+
const { code, multihash } = this;
|
|
3493
|
+
if (code !== DAG_PB_CODE) {
|
|
3494
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
3495
|
+
}
|
|
3496
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
3497
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
3498
|
+
}
|
|
3499
|
+
return _CID.createV0(multihash);
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
toV1() {
|
|
3504
|
+
switch (this.version) {
|
|
3505
|
+
case 0: {
|
|
3506
|
+
const { code, digest } = this.multihash;
|
|
3507
|
+
const multihash = create(code, digest);
|
|
3508
|
+
return _CID.createV1(this.code, multihash);
|
|
3509
|
+
}
|
|
3510
|
+
case 1: {
|
|
3511
|
+
return this;
|
|
3512
|
+
}
|
|
3513
|
+
default: {
|
|
3514
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
equals(other) {
|
|
3519
|
+
return other && this.code === other.code && this.version === other.version && equals2(this.multihash, other.multihash);
|
|
3520
|
+
}
|
|
3521
|
+
toString(base3) {
|
|
3522
|
+
const { bytes, version: version2, _baseCache } = this;
|
|
3523
|
+
switch (version2) {
|
|
3524
|
+
case 0:
|
|
3525
|
+
return toStringV0(bytes, _baseCache, base3 || base58btc.encoder);
|
|
3526
|
+
default:
|
|
3527
|
+
return toStringV1(bytes, _baseCache, base3 || base32.encoder);
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
toJSON() {
|
|
3531
|
+
return {
|
|
3532
|
+
code: this.code,
|
|
3533
|
+
version: this.version,
|
|
3534
|
+
hash: this.multihash.bytes
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3537
|
+
get [Symbol.toStringTag]() {
|
|
3538
|
+
return "CID";
|
|
3539
|
+
}
|
|
3540
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
3541
|
+
return "CID(" + this.toString() + ")";
|
|
3542
|
+
}
|
|
3543
|
+
static isCID(value) {
|
|
3544
|
+
deprecate(/^0\.0/, IS_CID_DEPRECATION);
|
|
3545
|
+
return !!(value && (value[cidSymbol] || value.asCID === value));
|
|
3546
|
+
}
|
|
3547
|
+
get toBaseEncodedString() {
|
|
3548
|
+
throw new Error("Deprecated, use .toString()");
|
|
3549
|
+
}
|
|
3550
|
+
get codec() {
|
|
3551
|
+
throw new Error('"codec" property is deprecated, use integer "code" property instead');
|
|
3552
|
+
}
|
|
3553
|
+
get buffer() {
|
|
3554
|
+
throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead");
|
|
3555
|
+
}
|
|
3556
|
+
get multibaseName() {
|
|
3557
|
+
throw new Error('"multibaseName" property is deprecated');
|
|
3558
|
+
}
|
|
3559
|
+
get prefix() {
|
|
3560
|
+
throw new Error('"prefix" property is deprecated');
|
|
3561
|
+
}
|
|
3562
|
+
static asCID(value) {
|
|
3563
|
+
if (value instanceof _CID) {
|
|
3564
|
+
return value;
|
|
3565
|
+
} else if (value != null && value.asCID === value) {
|
|
3566
|
+
const { version: version2, code, multihash, bytes } = value;
|
|
3567
|
+
return new _CID(version2, code, multihash, bytes || encodeCID(version2, code, multihash.bytes));
|
|
3568
|
+
} else if (value != null && value[cidSymbol] === true) {
|
|
3569
|
+
const { version: version2, multihash, code } = value;
|
|
3570
|
+
const digest = decode3(multihash);
|
|
3571
|
+
return _CID.create(version2, code, digest);
|
|
3572
|
+
} else {
|
|
3573
|
+
return null;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
static create(version2, code, digest) {
|
|
3577
|
+
if (typeof code !== "number") {
|
|
3578
|
+
throw new Error("String codecs are no longer supported");
|
|
3579
|
+
}
|
|
3580
|
+
switch (version2) {
|
|
3581
|
+
case 0: {
|
|
3582
|
+
if (code !== DAG_PB_CODE) {
|
|
3583
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
3584
|
+
} else {
|
|
3585
|
+
return new _CID(version2, code, digest, digest.bytes);
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
case 1: {
|
|
3589
|
+
const bytes = encodeCID(version2, code, digest.bytes);
|
|
3590
|
+
return new _CID(version2, code, digest, bytes);
|
|
3591
|
+
}
|
|
3592
|
+
default: {
|
|
3593
|
+
throw new Error("Invalid version");
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
static createV0(digest) {
|
|
3598
|
+
return _CID.create(0, DAG_PB_CODE, digest);
|
|
3599
|
+
}
|
|
3600
|
+
static createV1(code, digest) {
|
|
3601
|
+
return _CID.create(1, code, digest);
|
|
3602
|
+
}
|
|
3603
|
+
static decode(bytes) {
|
|
3604
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
3605
|
+
if (remainder.length) {
|
|
3606
|
+
throw new Error("Incorrect length");
|
|
3607
|
+
}
|
|
3608
|
+
return cid;
|
|
3609
|
+
}
|
|
3610
|
+
static decodeFirst(bytes) {
|
|
3611
|
+
const specs = _CID.inspectBytes(bytes);
|
|
3612
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
3613
|
+
const multihashBytes = coerce3(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
3614
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
3615
|
+
throw new Error("Incorrect length");
|
|
3616
|
+
}
|
|
3617
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
3618
|
+
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
3619
|
+
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
3620
|
+
return [
|
|
3621
|
+
cid,
|
|
3622
|
+
bytes.subarray(specs.size)
|
|
3623
|
+
];
|
|
3624
|
+
}
|
|
3625
|
+
static inspectBytes(initialBytes) {
|
|
3626
|
+
let offset = 0;
|
|
3627
|
+
const next = () => {
|
|
3628
|
+
const [i, length2] = decode2(initialBytes.subarray(offset));
|
|
3629
|
+
offset += length2;
|
|
3630
|
+
return i;
|
|
3631
|
+
};
|
|
3632
|
+
let version2 = next();
|
|
3633
|
+
let codec = DAG_PB_CODE;
|
|
3634
|
+
if (version2 === 18) {
|
|
3635
|
+
version2 = 0;
|
|
3636
|
+
offset = 0;
|
|
3637
|
+
} else if (version2 === 1) {
|
|
3638
|
+
codec = next();
|
|
3639
|
+
}
|
|
3640
|
+
if (version2 !== 0 && version2 !== 1) {
|
|
3641
|
+
throw new RangeError(`Invalid CID version ${version2}`);
|
|
3642
|
+
}
|
|
3643
|
+
const prefixSize = offset;
|
|
3644
|
+
const multihashCode = next();
|
|
3645
|
+
const digestSize = next();
|
|
3646
|
+
const size = offset + digestSize;
|
|
3647
|
+
const multihashSize = size - prefixSize;
|
|
3648
|
+
return {
|
|
3649
|
+
version: version2,
|
|
3650
|
+
codec,
|
|
3651
|
+
multihashCode,
|
|
3652
|
+
digestSize,
|
|
3653
|
+
multihashSize,
|
|
3654
|
+
size
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
static parse(source, base3) {
|
|
3658
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
3659
|
+
const cid = _CID.decode(bytes);
|
|
3660
|
+
cid._baseCache.set(prefix, source);
|
|
3661
|
+
return cid;
|
|
3662
|
+
}
|
|
3663
|
+
};
|
|
3664
|
+
var parseCIDtoBytes = (source, base3) => {
|
|
3665
|
+
switch (source[0]) {
|
|
3666
|
+
case "Q": {
|
|
3667
|
+
const decoder = base3 || base58btc;
|
|
3668
|
+
return [
|
|
3669
|
+
base58btc.prefix,
|
|
3670
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
3671
|
+
];
|
|
3672
|
+
}
|
|
3673
|
+
case base58btc.prefix: {
|
|
3674
|
+
const decoder = base3 || base58btc;
|
|
3675
|
+
return [
|
|
3676
|
+
base58btc.prefix,
|
|
3677
|
+
decoder.decode(source)
|
|
3678
|
+
];
|
|
3679
|
+
}
|
|
3680
|
+
case base32.prefix: {
|
|
3681
|
+
const decoder = base3 || base32;
|
|
3682
|
+
return [
|
|
3683
|
+
base32.prefix,
|
|
3684
|
+
decoder.decode(source)
|
|
3685
|
+
];
|
|
3686
|
+
}
|
|
3687
|
+
default: {
|
|
3688
|
+
if (base3 == null) {
|
|
3689
|
+
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
3690
|
+
}
|
|
3691
|
+
return [
|
|
3692
|
+
source[0],
|
|
3693
|
+
base3.decode(source)
|
|
3694
|
+
];
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
};
|
|
3698
|
+
var toStringV0 = (bytes, cache, base3) => {
|
|
3699
|
+
const { prefix } = base3;
|
|
3700
|
+
if (prefix !== base58btc.prefix) {
|
|
3701
|
+
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
3702
|
+
}
|
|
3703
|
+
const cid = cache.get(prefix);
|
|
3704
|
+
if (cid == null) {
|
|
3705
|
+
const cid2 = base3.encode(bytes).slice(1);
|
|
3706
|
+
cache.set(prefix, cid2);
|
|
3707
|
+
return cid2;
|
|
3708
|
+
} else {
|
|
3709
|
+
return cid;
|
|
3710
|
+
}
|
|
3711
|
+
};
|
|
3712
|
+
var toStringV1 = (bytes, cache, base3) => {
|
|
3713
|
+
const { prefix } = base3;
|
|
3714
|
+
const cid = cache.get(prefix);
|
|
3715
|
+
if (cid == null) {
|
|
3716
|
+
const cid2 = base3.encode(bytes);
|
|
3717
|
+
cache.set(prefix, cid2);
|
|
3718
|
+
return cid2;
|
|
3719
|
+
} else {
|
|
3720
|
+
return cid;
|
|
3721
|
+
}
|
|
3722
|
+
};
|
|
3723
|
+
var DAG_PB_CODE = 112;
|
|
3724
|
+
var SHA_256_CODE = 18;
|
|
3725
|
+
var encodeCID = (version2, code, multihash) => {
|
|
3726
|
+
const codeOffset = encodingLength(version2);
|
|
3727
|
+
const hashOffset = codeOffset + encodingLength(code);
|
|
3728
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
3729
|
+
encodeTo(version2, bytes, 0);
|
|
3730
|
+
encodeTo(code, bytes, codeOffset);
|
|
3731
|
+
bytes.set(multihash, hashOffset);
|
|
3732
|
+
return bytes;
|
|
3733
|
+
};
|
|
3734
|
+
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
3735
|
+
var readonly = {
|
|
3736
|
+
writable: false,
|
|
3737
|
+
configurable: false,
|
|
3738
|
+
enumerable: true
|
|
3739
|
+
};
|
|
3740
|
+
var hidden = {
|
|
3741
|
+
writable: false,
|
|
3742
|
+
enumerable: false,
|
|
3743
|
+
configurable: false
|
|
3744
|
+
};
|
|
3745
|
+
var version = "0.0.0-dev";
|
|
3746
|
+
var deprecate = (range, message) => {
|
|
3747
|
+
if (range.test(version)) {
|
|
3748
|
+
console.warn(message);
|
|
3749
|
+
} else {
|
|
3750
|
+
throw new Error(message);
|
|
3751
|
+
}
|
|
3752
|
+
};
|
|
3753
|
+
var IS_CID_DEPRECATION = `CID.isCID(v) is deprecated and will be removed in the next major release.
|
|
3754
|
+
Following code pattern:
|
|
3755
|
+
|
|
3756
|
+
if (CID.isCID(value)) {
|
|
3757
|
+
doSomethingWithCID(value)
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3760
|
+
Is replaced with:
|
|
3761
|
+
|
|
3762
|
+
const cid = CID.asCID(value)
|
|
3763
|
+
if (cid) {
|
|
3764
|
+
// Make sure to use cid instead of value
|
|
3765
|
+
doSomethingWithCID(cid)
|
|
3766
|
+
}
|
|
3767
|
+
`;
|
|
3768
|
+
|
|
3769
|
+
// src/ipfs/ipfs.ts
|
|
3770
|
+
function isCID(str) {
|
|
3771
|
+
if (!str)
|
|
3772
|
+
return false;
|
|
3773
|
+
try {
|
|
3774
|
+
CID.parse(str);
|
|
3775
|
+
return true;
|
|
3776
|
+
} catch (e) {
|
|
3777
|
+
if (/^(bafy|Qm)/.test(str))
|
|
3778
|
+
return true;
|
|
3779
|
+
return false;
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
function normalizeIPFSUrl(url) {
|
|
3783
|
+
if (!url || typeof url !== "string")
|
|
3784
|
+
return null;
|
|
3785
|
+
url = url.replace(/"/g, "");
|
|
3786
|
+
if (isNormalizedIPFSURL(url))
|
|
3787
|
+
return url;
|
|
3788
|
+
if (isCID(url))
|
|
3789
|
+
return `ipfs://${url}`;
|
|
3790
|
+
if (!isIPFSUrl(url))
|
|
3791
|
+
return null;
|
|
3792
|
+
if (isGatewayIPFSUrl(url)) {
|
|
3793
|
+
const parsed = new URL(url.replace(/^\/\//, "http://"));
|
|
3794
|
+
parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
|
|
3795
|
+
const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
|
|
3796
|
+
return `ipfs://${cid}`;
|
|
3797
|
+
}
|
|
3798
|
+
return null;
|
|
3799
|
+
}
|
|
3800
|
+
function isNormalizedIPFSURL(url) {
|
|
3801
|
+
return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
|
|
3802
|
+
}
|
|
3803
|
+
function isGatewayIPFSUrl(url) {
|
|
3804
|
+
if (url && typeof url === "string") {
|
|
3805
|
+
try {
|
|
3806
|
+
const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
|
|
3807
|
+
return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
|
|
3808
|
+
} catch {
|
|
3809
|
+
return false;
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
return false;
|
|
3813
|
+
}
|
|
3814
|
+
function isIPFSUrl(url) {
|
|
3815
|
+
return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
|
|
3816
|
+
}
|
|
3817
|
+
function isNormalizeableIPFSUrl(url) {
|
|
3818
|
+
return url ? isIPFSUrl(url) || isCID(url) : false;
|
|
3819
|
+
}
|
|
3820
|
+
|
|
3821
|
+
// src/ipfs/gateway.ts
|
|
3822
|
+
var IPFS_GATEWAY = "https://magic.decentralized-content.com";
|
|
3823
|
+
var ARWEAVE_GATEWAY = "https://arweave.net";
|
|
3824
|
+
function arweaveGatewayUrl(normalizedArweaveUrl) {
|
|
3825
|
+
if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
|
|
3826
|
+
return null;
|
|
3827
|
+
return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
|
|
3828
|
+
}
|
|
3829
|
+
function ipfsGatewayUrl(url) {
|
|
3830
|
+
if (!url || typeof url !== "string")
|
|
3831
|
+
return null;
|
|
3832
|
+
const normalizedIPFSUrl = normalizeIPFSUrl(url);
|
|
3833
|
+
if (normalizedIPFSUrl) {
|
|
3834
|
+
return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
|
|
3835
|
+
}
|
|
3836
|
+
return null;
|
|
3837
|
+
}
|
|
3838
|
+
function getFetchableUrl(uri) {
|
|
3839
|
+
if (!uri || typeof uri !== "string")
|
|
3840
|
+
return null;
|
|
3841
|
+
if (uri.startsWith("http://"))
|
|
3842
|
+
return null;
|
|
3843
|
+
if (isNormalizeableIPFSUrl(uri)) {
|
|
3844
|
+
return ipfsGatewayUrl(uri);
|
|
3845
|
+
}
|
|
3846
|
+
if (isArweaveURL(uri)) {
|
|
3847
|
+
return arweaveGatewayUrl(uri);
|
|
3848
|
+
}
|
|
3849
|
+
if (/^(https|data|blob):/.test(uri)) {
|
|
3850
|
+
return uri;
|
|
3851
|
+
}
|
|
3852
|
+
return null;
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
// src/ipfs/mimeTypes.ts
|
|
3856
|
+
var HTML = "text/html";
|
|
3857
|
+
var MARKDOWN = "text/markdown";
|
|
3858
|
+
var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
|
|
3859
|
+
var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
|
|
3860
|
+
var TEXT_PLAIN = "text/plain";
|
|
3861
|
+
var CSV = "text/csv";
|
|
3862
|
+
var NUMBERS = ".numbers";
|
|
3863
|
+
var EXCEL = ".xlsx";
|
|
3864
|
+
var PDF = "application/pdf";
|
|
3865
|
+
var JPG = "image/jpg";
|
|
3866
|
+
var JPEG = "image/jpeg";
|
|
3867
|
+
var PNG = "image/png";
|
|
3868
|
+
var WEBP = "image/webp";
|
|
3869
|
+
var SVG = "image/svg+xml";
|
|
3870
|
+
var TIFF = "image/tiff";
|
|
3871
|
+
var GIF = "image/gif";
|
|
3872
|
+
var isImage = (mimeType) => {
|
|
3873
|
+
if (!mimeType)
|
|
3874
|
+
return false;
|
|
3875
|
+
return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
|
|
3876
|
+
};
|
|
3877
|
+
var DEFAULT_THUMBNAIL_CID_HASHES = {
|
|
3878
|
+
["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
|
|
3879
|
+
["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
|
|
3880
|
+
["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
|
|
3881
|
+
["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
|
|
3882
|
+
// assuming all zip files are html directories
|
|
3883
|
+
["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
|
|
3884
|
+
default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
|
|
3885
|
+
};
|
|
3886
|
+
var MP4 = "video/mp4";
|
|
3887
|
+
var QUICKTIME = "video/quicktime";
|
|
3888
|
+
var M4V = "video/x-m4v";
|
|
3889
|
+
var WEBM = "video/webm";
|
|
3890
|
+
var M4A = "audio/x-m4a";
|
|
3891
|
+
var MPEG = "audio/mpeg";
|
|
3892
|
+
var MP3 = "audio/mp3";
|
|
3893
|
+
var WAV = "audio/wav";
|
|
3894
|
+
var VND_WAV = "audio/vnd.wav";
|
|
3895
|
+
var VND_WAVE = "audio/vnd.wave";
|
|
3896
|
+
var WAVE = "audio/wave";
|
|
3897
|
+
var X_WAV = "audio/x-wav";
|
|
3898
|
+
var AIFF = "audio/aiff";
|
|
3899
|
+
var GLTF = "model/gltf+json";
|
|
3900
|
+
var GLB = "model/gltf-binary";
|
|
3901
|
+
var GLTF_EXT = ".gltf";
|
|
3902
|
+
var GLB_EXT = ".glb";
|
|
3903
|
+
var JSON_MIME_TYPE = "application/json";
|
|
3904
|
+
var ZIP = "application/zip";
|
|
3905
|
+
var mimeToMediaType = {
|
|
3906
|
+
[HTML]: "HTML" /* HTML */,
|
|
3907
|
+
[JPG]: "IMAGE" /* IMAGE */,
|
|
3908
|
+
[JPEG]: "IMAGE" /* IMAGE */,
|
|
3909
|
+
[PNG]: "IMAGE" /* IMAGE */,
|
|
3910
|
+
[WEBP]: "IMAGE" /* IMAGE */,
|
|
3911
|
+
[SVG]: "IMAGE" /* IMAGE */,
|
|
3912
|
+
[TIFF]: "TIFF" /* TIFF */,
|
|
3913
|
+
[GIF]: "IMAGE" /* IMAGE */,
|
|
3914
|
+
[MP4]: "VIDEO" /* VIDEO */,
|
|
3915
|
+
[WEBM]: "VIDEO" /* VIDEO */,
|
|
3916
|
+
[QUICKTIME]: "VIDEO" /* VIDEO */,
|
|
3917
|
+
[M4V]: "VIDEO" /* VIDEO */,
|
|
3918
|
+
[MPEG]: "AUDIO" /* AUDIO */,
|
|
3919
|
+
[MP3]: "AUDIO" /* AUDIO */,
|
|
3920
|
+
[M4A]: "AUDIO" /* AUDIO */,
|
|
3921
|
+
[VND_WAV]: "AUDIO" /* AUDIO */,
|
|
3922
|
+
[VND_WAVE]: "AUDIO" /* AUDIO */,
|
|
3923
|
+
[WAV]: "AUDIO" /* AUDIO */,
|
|
3924
|
+
[WAVE]: "AUDIO" /* AUDIO */,
|
|
3925
|
+
[X_WAV]: "AUDIO" /* AUDIO */,
|
|
3926
|
+
[AIFF]: "AUDIO" /* AUDIO */,
|
|
3927
|
+
[TEXT_PLAIN]: "TEXT" /* TEXT */,
|
|
3928
|
+
[TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
|
|
3929
|
+
[MARKDOWN]: "TEXT" /* TEXT */,
|
|
3930
|
+
[MARKDOWN_UTF8]: "TEXT" /* TEXT */,
|
|
3931
|
+
[CSV]: "CSV" /* CSV */,
|
|
3932
|
+
[NUMBERS]: "NUMBERS" /* NUMBERS */,
|
|
3933
|
+
[EXCEL]: "EXCEL" /* EXCEL */,
|
|
3934
|
+
[PDF]: "PDF" /* PDF */,
|
|
3935
|
+
[ZIP]: "ZIP" /* ZIP */,
|
|
3936
|
+
[GLTF]: "MODEL" /* MODEL */,
|
|
3937
|
+
[GLTF_EXT]: "MODEL" /* MODEL */,
|
|
3938
|
+
[GLB]: "MODEL" /* MODEL */,
|
|
3939
|
+
// GLTF returns 'application/json' as the mimetype,
|
|
3940
|
+
// and as the only JSON-encoded media we currently support,
|
|
3941
|
+
// we assume that if the mimetype is JSON, it's a GLTF
|
|
3942
|
+
[JSON_MIME_TYPE]: "MODEL" /* MODEL */,
|
|
3943
|
+
[GLB_EXT]: "MODEL" /* MODEL */
|
|
3944
|
+
};
|
|
3945
|
+
function mimeTypeToMedia(mimeType) {
|
|
3946
|
+
if (!mimeType)
|
|
3947
|
+
return "UNKNOWN" /* UNKNOWN */;
|
|
3948
|
+
return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
|
|
3949
|
+
}
|
|
3950
|
+
async function getMimeType(uri) {
|
|
3951
|
+
if (!uri)
|
|
3952
|
+
return uri;
|
|
3953
|
+
const res = await fetch(uri, { method: "HEAD" });
|
|
3954
|
+
let mimeType = res.headers.get("content-type");
|
|
3955
|
+
return mimeType;
|
|
3956
|
+
}
|
|
3957
|
+
|
|
3958
|
+
// src/ipfs/token-metadata.ts
|
|
3959
|
+
var makeTextTokenMetadata = (parameters) => {
|
|
3960
|
+
const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
|
|
3961
|
+
const content = textFileUrl ? {
|
|
3962
|
+
mime: TEXT_PLAIN,
|
|
3963
|
+
uri: textFileUrl
|
|
3964
|
+
} : null;
|
|
3965
|
+
const image = thumbnailUrl;
|
|
3966
|
+
const animation_url = textFileUrl;
|
|
3967
|
+
return {
|
|
3968
|
+
name,
|
|
3969
|
+
image,
|
|
3970
|
+
animation_url,
|
|
3971
|
+
content,
|
|
3972
|
+
attributes
|
|
3973
|
+
};
|
|
3974
|
+
};
|
|
3975
|
+
var makeMediaTokenMetadata = async ({
|
|
3976
|
+
name,
|
|
3977
|
+
description,
|
|
3978
|
+
attributes = [],
|
|
3979
|
+
mediaUrl,
|
|
3980
|
+
thumbnailUrl
|
|
3981
|
+
}) => {
|
|
3982
|
+
const contentUrl = mediaUrl;
|
|
3983
|
+
const fetchableContentUrl = getFetchableUrl(contentUrl);
|
|
3984
|
+
if (!fetchableContentUrl)
|
|
3985
|
+
throw new Error(`Content url (${contentUrl}) is not fetchable`);
|
|
3986
|
+
const mimeType = await getMimeType(fetchableContentUrl);
|
|
3987
|
+
const mediaType = mimeTypeToMedia(mimeType);
|
|
3988
|
+
let image = void 0;
|
|
3989
|
+
let animation_url = null;
|
|
3990
|
+
if (isImage(mimeType)) {
|
|
3991
|
+
image = contentUrl;
|
|
3992
|
+
} else {
|
|
3993
|
+
image = thumbnailUrl;
|
|
3994
|
+
animation_url = mediaUrl;
|
|
3995
|
+
}
|
|
3996
|
+
if (!image)
|
|
3997
|
+
image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
|
|
3998
|
+
const content = contentUrl ? {
|
|
3999
|
+
mime: mimeType || "application/octet-stream",
|
|
4000
|
+
uri: contentUrl
|
|
4001
|
+
} : null;
|
|
4002
|
+
return {
|
|
4003
|
+
name,
|
|
4004
|
+
description,
|
|
4005
|
+
image,
|
|
4006
|
+
animation_url,
|
|
4007
|
+
content,
|
|
4008
|
+
attributes
|
|
4009
|
+
};
|
|
4010
|
+
};
|
|
4011
|
+
|
|
4012
|
+
// src/ipfs/text-metadata.ts
|
|
4013
|
+
var CHAR_LIMIT = 1111;
|
|
4014
|
+
var wrapText = ({
|
|
4015
|
+
ctx,
|
|
4016
|
+
text,
|
|
4017
|
+
x,
|
|
4018
|
+
y,
|
|
4019
|
+
maxWidth,
|
|
4020
|
+
lineHeight
|
|
4021
|
+
}) => {
|
|
4022
|
+
let words = text.replaceAll("\n", " \n ").split(/ +/);
|
|
4023
|
+
let line = "";
|
|
4024
|
+
let testLine = "";
|
|
4025
|
+
let lineArray = [];
|
|
4026
|
+
for (var n = 0; n < words.length; n++) {
|
|
4027
|
+
testLine += `${words[n]} `;
|
|
4028
|
+
let metrics = ctx.measureText(testLine);
|
|
4029
|
+
let testWidth = metrics.width;
|
|
4030
|
+
if (words[n]?.includes("\n") || testWidth > maxWidth && n > 0) {
|
|
4031
|
+
lineArray.push({ text: line, x, y });
|
|
4032
|
+
y += lineHeight;
|
|
4033
|
+
if (words[n]?.includes("\n")) {
|
|
4034
|
+
line = ``;
|
|
4035
|
+
testLine = ``;
|
|
4036
|
+
} else {
|
|
4037
|
+
line = `${words[n]} `;
|
|
4038
|
+
testLine = `${words[n]} `;
|
|
4039
|
+
}
|
|
4040
|
+
} else {
|
|
4041
|
+
line += `${words[n]} `;
|
|
4042
|
+
}
|
|
4043
|
+
if (n === words.length - 1) {
|
|
4044
|
+
lineArray.push({ text: line, x, y });
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
return lineArray;
|
|
4048
|
+
};
|
|
4049
|
+
async function generateTextPreview(text) {
|
|
4050
|
+
const trimmedText = text.trim().slice(0, CHAR_LIMIT);
|
|
4051
|
+
const [width, height] = [500, 500];
|
|
4052
|
+
const padding = 20;
|
|
4053
|
+
const dpr = 2;
|
|
4054
|
+
const fontFamily = "Inter";
|
|
4055
|
+
const [fontSize, lineHeight] = [16, 24];
|
|
4056
|
+
const [textColor, backgroundColor] = ["black", "white"];
|
|
4057
|
+
return new Promise((resolve, reject) => {
|
|
4058
|
+
const canvas = document.createElement("canvas");
|
|
4059
|
+
canvas.width = width * dpr;
|
|
4060
|
+
canvas.height = height * dpr;
|
|
4061
|
+
const ctx = canvas.getContext("2d");
|
|
4062
|
+
if (!ctx) {
|
|
4063
|
+
return reject(new Error("Could not create canvas context"));
|
|
4064
|
+
}
|
|
4065
|
+
ctx.fillStyle = backgroundColor;
|
|
4066
|
+
ctx.fillRect(0, 0, width * dpr, width * dpr);
|
|
4067
|
+
ctx.fillStyle = textColor;
|
|
4068
|
+
ctx.font = `${fontSize * dpr}px ${fontFamily}`;
|
|
4069
|
+
const wrapped = wrapText({
|
|
4070
|
+
ctx,
|
|
4071
|
+
text: trimmedText,
|
|
4072
|
+
x: padding * dpr,
|
|
4073
|
+
y: fontSize * dpr + padding * dpr,
|
|
4074
|
+
maxWidth: width * dpr - padding * 2 * dpr,
|
|
4075
|
+
lineHeight: lineHeight * dpr
|
|
4076
|
+
});
|
|
4077
|
+
wrapped.forEach((line) => ctx.fillText(line.text, line.x, line.y));
|
|
4078
|
+
canvas.toBlob((blob) => {
|
|
4079
|
+
if (!blob) {
|
|
4080
|
+
return reject(new Error("Could not create blob"));
|
|
4081
|
+
}
|
|
4082
|
+
resolve(new File([blob], "thumbnail.png", { type: "image/png" }));
|
|
4083
|
+
});
|
|
4084
|
+
});
|
|
4085
|
+
}
|
|
4086
|
+
function generateTextTitle(text) {
|
|
4087
|
+
const firstLine = text.split("\n")[0];
|
|
4088
|
+
const firstSentence = firstLine?.split(". ")[0];
|
|
4089
|
+
if (firstSentence.length > 50) {
|
|
4090
|
+
return firstSentence.slice(0, 50) + "...";
|
|
4091
|
+
}
|
|
4092
|
+
return firstSentence;
|
|
4093
|
+
}
|
|
4094
|
+
var toTextFile = (text) => new File([text], "Untitled.txt", { type: "text/plain" });
|
|
4095
|
+
async function generateTextNftMetadataFiles(text) {
|
|
4096
|
+
const name = generateTextTitle(text);
|
|
4097
|
+
const textFile = toTextFile(text);
|
|
4098
|
+
const thumbnailFile = await generateTextPreview(text);
|
|
4099
|
+
return {
|
|
4100
|
+
name,
|
|
4101
|
+
mediaUrlFile: textFile,
|
|
4102
|
+
thumbnailFile
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
2513
4105
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2514
4106
|
0 && (module.exports = {
|
|
2515
4107
|
Create1155Client,
|
|
@@ -2521,12 +4113,14 @@ function createCollectorClient(params) {
|
|
|
2521
4113
|
SubgraphMintGetter,
|
|
2522
4114
|
ZORA_API_BASE,
|
|
2523
4115
|
applyUpdateToPremint,
|
|
4116
|
+
buildPremintMintCall,
|
|
2524
4117
|
collectOnchain,
|
|
2525
4118
|
collectPremint,
|
|
2526
4119
|
collectPremintV2WithMintsParams,
|
|
2527
4120
|
collectWithMintsParams,
|
|
2528
4121
|
convertCollectionFromApi,
|
|
2529
4122
|
convertGetPremintApiResponse,
|
|
4123
|
+
convertGetPremintOfCollectionApiResponse,
|
|
2530
4124
|
convertPremintFromApi,
|
|
2531
4125
|
createCollectorClient,
|
|
2532
4126
|
createCreatorClient,
|
|
@@ -2538,13 +4132,12 @@ function createCollectorClient(params) {
|
|
|
2538
4132
|
encodeCollectOnManager,
|
|
2539
4133
|
encodePostSignatureInput,
|
|
2540
4134
|
encodePremintForAPI,
|
|
4135
|
+
generateTextNftMetadataFiles,
|
|
2541
4136
|
getApiNetworkConfigForChain,
|
|
2542
4137
|
getDataFromPremintReceipt,
|
|
2543
4138
|
getDefaultFixedPriceMinterAddress,
|
|
2544
|
-
getMintCosts,
|
|
2545
4139
|
getMintsAccountBalanceWithPriceQuery,
|
|
2546
4140
|
getMintsEthPrice,
|
|
2547
|
-
getNecessaryErc20Approval,
|
|
2548
4141
|
getPremintCollectionAddress,
|
|
2549
4142
|
getPremintExecutorAddress,
|
|
2550
4143
|
getPremintMintCosts,
|
|
@@ -2559,20 +4152,19 @@ function createCollectorClient(params) {
|
|
|
2559
4152
|
isPremintConfigV2,
|
|
2560
4153
|
isValidSignature,
|
|
2561
4154
|
makeCallWithEthSafeTransferData,
|
|
4155
|
+
makeMediaTokenMetadata,
|
|
2562
4156
|
makeMintRewardsRecipient,
|
|
2563
4157
|
makeNewPremint,
|
|
2564
4158
|
makePermitToCollectPremintOrNonPremint,
|
|
2565
4159
|
makePermitTransferBatchAndTypeData,
|
|
2566
4160
|
makePermitTransferTypeData,
|
|
2567
|
-
|
|
4161
|
+
makeTextTokenMetadata,
|
|
2568
4162
|
makeUrls,
|
|
2569
4163
|
migratePremintConfigToV2,
|
|
2570
4164
|
mintWithEthParams,
|
|
2571
4165
|
mintsBalanceOfAccountParams,
|
|
2572
|
-
parseMintCosts,
|
|
2573
4166
|
recoverCreatorFromCreatorAttribution,
|
|
2574
4167
|
recoverPremintSigner,
|
|
2575
|
-
requestErc20ApprovalForMint,
|
|
2576
4168
|
selectMintsToCollectWithFromQueryResult,
|
|
2577
4169
|
sumBalances,
|
|
2578
4170
|
supportedPremintVersions,
|