@zoralabs/protocol-sdk 0.8.0 → 0.9.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 +7 -7
- package/CHANGELOG.md +17 -0
- package/dist/allow-list/allow-list-client.d.ts +26 -0
- package/dist/allow-list/allow-list-client.d.ts.map +1 -0
- package/dist/allow-list/types.d.ts +14 -0
- package/dist/allow-list/types.d.ts.map +1 -0
- package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
- package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/apis/subgraph-querier.d.ts +18 -0
- package/dist/apis/subgraph-querier.d.ts.map +1 -0
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/contract-setup.d.ts +1 -0
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/mint-from-create.d.ts +12 -0
- package/dist/create/mint-from-create.d.ts.map +1 -0
- package/dist/create/minter-defaults.d.ts +5 -0
- package/dist/create/minter-defaults.d.ts.map +1 -0
- package/dist/create/minter-setup.d.ts +14 -0
- package/dist/create/minter-setup.d.ts.map +1 -0
- package/dist/create/token-setup.d.ts +4 -19
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/create/types.d.ts +34 -7
- package/dist/create/types.d.ts.map +1 -1
- package/dist/create/update.d.ts +15 -0
- package/dist/create/update.d.ts.map +1 -0
- package/dist/index.cjs +2359 -1932
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2379 -1947
- package/dist/index.js.map +1 -1
- package/dist/ipfs/token-metadata.d.ts +1 -0
- package/dist/ipfs/token-metadata.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +2 -6
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +6 -2
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +9 -7
- package/dist/mint/mint-transactions.d.ts.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +5 -4
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +42 -15
- package/dist/mint/subgraph-queries.d.ts.map +1 -1
- package/dist/mint/types.d.ts +33 -13
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/sparks/sparks-contracts.d.ts +96 -96
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -8
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/allow-list/allow-list-client.ts +105 -0
- package/src/allow-list/types.ts +15 -0
- package/src/apis/generated/allow-list-api-types.ts +288 -0
- package/src/apis/http-api-base.ts +12 -0
- package/src/apis/subgraph-querier.ts +38 -0
- package/src/create/1155-create-helper.test.ts +217 -89
- package/src/create/1155-create-helper.ts +25 -4
- package/src/create/contract-setup.ts +8 -0
- package/src/create/mint-from-create.ts +119 -0
- package/src/create/minter-defaults.test.ts +21 -0
- package/src/create/minter-defaults.ts +134 -0
- package/src/create/minter-setup.ts +293 -0
- package/src/create/token-setup.ts +14 -190
- package/src/create/types.ts +58 -9
- package/src/create/update.ts +93 -0
- package/src/index.ts +4 -0
- package/src/ipfs/token-metadata.ts +18 -0
- package/src/mint/mint-client.test.ts +219 -15
- package/src/mint/mint-client.ts +2 -34
- package/src/mint/mint-queries.ts +40 -19
- package/src/mint/mint-transactions.ts +104 -17
- package/src/mint/subgraph-mint-getter.ts +107 -50
- package/src/mint/subgraph-queries.ts +67 -37
- package/src/mint/types.ts +58 -16
- package/src/premint/premint-client.test.ts +6 -5
- package/src/types.ts +1 -1
- package/src/utils.ts +1 -25
package/dist/index.cjs
CHANGED
|
@@ -716,8 +716,8 @@ var require_gte = __commonJS({
|
|
|
716
716
|
"../../node_modules/.pnpm/semver@7.6.3/node_modules/semver/functions/gte.js"(exports2, module2) {
|
|
717
717
|
"use strict";
|
|
718
718
|
var compare = require_compare();
|
|
719
|
-
var
|
|
720
|
-
module2.exports =
|
|
719
|
+
var gte3 = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
720
|
+
module2.exports = gte3;
|
|
721
721
|
}
|
|
722
722
|
});
|
|
723
723
|
|
|
@@ -738,7 +738,7 @@ var require_cmp = __commonJS({
|
|
|
738
738
|
var eq = require_eq();
|
|
739
739
|
var neq = require_neq();
|
|
740
740
|
var gt = require_gt();
|
|
741
|
-
var
|
|
741
|
+
var gte3 = require_gte();
|
|
742
742
|
var lt = require_lt();
|
|
743
743
|
var lte = require_lte();
|
|
744
744
|
var cmp = (a, op, b, loose) => {
|
|
@@ -768,7 +768,7 @@ var require_cmp = __commonJS({
|
|
|
768
768
|
case ">":
|
|
769
769
|
return gt(a, b, loose);
|
|
770
770
|
case ">=":
|
|
771
|
-
return
|
|
771
|
+
return gte3(a, b, loose);
|
|
772
772
|
case "<":
|
|
773
773
|
return lt(a, b, loose);
|
|
774
774
|
case "<=":
|
|
@@ -788,7 +788,7 @@ var require_coerce = __commonJS({
|
|
|
788
788
|
var SemVer = require_semver();
|
|
789
789
|
var parse = require_parse();
|
|
790
790
|
var { safeRe: re, t } = require_re();
|
|
791
|
-
var
|
|
791
|
+
var coerce4 = (version, options) => {
|
|
792
792
|
if (version instanceof SemVer) {
|
|
793
793
|
return version;
|
|
794
794
|
}
|
|
@@ -823,7 +823,7 @@ var require_coerce = __commonJS({
|
|
|
823
823
|
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
824
824
|
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
825
825
|
};
|
|
826
|
-
module2.exports =
|
|
826
|
+
module2.exports = coerce4;
|
|
827
827
|
}
|
|
828
828
|
});
|
|
829
829
|
|
|
@@ -1524,7 +1524,7 @@ var require_outside = __commonJS({
|
|
|
1524
1524
|
var gt = require_gt();
|
|
1525
1525
|
var lt = require_lt();
|
|
1526
1526
|
var lte = require_lte();
|
|
1527
|
-
var
|
|
1527
|
+
var gte3 = require_gte();
|
|
1528
1528
|
var outside = (version, range, hilo, options) => {
|
|
1529
1529
|
version = new SemVer(version, options);
|
|
1530
1530
|
range = new Range(range, options);
|
|
@@ -1539,7 +1539,7 @@ var require_outside = __commonJS({
|
|
|
1539
1539
|
break;
|
|
1540
1540
|
case "<":
|
|
1541
1541
|
gtfn = lt;
|
|
1542
|
-
ltefn =
|
|
1542
|
+
ltefn = gte3;
|
|
1543
1543
|
ltfn = gt;
|
|
1544
1544
|
comp = "<";
|
|
1545
1545
|
ecomp = "<=";
|
|
@@ -1855,10 +1855,10 @@ var require_semver2 = __commonJS({
|
|
|
1855
1855
|
var lt = require_lt();
|
|
1856
1856
|
var eq = require_eq();
|
|
1857
1857
|
var neq = require_neq();
|
|
1858
|
-
var
|
|
1858
|
+
var gte3 = require_gte();
|
|
1859
1859
|
var lte = require_lte();
|
|
1860
1860
|
var cmp = require_cmp();
|
|
1861
|
-
var
|
|
1861
|
+
var coerce4 = require_coerce();
|
|
1862
1862
|
var Comparator = require_comparator();
|
|
1863
1863
|
var Range = require_range();
|
|
1864
1864
|
var satisfies = require_satisfies();
|
|
@@ -1893,10 +1893,10 @@ var require_semver2 = __commonJS({
|
|
|
1893
1893
|
lt,
|
|
1894
1894
|
eq,
|
|
1895
1895
|
neq,
|
|
1896
|
-
gte:
|
|
1896
|
+
gte: gte3,
|
|
1897
1897
|
lte,
|
|
1898
1898
|
cmp,
|
|
1899
|
-
coerce:
|
|
1899
|
+
coerce: coerce4,
|
|
1900
1900
|
Comparator,
|
|
1901
1901
|
Range,
|
|
1902
1902
|
satisfies,
|
|
@@ -1936,7 +1936,6 @@ __export(src_exports, {
|
|
|
1936
1936
|
ZORA_API_BASE: () => ZORA_API_BASE,
|
|
1937
1937
|
applyUpdateToPremint: () => applyUpdateToPremint,
|
|
1938
1938
|
buildPremintMintCall: () => buildPremintMintCall,
|
|
1939
|
-
collectOnchain: () => collectOnchain,
|
|
1940
1939
|
collectPremint: () => collectPremint,
|
|
1941
1940
|
collectPremintV2WithMintsParams: () => collectPremintV2WithMintsParams,
|
|
1942
1941
|
collectWithMintsParams: () => collectWithMintsParams,
|
|
@@ -1944,6 +1943,7 @@ __export(src_exports, {
|
|
|
1944
1943
|
convertGetPremintApiResponse: () => convertGetPremintApiResponse,
|
|
1945
1944
|
convertGetPremintOfCollectionApiResponse: () => convertGetPremintOfCollectionApiResponse,
|
|
1946
1945
|
convertPremintFromApi: () => convertPremintFromApi,
|
|
1946
|
+
createAllowList: () => createAllowList,
|
|
1947
1947
|
createCollectorClient: () => createCollectorClient,
|
|
1948
1948
|
createCreatorClient: () => createCreatorClient,
|
|
1949
1949
|
decodeCallFailedError: () => decodeCallFailedError,
|
|
@@ -2582,14 +2582,20 @@ var get = async (url) => {
|
|
|
2582
2582
|
return await response.json();
|
|
2583
2583
|
};
|
|
2584
2584
|
var post = async (url, data) => {
|
|
2585
|
+
const controller = new AbortController();
|
|
2586
|
+
const { signal } = controller;
|
|
2587
|
+
const timeout = 30 * 60 * 1e3;
|
|
2588
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2585
2589
|
const response = await fetch(url, {
|
|
2586
2590
|
method: "POST",
|
|
2587
2591
|
headers: {
|
|
2588
2592
|
"content-type": "application/json",
|
|
2589
2593
|
accept: "application/json"
|
|
2590
2594
|
},
|
|
2591
|
-
body: JSON.stringify(data)
|
|
2595
|
+
body: JSON.stringify(data),
|
|
2596
|
+
signal
|
|
2592
2597
|
});
|
|
2598
|
+
clearTimeout(timeoutId);
|
|
2593
2599
|
if (response.status !== 200) {
|
|
2594
2600
|
let json;
|
|
2595
2601
|
try {
|
|
@@ -2625,36 +2631,26 @@ var httpClient = {
|
|
|
2625
2631
|
retries
|
|
2626
2632
|
};
|
|
2627
2633
|
|
|
2628
|
-
// src/
|
|
2629
|
-
var
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
httpClient: httpClient2,
|
|
2645
|
-
subgraphUrl,
|
|
2646
|
-
query,
|
|
2647
|
-
variables
|
|
2648
|
-
}) {
|
|
2649
|
-
const { retries: retries2, post: post2 } = httpClient2;
|
|
2650
|
-
const result = await retries2(async () => {
|
|
2651
|
-
return await post2(subgraphUrl, {
|
|
2652
|
-
query,
|
|
2653
|
-
variables
|
|
2634
|
+
// src/apis/subgraph-querier.ts
|
|
2635
|
+
var SubgraphQuerier = class {
|
|
2636
|
+
constructor(httpClient2) {
|
|
2637
|
+
this.httpClient = httpClient2;
|
|
2638
|
+
}
|
|
2639
|
+
async query({
|
|
2640
|
+
subgraphUrl,
|
|
2641
|
+
query,
|
|
2642
|
+
variables
|
|
2643
|
+
}) {
|
|
2644
|
+
const { retries: retries2, post: post2 } = this.httpClient;
|
|
2645
|
+
const result = await retries2(async () => {
|
|
2646
|
+
return await post2(subgraphUrl, {
|
|
2647
|
+
query,
|
|
2648
|
+
variables
|
|
2649
|
+
});
|
|
2654
2650
|
});
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
}
|
|
2651
|
+
return result?.data;
|
|
2652
|
+
}
|
|
2653
|
+
};
|
|
2658
2654
|
|
|
2659
2655
|
// src/mint/subgraph-queries.ts
|
|
2660
2656
|
var NFT_SALE_STRATEGY_FRAGMENT = `
|
|
@@ -2675,6 +2671,23 @@ fragment SaleStrategy on SalesStrategyConfig {
|
|
|
2675
2671
|
saleStart
|
|
2676
2672
|
maxTokensPerAddress
|
|
2677
2673
|
}
|
|
2674
|
+
presale {
|
|
2675
|
+
address
|
|
2676
|
+
presaleStart
|
|
2677
|
+
presaleEnd
|
|
2678
|
+
merkleRoot
|
|
2679
|
+
}
|
|
2680
|
+
zoraTimedMinter {
|
|
2681
|
+
address
|
|
2682
|
+
mintFee
|
|
2683
|
+
saleStart
|
|
2684
|
+
saleEnd
|
|
2685
|
+
erc20Z {
|
|
2686
|
+
id
|
|
2687
|
+
pool
|
|
2688
|
+
}
|
|
2689
|
+
secondaryActivated
|
|
2690
|
+
}
|
|
2678
2691
|
}`;
|
|
2679
2692
|
var TOKEN_FRAGMENT = `
|
|
2680
2693
|
fragment Token on ZoraCreateToken {
|
|
@@ -2684,7 +2697,7 @@ fragment Token on ZoraCreateToken {
|
|
|
2684
2697
|
totalMinted
|
|
2685
2698
|
maxSupply
|
|
2686
2699
|
tokenStandard
|
|
2687
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
2700
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
2688
2701
|
...SaleStrategy
|
|
2689
2702
|
}
|
|
2690
2703
|
contract {
|
|
@@ -2693,7 +2706,7 @@ fragment Token on ZoraCreateToken {
|
|
|
2693
2706
|
contractVersion
|
|
2694
2707
|
contractURI
|
|
2695
2708
|
name
|
|
2696
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
2709
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
2697
2710
|
...SaleStrategy
|
|
2698
2711
|
}
|
|
2699
2712
|
}
|
|
@@ -2724,19 +2737,6 @@ query ($id: ID!) {
|
|
|
2724
2737
|
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
2725
2738
|
};
|
|
2726
2739
|
}
|
|
2727
|
-
function buildGetDefaultMintPriceQuery({}) {
|
|
2728
|
-
return {
|
|
2729
|
-
query: `
|
|
2730
|
-
{
|
|
2731
|
-
defaultMintPrice(id: "0x0000000000000000000000000000000000000000") {
|
|
2732
|
-
pricePerToken
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
`,
|
|
2736
|
-
variables: {},
|
|
2737
|
-
parseResponseData: (responseData) => responseData?.defaultMintPrice?.pricePerToken ? BigInt(responseData?.defaultMintPrice?.pricePerToken) : void 0
|
|
2738
|
-
};
|
|
2739
|
-
}
|
|
2740
2740
|
function buildContractTokensQuery({
|
|
2741
2741
|
tokenAddress
|
|
2742
2742
|
}) {
|
|
@@ -2777,14 +2777,13 @@ function buildPremintsOfContractQuery({
|
|
|
2777
2777
|
}
|
|
2778
2778
|
|
|
2779
2779
|
// src/mint/subgraph-mint-getter.ts
|
|
2780
|
-
var semver = __toESM(require_semver2(), 1);
|
|
2781
2780
|
var getApiNetworkConfigForChain = (chainId) => {
|
|
2782
2781
|
if (!networkConfigByChain[chainId]) {
|
|
2783
2782
|
throw new Error(`chain id ${chainId} network not configured `);
|
|
2784
2783
|
}
|
|
2785
2784
|
return networkConfigByChain[chainId];
|
|
2786
2785
|
};
|
|
2787
|
-
function parseSalesConfig(targetStrategy) {
|
|
2786
|
+
function parseSalesConfig(targetStrategy, contractMintFee) {
|
|
2788
2787
|
if (targetStrategy.type === "FIXED_PRICE")
|
|
2789
2788
|
return {
|
|
2790
2789
|
saleType: "fixedPrice",
|
|
@@ -2792,7 +2791,8 @@ function parseSalesConfig(targetStrategy) {
|
|
|
2792
2791
|
maxTokensPerAddress: BigInt(
|
|
2793
2792
|
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
2794
2793
|
),
|
|
2795
|
-
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
|
|
2794
|
+
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken),
|
|
2795
|
+
mintFeePerQuantity: contractMintFee
|
|
2796
2796
|
};
|
|
2797
2797
|
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
2798
2798
|
return {
|
|
@@ -2801,31 +2801,72 @@ function parseSalesConfig(targetStrategy) {
|
|
|
2801
2801
|
maxTokensPerAddress: BigInt(
|
|
2802
2802
|
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
2803
2803
|
),
|
|
2804
|
-
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
|
|
2804
|
+
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
|
|
2805
|
+
mintFeePerQuantity: 0n
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
if (targetStrategy.type === "PRESALE") {
|
|
2809
|
+
return {
|
|
2810
|
+
saleType: "allowlist",
|
|
2811
|
+
address: targetStrategy.presale.address,
|
|
2812
|
+
merkleRoot: targetStrategy.presale.merkleRoot,
|
|
2813
|
+
saleStart: targetStrategy.presale.presaleStart,
|
|
2814
|
+
saleEnd: targetStrategy.presale.presaleEnd,
|
|
2815
|
+
mintFeePerQuantity: contractMintFee
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2818
|
+
if (targetStrategy.type === "ZORA_TIMED") {
|
|
2819
|
+
return {
|
|
2820
|
+
saleType: "timed",
|
|
2821
|
+
address: targetStrategy.zoraTimedMinter.address,
|
|
2822
|
+
mintFee: BigInt(targetStrategy.zoraTimedMinter.mintFee),
|
|
2823
|
+
saleStart: targetStrategy.zoraTimedMinter.saleStart,
|
|
2824
|
+
saleEnd: targetStrategy.zoraTimedMinter.saleEnd,
|
|
2825
|
+
erc20Z: targetStrategy.zoraTimedMinter.erc20Z.id,
|
|
2826
|
+
pool: targetStrategy.zoraTimedMinter.erc20Z.pool,
|
|
2827
|
+
secondaryActivated: targetStrategy.zoraTimedMinter.secondaryActivated,
|
|
2828
|
+
mintFeePerQuantity: BigInt(targetStrategy.zoraTimedMinter.mintFee)
|
|
2805
2829
|
};
|
|
2806
2830
|
}
|
|
2807
2831
|
throw new Error("Unknown saleType");
|
|
2808
2832
|
}
|
|
2809
2833
|
function getSaleEnd(a) {
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
)
|
|
2834
|
+
if (a.type === "FIXED_PRICE")
|
|
2835
|
+
return BigInt(a.fixedPrice.saleEnd);
|
|
2836
|
+
if (a.type === "ERC_20_MINTER")
|
|
2837
|
+
return BigInt(a.erc20Minter.saleEnd);
|
|
2838
|
+
if (a.type === "ZORA_TIMED")
|
|
2839
|
+
return BigInt(a.zoraTimedMinter.saleEnd);
|
|
2840
|
+
return BigInt(a.presale.presaleEnd);
|
|
2841
|
+
}
|
|
2842
|
+
function strategyIsStillValid(strategy, blockTime) {
|
|
2843
|
+
if (strategy.type === "FIXED_PRICE") {
|
|
2844
|
+
return BigInt(strategy.fixedPrice.saleEnd) > blockTime;
|
|
2845
|
+
}
|
|
2846
|
+
if (strategy.type === "ERC_20_MINTER") {
|
|
2847
|
+
return BigInt(strategy.erc20Minter.saleEnd) > blockTime;
|
|
2848
|
+
}
|
|
2849
|
+
if (strategy.type === "ZORA_TIMED") {
|
|
2850
|
+
return BigInt(strategy.zoraTimedMinter.saleEnd) > blockTime;
|
|
2851
|
+
}
|
|
2852
|
+
return BigInt(strategy.presale.presaleEnd) > blockTime;
|
|
2813
2853
|
}
|
|
2814
2854
|
function getTargetStrategy({
|
|
2815
2855
|
tokenId,
|
|
2816
2856
|
preferredSaleType,
|
|
2817
|
-
token
|
|
2857
|
+
token,
|
|
2858
|
+
blockTime
|
|
2818
2859
|
}) {
|
|
2819
2860
|
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
2820
|
-
const
|
|
2861
|
+
const stillValidSalesStrategies = allStrategies.filter(
|
|
2862
|
+
(strategy) => strategyIsStillValid(strategy, blockTime)
|
|
2863
|
+
);
|
|
2864
|
+
const saleStrategies = stillValidSalesStrategies.sort(
|
|
2821
2865
|
(a, b) => getSaleEnd(a) > getSaleEnd(b) ? 1 : -1
|
|
2822
2866
|
);
|
|
2823
2867
|
let targetStrategy;
|
|
2824
2868
|
if (!preferredSaleType) {
|
|
2825
|
-
|
|
2826
|
-
if (!targetStrategy) {
|
|
2827
|
-
throw new Error("Cannot find sale strategy");
|
|
2828
|
-
}
|
|
2869
|
+
return saleStrategies[0];
|
|
2829
2870
|
} else {
|
|
2830
2871
|
const mappedSaleType = preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
2831
2872
|
targetStrategy = saleStrategies.find(
|
|
@@ -2843,11 +2884,12 @@ function getTargetStrategy({
|
|
|
2843
2884
|
return targetStrategy;
|
|
2844
2885
|
}
|
|
2845
2886
|
var SubgraphMintGetter = class {
|
|
2846
|
-
constructor(chainId,
|
|
2887
|
+
constructor(chainId, subgraphQuerier) {
|
|
2847
2888
|
this.getMintable = async ({
|
|
2848
2889
|
tokenAddress,
|
|
2849
2890
|
tokenId,
|
|
2850
|
-
preferredSaleType: saleType
|
|
2891
|
+
preferredSaleType: saleType,
|
|
2892
|
+
blockTime
|
|
2851
2893
|
}) => {
|
|
2852
2894
|
const token = await this.querySubgraphWithRetries(
|
|
2853
2895
|
buildNftTokenSalesQuery({
|
|
@@ -2863,29 +2905,22 @@ var SubgraphMintGetter = class {
|
|
|
2863
2905
|
token,
|
|
2864
2906
|
defaultMintFee,
|
|
2865
2907
|
tokenId,
|
|
2866
|
-
preferredSaleType: saleType
|
|
2908
|
+
preferredSaleType: saleType,
|
|
2909
|
+
blockTime
|
|
2867
2910
|
});
|
|
2868
2911
|
};
|
|
2869
|
-
this.
|
|
2912
|
+
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
2870
2913
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
2871
2914
|
}
|
|
2872
2915
|
async getContractMintFee(contract) {
|
|
2873
|
-
|
|
2874
|
-
if (!contractUsesMintCardsForMintFee(contract.contractVersion)) {
|
|
2875
|
-
return storedMintFee;
|
|
2876
|
-
}
|
|
2877
|
-
const defaultMintFee = await this.querySubgraphWithRetries(
|
|
2878
|
-
buildGetDefaultMintPriceQuery({})
|
|
2879
|
-
);
|
|
2880
|
-
return defaultMintFee || storedMintFee;
|
|
2916
|
+
return BigInt(contract.mintFeePerQuantity);
|
|
2881
2917
|
}
|
|
2882
2918
|
async querySubgraphWithRetries({
|
|
2883
2919
|
query,
|
|
2884
2920
|
variables,
|
|
2885
2921
|
parseResponseData
|
|
2886
2922
|
}) {
|
|
2887
|
-
const responseData = await
|
|
2888
|
-
httpClient: this.httpClient,
|
|
2923
|
+
const responseData = await this.subgraphQuerier.query({
|
|
2889
2924
|
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
2890
2925
|
query,
|
|
2891
2926
|
variables
|
|
@@ -2894,7 +2929,8 @@ var SubgraphMintGetter = class {
|
|
|
2894
2929
|
}
|
|
2895
2930
|
async getContractMintable({
|
|
2896
2931
|
tokenAddress,
|
|
2897
|
-
preferredSaleType
|
|
2932
|
+
preferredSaleType,
|
|
2933
|
+
blockTime
|
|
2898
2934
|
}) {
|
|
2899
2935
|
const tokens = await this.querySubgraphWithRetries(
|
|
2900
2936
|
buildContractTokensQuery({
|
|
@@ -2909,7 +2945,8 @@ var SubgraphMintGetter = class {
|
|
|
2909
2945
|
token,
|
|
2910
2946
|
tokenId: token.tokenId,
|
|
2911
2947
|
preferredSaleType,
|
|
2912
|
-
defaultMintFee
|
|
2948
|
+
defaultMintFee,
|
|
2949
|
+
blockTime
|
|
2913
2950
|
})
|
|
2914
2951
|
);
|
|
2915
2952
|
}
|
|
@@ -2927,34 +2964,49 @@ var SubgraphMintGetter = class {
|
|
|
2927
2964
|
})) || [];
|
|
2928
2965
|
}
|
|
2929
2966
|
};
|
|
2930
|
-
function
|
|
2967
|
+
function getTargetStrategyAndMintFee({
|
|
2931
2968
|
token,
|
|
2932
2969
|
tokenId,
|
|
2933
2970
|
preferredSaleType,
|
|
2934
|
-
defaultMintFee
|
|
2971
|
+
defaultMintFee,
|
|
2972
|
+
blockTime
|
|
2935
2973
|
}) {
|
|
2936
2974
|
const targetStrategy = getTargetStrategy({
|
|
2937
2975
|
tokenId,
|
|
2938
2976
|
preferredSaleType,
|
|
2977
|
+
token,
|
|
2978
|
+
blockTime
|
|
2979
|
+
});
|
|
2980
|
+
if (!targetStrategy)
|
|
2981
|
+
return void 0;
|
|
2982
|
+
const salesConfig = parseSalesConfig(targetStrategy, defaultMintFee);
|
|
2983
|
+
return salesConfig;
|
|
2984
|
+
}
|
|
2985
|
+
function parseTokenQueryResult({
|
|
2986
|
+
token,
|
|
2987
|
+
tokenId,
|
|
2988
|
+
preferredSaleType,
|
|
2989
|
+
defaultMintFee,
|
|
2990
|
+
blockTime
|
|
2991
|
+
}) {
|
|
2992
|
+
const salesConfig = getTargetStrategyAndMintFee({
|
|
2993
|
+
token,
|
|
2994
|
+
tokenId,
|
|
2995
|
+
preferredSaleType,
|
|
2996
|
+
defaultMintFee,
|
|
2997
|
+
blockTime
|
|
2998
|
+
});
|
|
2999
|
+
const tokenInfo = parseTokenInfo({
|
|
2939
3000
|
token
|
|
2940
3001
|
});
|
|
2941
|
-
const tokenInfo = parseTokenInfo(token, defaultMintFee);
|
|
2942
|
-
const salesConfig = parseSalesConfig(targetStrategy);
|
|
2943
|
-
if (isErc20SaleStrategy(salesConfig)) {
|
|
2944
|
-
tokenInfo.mintFeePerQuantity = 0n;
|
|
2945
|
-
}
|
|
2946
3002
|
return {
|
|
2947
3003
|
...tokenInfo,
|
|
2948
3004
|
salesConfig
|
|
2949
3005
|
};
|
|
2950
3006
|
}
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
return false;
|
|
2955
|
-
return semver.gte(semVerContractVersion, "2.9.0");
|
|
2956
|
-
};
|
|
2957
|
-
function parseTokenInfo(token, defaultMintFee) {
|
|
3007
|
+
function parseTokenInfo({
|
|
3008
|
+
token
|
|
3009
|
+
}) {
|
|
2958
3010
|
return {
|
|
2959
3011
|
contract: {
|
|
2960
3012
|
address: token.contract.address,
|
|
@@ -2967,11 +3019,19 @@ function parseTokenInfo(token, defaultMintFee) {
|
|
|
2967
3019
|
creator: token.creator,
|
|
2968
3020
|
totalMinted: BigInt(token.totalMinted),
|
|
2969
3021
|
maxSupply: BigInt(token.maxSupply),
|
|
2970
|
-
mintFeePerQuantity: defaultMintFee,
|
|
2971
3022
|
contractVersion: token.contract.contractVersion
|
|
2972
3023
|
};
|
|
2973
3024
|
}
|
|
2974
3025
|
|
|
3026
|
+
// src/utils.ts
|
|
3027
|
+
var makeContractParameters = (args) => args;
|
|
3028
|
+
function mintRecipientOrAccount({
|
|
3029
|
+
mintRecipient,
|
|
3030
|
+
minterAccount
|
|
3031
|
+
}) {
|
|
3032
|
+
return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
3033
|
+
}
|
|
3034
|
+
|
|
2975
3035
|
// src/premint/premint-client.ts
|
|
2976
3036
|
var defaultTokenConfigV1MintArguments = () => ({
|
|
2977
3037
|
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
@@ -3617,20 +3677,30 @@ var PremintAPIClient = class {
|
|
|
3617
3677
|
}
|
|
3618
3678
|
};
|
|
3619
3679
|
|
|
3680
|
+
// src/mint/types.ts
|
|
3681
|
+
var isOnChainMint = (mint2) => mint2.mintType !== "premint";
|
|
3682
|
+
var is1155Mint = (mint2) => mint2.mintType === "1155";
|
|
3683
|
+
function isErc20SaleStrategy(salesConfig) {
|
|
3684
|
+
return salesConfig.saleType === "erc20";
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
// src/mint/mint-queries.ts
|
|
3688
|
+
var import_viem6 = require("viem");
|
|
3689
|
+
|
|
3620
3690
|
// src/mint/mint-transactions.ts
|
|
3621
3691
|
var import_viem5 = require("viem");
|
|
3622
3692
|
var import_protocol_deployments6 = require("@zoralabs/protocol-deployments");
|
|
3623
3693
|
|
|
3624
3694
|
// src/mint/utils.ts
|
|
3625
|
-
var
|
|
3695
|
+
var semver = __toESM(require_semver2(), 1);
|
|
3626
3696
|
var contractSupportsNewMintFunction = (contractVersion) => {
|
|
3627
3697
|
if (!contractVersion) {
|
|
3628
3698
|
return false;
|
|
3629
3699
|
}
|
|
3630
|
-
const semVerContractVersion =
|
|
3700
|
+
const semVerContractVersion = semver.coerce(contractVersion)?.raw;
|
|
3631
3701
|
if (!semVerContractVersion)
|
|
3632
3702
|
return false;
|
|
3633
|
-
return
|
|
3703
|
+
return semver.gte(semVerContractVersion, "2.9.0");
|
|
3634
3704
|
};
|
|
3635
3705
|
|
|
3636
3706
|
// src/mint/mint-transactions.ts
|
|
@@ -3660,12 +3730,13 @@ function makePrepareMint1155TokenParams({
|
|
|
3660
3730
|
mintComment,
|
|
3661
3731
|
mintReferral,
|
|
3662
3732
|
mintRecipient,
|
|
3663
|
-
quantityToMint
|
|
3733
|
+
quantityToMint,
|
|
3734
|
+
allowListEntry
|
|
3664
3735
|
}) {
|
|
3665
3736
|
const mintQuantity = BigInt(quantityToMint || 1);
|
|
3666
3737
|
const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
|
|
3667
3738
|
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
3668
|
-
if (saleType === "fixedPrice") {
|
|
3739
|
+
if (saleType === "fixedPrice" || saleType === "allowlist") {
|
|
3669
3740
|
return makeEthMintCall({
|
|
3670
3741
|
mintComment,
|
|
3671
3742
|
minterAccount,
|
|
@@ -3674,7 +3745,26 @@ function makePrepareMint1155TokenParams({
|
|
|
3674
3745
|
mintTo,
|
|
3675
3746
|
salesConfigAndTokenInfo,
|
|
3676
3747
|
tokenContract,
|
|
3677
|
-
tokenId
|
|
3748
|
+
tokenId,
|
|
3749
|
+
allowListEntry
|
|
3750
|
+
});
|
|
3751
|
+
}
|
|
3752
|
+
if (saleType === "timed") {
|
|
3753
|
+
return makeContractParameters({
|
|
3754
|
+
abi: import_protocol_deployments6.zoraTimedSaleStrategyABI,
|
|
3755
|
+
functionName: "mint",
|
|
3756
|
+
account: minterAccount,
|
|
3757
|
+
address: salesConfigAndTokenInfo.salesConfig.address,
|
|
3758
|
+
value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
|
|
3759
|
+
/* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
|
|
3760
|
+
args: [
|
|
3761
|
+
mintTo,
|
|
3762
|
+
mintQuantity,
|
|
3763
|
+
tokenContract,
|
|
3764
|
+
BigInt(tokenId),
|
|
3765
|
+
mintReferral || import_viem5.zeroAddress,
|
|
3766
|
+
mintComment || ""
|
|
3767
|
+
]
|
|
3678
3768
|
});
|
|
3679
3769
|
}
|
|
3680
3770
|
if (saleType === "erc20") {
|
|
@@ -3709,9 +3799,9 @@ function makePrepareMint721TokenParams({
|
|
|
3709
3799
|
}) {
|
|
3710
3800
|
const actualQuantityToMint = BigInt(quantityToMint || 1);
|
|
3711
3801
|
const mintValue = parseMintCosts({
|
|
3712
|
-
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
3713
3802
|
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
3714
|
-
quantityToMint: actualQuantityToMint
|
|
3803
|
+
quantityToMint: actualQuantityToMint,
|
|
3804
|
+
allowListEntry: void 0
|
|
3715
3805
|
}).totalCostEth;
|
|
3716
3806
|
return makeContractParameters({
|
|
3717
3807
|
abi: zora721Abi,
|
|
@@ -3727,6 +3817,29 @@ function makePrepareMint721TokenParams({
|
|
|
3727
3817
|
]
|
|
3728
3818
|
});
|
|
3729
3819
|
}
|
|
3820
|
+
function makeFixedPriceMinterArguments({
|
|
3821
|
+
mintTo,
|
|
3822
|
+
mintComment
|
|
3823
|
+
}) {
|
|
3824
|
+
return (0, import_viem5.encodeAbiParameters)((0, import_viem5.parseAbiParameters)("address, string"), [
|
|
3825
|
+
mintTo,
|
|
3826
|
+
mintComment || ""
|
|
3827
|
+
]);
|
|
3828
|
+
}
|
|
3829
|
+
function makeAllowListMinterArguments({
|
|
3830
|
+
mintTo,
|
|
3831
|
+
allowListEntry
|
|
3832
|
+
}) {
|
|
3833
|
+
return (0, import_viem5.encodeAbiParameters)(
|
|
3834
|
+
(0, import_viem5.parseAbiParameters)("address, uint256, uint256, bytes32[]"),
|
|
3835
|
+
[
|
|
3836
|
+
mintTo,
|
|
3837
|
+
BigInt(allowListEntry.maxCanMint),
|
|
3838
|
+
allowListEntry.price,
|
|
3839
|
+
allowListEntry.proof
|
|
3840
|
+
]
|
|
3841
|
+
);
|
|
3842
|
+
}
|
|
3730
3843
|
function makeEthMintCall({
|
|
3731
3844
|
tokenContract,
|
|
3732
3845
|
tokenId,
|
|
@@ -3735,17 +3848,25 @@ function makeEthMintCall({
|
|
|
3735
3848
|
mintComment,
|
|
3736
3849
|
mintReferral,
|
|
3737
3850
|
mintQuantity,
|
|
3738
|
-
mintTo
|
|
3851
|
+
mintTo,
|
|
3852
|
+
allowListEntry
|
|
3739
3853
|
}) {
|
|
3740
3854
|
const mintValue = parseMintCosts({
|
|
3741
|
-
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
3742
3855
|
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
3743
|
-
quantityToMint: mintQuantity
|
|
3856
|
+
quantityToMint: mintQuantity,
|
|
3857
|
+
allowListEntry
|
|
3744
3858
|
}).totalCostEth;
|
|
3745
|
-
const
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3859
|
+
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
3860
|
+
let minterArguments;
|
|
3861
|
+
if (saleType === "fixedPrice") {
|
|
3862
|
+
minterArguments = makeFixedPriceMinterArguments({ mintTo, mintComment });
|
|
3863
|
+
} else if (saleType === "allowlist") {
|
|
3864
|
+
if (!allowListEntry)
|
|
3865
|
+
throw new Error("Missing allowListEntry");
|
|
3866
|
+
minterArguments = makeAllowListMinterArguments({ mintTo, allowListEntry });
|
|
3867
|
+
} else {
|
|
3868
|
+
throw new Error("Unsupported sale type");
|
|
3869
|
+
}
|
|
3749
3870
|
if (contractSupportsNewMintFunction(salesConfigAndTokenInfo.contractVersion)) {
|
|
3750
3871
|
return makeContractParameters({
|
|
3751
3872
|
abi: import_protocol_deployments6.zoraCreator1155ImplABI,
|
|
@@ -3778,13 +3899,21 @@ function makeEthMintCall({
|
|
|
3778
3899
|
]
|
|
3779
3900
|
});
|
|
3780
3901
|
}
|
|
3902
|
+
function paidMintCost(salesConfig, allowListEntry) {
|
|
3903
|
+
if (salesConfig.saleType === "erc20" || salesConfig.saleType === "fixedPrice") {
|
|
3904
|
+
return salesConfig.pricePerToken;
|
|
3905
|
+
}
|
|
3906
|
+
if (allowListEntry)
|
|
3907
|
+
return allowListEntry.price;
|
|
3908
|
+
return 0n;
|
|
3909
|
+
}
|
|
3781
3910
|
function parseMintCosts({
|
|
3782
3911
|
salesConfig,
|
|
3783
|
-
|
|
3784
|
-
|
|
3912
|
+
quantityToMint,
|
|
3913
|
+
allowListEntry
|
|
3785
3914
|
}) {
|
|
3786
|
-
const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
|
|
3787
|
-
const tokenPurchaseCost =
|
|
3915
|
+
const mintFeeForTokens = salesConfig.mintFeePerQuantity * quantityToMint;
|
|
3916
|
+
const tokenPurchaseCost = paidMintCost(salesConfig, allowListEntry) * quantityToMint;
|
|
3788
3917
|
const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig) ? salesConfig.currency : void 0;
|
|
3789
3918
|
const totalPurchaseCostEth = totalPurchaseCostCurrency ? 0n : tokenPurchaseCost;
|
|
3790
3919
|
return {
|
|
@@ -3796,7 +3925,6 @@ function parseMintCosts({
|
|
|
3796
3925
|
}
|
|
3797
3926
|
|
|
3798
3927
|
// src/mint/mint-queries.ts
|
|
3799
|
-
var import_viem6 = require("viem");
|
|
3800
3928
|
async function getMint({
|
|
3801
3929
|
params,
|
|
3802
3930
|
mintGetter,
|
|
@@ -3806,10 +3934,12 @@ async function getMint({
|
|
|
3806
3934
|
const { tokenContract } = params;
|
|
3807
3935
|
if (isOnChainMint(params)) {
|
|
3808
3936
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
3937
|
+
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
3809
3938
|
const result = await mintGetter.getMintable({
|
|
3810
3939
|
tokenId,
|
|
3811
3940
|
tokenAddress: tokenContract,
|
|
3812
|
-
preferredSaleType: params.preferredSaleType
|
|
3941
|
+
preferredSaleType: params.preferredSaleType,
|
|
3942
|
+
blockTime
|
|
3813
3943
|
});
|
|
3814
3944
|
return toMintableReturn(result);
|
|
3815
3945
|
}
|
|
@@ -3870,6 +4000,7 @@ async function getMintsOfContract({
|
|
|
3870
4000
|
}
|
|
3871
4001
|
async function getMintCosts({
|
|
3872
4002
|
params,
|
|
4003
|
+
allowListEntry,
|
|
3873
4004
|
mintGetter,
|
|
3874
4005
|
premintGetter,
|
|
3875
4006
|
publicClient
|
|
@@ -3877,14 +4008,19 @@ async function getMintCosts({
|
|
|
3877
4008
|
const { quantityMinted: quantityToMint, collection } = params;
|
|
3878
4009
|
if (isOnChainMint(params)) {
|
|
3879
4010
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
4011
|
+
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
3880
4012
|
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
3881
4013
|
tokenId,
|
|
3882
|
-
tokenAddress: collection
|
|
4014
|
+
tokenAddress: collection,
|
|
4015
|
+
blockTime
|
|
3883
4016
|
});
|
|
4017
|
+
if (!salesConfigAndTokenInfo.salesConfig) {
|
|
4018
|
+
throw new Error("No valid sales config found for token");
|
|
4019
|
+
}
|
|
3884
4020
|
return parseMintCosts({
|
|
3885
|
-
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
3886
4021
|
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
3887
|
-
quantityToMint: BigInt(quantityToMint)
|
|
4022
|
+
quantityToMint: BigInt(quantityToMint),
|
|
4023
|
+
allowListEntry
|
|
3888
4024
|
});
|
|
3889
4025
|
}
|
|
3890
4026
|
return getPremintMintCostsWithUnknownTokenPrice({
|
|
@@ -3940,7 +4076,6 @@ function parsePremint({
|
|
|
3940
4076
|
return {
|
|
3941
4077
|
creator: premint.signer,
|
|
3942
4078
|
maxSupply: premint.premint.premintConfig.tokenConfig.maxSupply,
|
|
3943
|
-
mintFeePerQuantity: mintFee,
|
|
3944
4079
|
mintType: "premint",
|
|
3945
4080
|
uid: premint.premint.premintConfig.uid,
|
|
3946
4081
|
contract: {
|
|
@@ -3954,21 +4089,30 @@ function parsePremint({
|
|
|
3954
4089
|
duration: premint.premint.premintConfig.tokenConfig.mintDuration,
|
|
3955
4090
|
maxTokensPerAddress: premint.premint.premintConfig.tokenConfig.maxTokensPerAddress,
|
|
3956
4091
|
pricePerToken: premint.premint.premintConfig.tokenConfig.pricePerToken,
|
|
3957
|
-
saleType: "premint"
|
|
4092
|
+
saleType: "premint",
|
|
4093
|
+
mintFeePerQuantity: mintFee
|
|
3958
4094
|
}
|
|
3959
4095
|
};
|
|
3960
4096
|
}
|
|
3961
4097
|
throw new Error("Invalid premint config version");
|
|
3962
4098
|
}
|
|
3963
|
-
var makeOnchainPrepareMint = (result) => (params) =>
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
})
|
|
4099
|
+
var makeOnchainPrepareMint = (result) => (params) => {
|
|
4100
|
+
if (!result.salesConfig) {
|
|
4101
|
+
throw new Error("No valid sales config found for token");
|
|
4102
|
+
}
|
|
4103
|
+
return {
|
|
4104
|
+
parameters: makeOnchainMintCall({
|
|
4105
|
+
token: result,
|
|
4106
|
+
mintParams: params
|
|
4107
|
+
}),
|
|
4108
|
+
erc20Approval: getRequiredErc20Approvals(params, result.salesConfig),
|
|
4109
|
+
costs: parseMintCosts({
|
|
4110
|
+
salesConfig: result.salesConfig,
|
|
4111
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
4112
|
+
allowListEntry: params.allowListEntry
|
|
4113
|
+
})
|
|
4114
|
+
};
|
|
4115
|
+
};
|
|
3972
4116
|
function toMintableReturn(result) {
|
|
3973
4117
|
return { token: result, prepareMint: makeOnchainPrepareMint(result) };
|
|
3974
4118
|
}
|
|
@@ -3979,9 +4123,9 @@ var makePremintPrepareMint = (mintable, mintFee, premint) => (params) => ({
|
|
|
3979
4123
|
premint
|
|
3980
4124
|
}),
|
|
3981
4125
|
costs: parseMintCosts({
|
|
3982
|
-
mintFeePerQuantity: mintFee,
|
|
3983
4126
|
quantityToMint: BigInt(params.quantityToMint),
|
|
3984
|
-
salesConfig: mintable.salesConfig
|
|
4127
|
+
salesConfig: mintable.salesConfig,
|
|
4128
|
+
allowListEntry: params.allowListEntry
|
|
3985
4129
|
})
|
|
3986
4130
|
});
|
|
3987
4131
|
function toPremintMintReturn({
|
|
@@ -3994,13 +4138,13 @@ function toPremintMintReturn({
|
|
|
3994
4138
|
prepareMint: makePremintPrepareMint(mintable, mintFee, premint)
|
|
3995
4139
|
};
|
|
3996
4140
|
}
|
|
3997
|
-
function getRequiredErc20Approvals(params,
|
|
3998
|
-
if (
|
|
4141
|
+
function getRequiredErc20Approvals(params, salesConfig) {
|
|
4142
|
+
if (salesConfig?.saleType !== "erc20")
|
|
3999
4143
|
return void 0;
|
|
4000
4144
|
return {
|
|
4001
|
-
quantity:
|
|
4002
|
-
approveTo:
|
|
4003
|
-
erc20:
|
|
4145
|
+
quantity: salesConfig.pricePerToken * BigInt(params.quantityToMint),
|
|
4146
|
+
approveTo: salesConfig.address,
|
|
4147
|
+
erc20: salesConfig.currency
|
|
4004
4148
|
};
|
|
4005
4149
|
}
|
|
4006
4150
|
|
|
@@ -4101,27 +4245,10 @@ async function mint({
|
|
|
4101
4245
|
mintReferral: parameters.mintReferral
|
|
4102
4246
|
});
|
|
4103
4247
|
}
|
|
4104
|
-
async function collectOnchain({
|
|
4105
|
-
chainId,
|
|
4106
|
-
mintGetter,
|
|
4107
|
-
...parameters
|
|
4108
|
-
}) {
|
|
4109
|
-
const { tokenContract, preferredSaleType: saleType } = parameters;
|
|
4110
|
-
const tokenId = is1155Mint(parameters) ? parameters.tokenId : void 0;
|
|
4111
|
-
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
4112
|
-
tokenId,
|
|
4113
|
-
tokenAddress: tokenContract,
|
|
4114
|
-
preferredSaleType: saleType
|
|
4115
|
-
});
|
|
4116
|
-
return makeOnchainMintCall({
|
|
4117
|
-
mintParams: parameters,
|
|
4118
|
-
token: salesConfigAndTokenInfo
|
|
4119
|
-
});
|
|
4120
|
-
}
|
|
4121
4248
|
|
|
4122
4249
|
// src/create/1155-create-helper.ts
|
|
4123
|
-
var
|
|
4124
|
-
var
|
|
4250
|
+
var import_protocol_deployments11 = require("@zoralabs/protocol-deployments");
|
|
4251
|
+
var import_viem10 = require("viem");
|
|
4125
4252
|
|
|
4126
4253
|
// src/create/contract-setup.ts
|
|
4127
4254
|
var import_protocol_deployments7 = require("@zoralabs/protocol-deployments");
|
|
@@ -4151,8 +4278,14 @@ async function getContractInfoExistingContract({
|
|
|
4151
4278
|
abi: import_protocol_deployments7.zoraCreator1155ImplABI,
|
|
4152
4279
|
functionName: "nextTokenId"
|
|
4153
4280
|
});
|
|
4281
|
+
const contractName = await publicClient.readContract({
|
|
4282
|
+
address: contractAddress,
|
|
4283
|
+
abi: import_protocol_deployments7.zoraCreator1155ImplABI,
|
|
4284
|
+
functionName: "name"
|
|
4285
|
+
});
|
|
4154
4286
|
return {
|
|
4155
4287
|
contractVersion,
|
|
4288
|
+
contractName,
|
|
4156
4289
|
nextTokenId
|
|
4157
4290
|
};
|
|
4158
4291
|
}
|
|
@@ -4179,1917 +4312,2191 @@ async function getDeterministicContractAddress({
|
|
|
4179
4312
|
}
|
|
4180
4313
|
|
|
4181
4314
|
// src/create/token-setup.ts
|
|
4182
|
-
var
|
|
4183
|
-
var
|
|
4184
|
-
var
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
const SALE_END_FOREVER = 18446744073709551615n;
|
|
4190
|
-
const DEFAULT_SALE_SETTINGS = {
|
|
4191
|
-
currency: import_viem7.zeroAddress,
|
|
4192
|
-
// Free Mint
|
|
4193
|
-
pricePerToken: 0n,
|
|
4194
|
-
// Sale start time – defaults to beginning of unix time
|
|
4195
|
-
saleStart: 0n,
|
|
4196
|
-
// This is the end of uint64, plenty of time
|
|
4197
|
-
saleEnd: SALE_END_FOREVER,
|
|
4198
|
-
// 0 Here means no limit
|
|
4199
|
-
maxTokensPerAddress: 0n
|
|
4200
|
-
};
|
|
4201
|
-
return {
|
|
4202
|
-
...DEFAULT_SALE_SETTINGS,
|
|
4203
|
-
...saleSettings
|
|
4204
|
-
};
|
|
4205
|
-
};
|
|
4206
|
-
function applyNew1155Defaults(props, ownerAddress) {
|
|
4207
|
-
const { payoutRecipient: fundsRecipient } = props;
|
|
4208
|
-
const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== import_viem7.zeroAddress ? fundsRecipient : ownerAddress;
|
|
4209
|
-
return {
|
|
4210
|
-
payoutRecipient: fundsRecipientOrOwner,
|
|
4211
|
-
createReferral: props.createReferral || import_viem7.zeroAddress,
|
|
4212
|
-
maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
|
|
4213
|
-
royaltyBPS: props.royaltyBPS || 1e3,
|
|
4214
|
-
salesConfig: saleSettingsOrDefault(props.salesConfig),
|
|
4215
|
-
tokenMetadataURI: props.tokenMetadataURI
|
|
4216
|
-
};
|
|
4315
|
+
var import_protocol_deployments9 = require("@zoralabs/protocol-deployments");
|
|
4316
|
+
var import_viem8 = require("viem");
|
|
4317
|
+
var semver2 = __toESM(require_semver2(), 1);
|
|
4318
|
+
|
|
4319
|
+
// src/ipfs/arweave.ts
|
|
4320
|
+
function isArweaveURL(url) {
|
|
4321
|
+
return url && typeof url === "string" ? url.startsWith("ar://") : false;
|
|
4217
4322
|
}
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
functionName: "addPermission",
|
|
4234
|
-
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
|
|
4235
|
-
});
|
|
4236
|
-
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
4237
|
-
abi: import_protocol_deployments8.erc20MinterABI,
|
|
4238
|
-
functionName: "setSale",
|
|
4239
|
-
args: [
|
|
4240
|
-
BigInt(nextTokenId),
|
|
4241
|
-
{
|
|
4242
|
-
saleStart: saleStart || BigInt(0),
|
|
4243
|
-
saleEnd: saleEnd || BigInt(0),
|
|
4244
|
-
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
4245
|
-
pricePerToken,
|
|
4246
|
-
fundsRecipient,
|
|
4247
|
-
currency
|
|
4248
|
-
}
|
|
4249
|
-
]
|
|
4250
|
-
});
|
|
4251
|
-
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
4252
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4253
|
-
functionName: "callSale",
|
|
4254
|
-
args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
|
|
4255
|
-
});
|
|
4256
|
-
return {
|
|
4257
|
-
minter: erc20MinterAddress,
|
|
4258
|
-
setupActions: [erc20MinterApproval, callSale]
|
|
4259
|
-
};
|
|
4323
|
+
|
|
4324
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
|
|
4325
|
+
var empty = new Uint8Array(0);
|
|
4326
|
+
function equals(aa, bb) {
|
|
4327
|
+
if (aa === bb)
|
|
4328
|
+
return true;
|
|
4329
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
4330
|
+
return false;
|
|
4331
|
+
}
|
|
4332
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
4333
|
+
if (aa[ii] !== bb[ii]) {
|
|
4334
|
+
return false;
|
|
4335
|
+
}
|
|
4336
|
+
}
|
|
4337
|
+
return true;
|
|
4260
4338
|
}
|
|
4261
|
-
function
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
fundsRecipient
|
|
4269
|
-
}) {
|
|
4270
|
-
const fixedPriceStrategyAddress = import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyAddress[chainId];
|
|
4271
|
-
const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
|
|
4272
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4273
|
-
functionName: "addPermission",
|
|
4274
|
-
args: [
|
|
4275
|
-
BigInt(nextTokenId),
|
|
4276
|
-
fixedPriceStrategyAddress,
|
|
4277
|
-
PERMISSION_BITS.MINTER
|
|
4278
|
-
]
|
|
4279
|
-
});
|
|
4280
|
-
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
4281
|
-
abi: import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyABI,
|
|
4282
|
-
functionName: "setSale",
|
|
4283
|
-
args: [
|
|
4284
|
-
BigInt(nextTokenId),
|
|
4285
|
-
{
|
|
4286
|
-
pricePerToken: price,
|
|
4287
|
-
saleStart: saleStart || BigInt(0),
|
|
4288
|
-
saleEnd: saleEnd || BigInt(0),
|
|
4289
|
-
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
4290
|
-
fundsRecipient
|
|
4291
|
-
}
|
|
4292
|
-
]
|
|
4293
|
-
});
|
|
4294
|
-
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
4295
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4296
|
-
functionName: "callSale",
|
|
4297
|
-
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
|
|
4298
|
-
});
|
|
4299
|
-
return {
|
|
4300
|
-
minter: fixedPriceStrategyAddress,
|
|
4301
|
-
setupActions: [fixedPriceApproval, callSale]
|
|
4302
|
-
};
|
|
4303
|
-
}
|
|
4304
|
-
function setupMinters({ salesConfig, ...rest }) {
|
|
4305
|
-
if (!salesConfig)
|
|
4306
|
-
throw new Error("No sales config for token");
|
|
4307
|
-
const { currency: currencyAddress } = salesConfig;
|
|
4308
|
-
if (currencyAddress === import_viem7.zeroAddress) {
|
|
4309
|
-
return setupFixedPriceMinter({
|
|
4310
|
-
...salesConfig,
|
|
4311
|
-
...rest
|
|
4312
|
-
});
|
|
4313
|
-
} else {
|
|
4314
|
-
return setupErc20Minter({
|
|
4315
|
-
...salesConfig,
|
|
4316
|
-
...rest
|
|
4317
|
-
});
|
|
4318
|
-
}
|
|
4319
|
-
}
|
|
4320
|
-
function buildSetupNewToken({
|
|
4321
|
-
tokenURI,
|
|
4322
|
-
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
4323
|
-
createReferral = import_viem7.zeroAddress,
|
|
4324
|
-
contractVersion
|
|
4325
|
-
}) {
|
|
4326
|
-
if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
|
|
4327
|
-
return (0, import_viem7.encodeFunctionData)({
|
|
4328
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4329
|
-
functionName: "setupNewTokenWithCreateReferral",
|
|
4330
|
-
args: [tokenURI, BigInt(maxSupply), createReferral]
|
|
4331
|
-
});
|
|
4332
|
-
}
|
|
4333
|
-
if (createReferral !== import_viem7.zeroAddress) {
|
|
4334
|
-
throw new Error(
|
|
4335
|
-
"Contract does not support create referral, but one was provided"
|
|
4336
|
-
);
|
|
4337
|
-
}
|
|
4338
|
-
return (0, import_viem7.encodeFunctionData)({
|
|
4339
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4340
|
-
functionName: "setupNewToken",
|
|
4341
|
-
args: [tokenURI, BigInt(maxSupply)]
|
|
4342
|
-
});
|
|
4343
|
-
}
|
|
4344
|
-
function setupRoyaltyConfig({
|
|
4345
|
-
royaltyBPS,
|
|
4346
|
-
royaltyRecipient,
|
|
4347
|
-
nextTokenId
|
|
4348
|
-
}) {
|
|
4349
|
-
if (royaltyBPS > 0 && royaltyRecipient != import_viem7.zeroAddress) {
|
|
4350
|
-
return (0, import_viem7.encodeFunctionData)({
|
|
4351
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4352
|
-
functionName: "updateRoyaltiesForToken",
|
|
4353
|
-
args: [
|
|
4354
|
-
nextTokenId,
|
|
4355
|
-
{
|
|
4356
|
-
royaltyBPS,
|
|
4357
|
-
royaltyRecipient,
|
|
4358
|
-
royaltyMintSchedule: 0
|
|
4359
|
-
}
|
|
4360
|
-
]
|
|
4361
|
-
});
|
|
4362
|
-
}
|
|
4363
|
-
return null;
|
|
4364
|
-
}
|
|
4365
|
-
function makeAdminMintCall({
|
|
4366
|
-
ownerAddress,
|
|
4367
|
-
mintQuantity,
|
|
4368
|
-
nextTokenId
|
|
4369
|
-
}) {
|
|
4370
|
-
if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
|
|
4371
|
-
return null;
|
|
4339
|
+
function coerce2(o) {
|
|
4340
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
4341
|
+
return o;
|
|
4342
|
+
if (o instanceof ArrayBuffer)
|
|
4343
|
+
return new Uint8Array(o);
|
|
4344
|
+
if (ArrayBuffer.isView(o)) {
|
|
4345
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
4372
4346
|
}
|
|
4373
|
-
|
|
4374
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4375
|
-
functionName: "adminMint",
|
|
4376
|
-
args: [ownerAddress, nextTokenId, BigInt(mintQuantity), import_viem7.zeroAddress]
|
|
4377
|
-
});
|
|
4378
|
-
}
|
|
4379
|
-
function constructCreate1155TokenCalls(props) {
|
|
4380
|
-
const {
|
|
4381
|
-
chainId,
|
|
4382
|
-
nextTokenId,
|
|
4383
|
-
mintToCreatorCount,
|
|
4384
|
-
ownerAddress,
|
|
4385
|
-
contractVersion
|
|
4386
|
-
} = props;
|
|
4387
|
-
const new1155TokenPropsWithDefaults = applyNew1155Defaults(
|
|
4388
|
-
props,
|
|
4389
|
-
ownerAddress
|
|
4390
|
-
);
|
|
4391
|
-
const verifyTokenIdExpected = (0, import_viem7.encodeFunctionData)({
|
|
4392
|
-
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
4393
|
-
functionName: "assumeLastTokenIdMatches",
|
|
4394
|
-
args: [nextTokenId - 1n]
|
|
4395
|
-
});
|
|
4396
|
-
const setupNewToken = buildSetupNewToken({
|
|
4397
|
-
tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
|
|
4398
|
-
maxSupply: new1155TokenPropsWithDefaults.maxSupply,
|
|
4399
|
-
createReferral: new1155TokenPropsWithDefaults.createReferral,
|
|
4400
|
-
contractVersion
|
|
4401
|
-
});
|
|
4402
|
-
const royaltyConfig = setupRoyaltyConfig({
|
|
4403
|
-
royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
|
|
4404
|
-
royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
4405
|
-
nextTokenId
|
|
4406
|
-
});
|
|
4407
|
-
const { minter, setupActions: mintersSetup } = setupMinters({
|
|
4408
|
-
tokenId: nextTokenId,
|
|
4409
|
-
chainId,
|
|
4410
|
-
fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
4411
|
-
salesConfig: new1155TokenPropsWithDefaults.salesConfig
|
|
4412
|
-
});
|
|
4413
|
-
const adminMintCall = makeAdminMintCall({
|
|
4414
|
-
ownerAddress,
|
|
4415
|
-
mintQuantity: mintToCreatorCount,
|
|
4416
|
-
nextTokenId
|
|
4417
|
-
});
|
|
4418
|
-
const setupActions = [
|
|
4419
|
-
verifyTokenIdExpected,
|
|
4420
|
-
setupNewToken,
|
|
4421
|
-
...mintersSetup,
|
|
4422
|
-
royaltyConfig,
|
|
4423
|
-
adminMintCall
|
|
4424
|
-
].filter((item) => item !== null);
|
|
4425
|
-
return {
|
|
4426
|
-
setupActions,
|
|
4427
|
-
minter,
|
|
4428
|
-
newToken: new1155TokenPropsWithDefaults
|
|
4429
|
-
};
|
|
4347
|
+
throw new Error("Unknown type, must be binary type");
|
|
4430
4348
|
}
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4349
|
+
|
|
4350
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
4351
|
+
function base2(ALPHABET, name) {
|
|
4352
|
+
if (ALPHABET.length >= 255) {
|
|
4353
|
+
throw new TypeError("Alphabet too long");
|
|
4434
4354
|
}
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
if (contractStandard === "ERC1155") {
|
|
4439
|
-
return semver3.gte(semVerContractVersion, "1.3.5");
|
|
4440
|
-
} else {
|
|
4441
|
-
return semver3.gte(semVerContractVersion, "14.0.0");
|
|
4355
|
+
var BASE_MAP = new Uint8Array(256);
|
|
4356
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
4357
|
+
BASE_MAP[j] = 255;
|
|
4442
4358
|
}
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
for (const data of receipt.logs) {
|
|
4449
|
-
try {
|
|
4450
|
-
const decodedLog = (0, import_viem8.decodeEventLog)({
|
|
4451
|
-
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
4452
|
-
eventName: "SetupNewToken",
|
|
4453
|
-
...data
|
|
4454
|
-
});
|
|
4455
|
-
if (decodedLog && decodedLog.eventName === "SetupNewToken") {
|
|
4456
|
-
return decodedLog.args.tokenId;
|
|
4457
|
-
}
|
|
4458
|
-
} catch (err) {
|
|
4359
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
4360
|
+
var x = ALPHABET.charAt(i);
|
|
4361
|
+
var xc = x.charCodeAt(0);
|
|
4362
|
+
if (BASE_MAP[xc] !== 255) {
|
|
4363
|
+
throw new TypeError(x + " is ambiguous");
|
|
4459
4364
|
}
|
|
4365
|
+
BASE_MAP[xc] = i;
|
|
4460
4366
|
}
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
);
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4367
|
+
var BASE = ALPHABET.length;
|
|
4368
|
+
var LEADER = ALPHABET.charAt(0);
|
|
4369
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
4370
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
4371
|
+
function encode3(source) {
|
|
4372
|
+
if (source instanceof Uint8Array)
|
|
4373
|
+
;
|
|
4374
|
+
else if (ArrayBuffer.isView(source)) {
|
|
4375
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
4376
|
+
} else if (Array.isArray(source)) {
|
|
4377
|
+
source = Uint8Array.from(source);
|
|
4378
|
+
}
|
|
4379
|
+
if (!(source instanceof Uint8Array)) {
|
|
4380
|
+
throw new TypeError("Expected Uint8Array");
|
|
4381
|
+
}
|
|
4382
|
+
if (source.length === 0) {
|
|
4383
|
+
return "";
|
|
4384
|
+
}
|
|
4385
|
+
var zeroes = 0;
|
|
4386
|
+
var length2 = 0;
|
|
4387
|
+
var pbegin = 0;
|
|
4388
|
+
var pend = source.length;
|
|
4389
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
4390
|
+
pbegin++;
|
|
4391
|
+
zeroes++;
|
|
4392
|
+
}
|
|
4393
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
4394
|
+
var b58 = new Uint8Array(size);
|
|
4395
|
+
while (pbegin !== pend) {
|
|
4396
|
+
var carry = source[pbegin];
|
|
4397
|
+
var i2 = 0;
|
|
4398
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
4399
|
+
carry += 256 * b58[it1] >>> 0;
|
|
4400
|
+
b58[it1] = carry % BASE >>> 0;
|
|
4401
|
+
carry = carry / BASE >>> 0;
|
|
4475
4402
|
}
|
|
4476
|
-
|
|
4403
|
+
if (carry !== 0) {
|
|
4404
|
+
throw new Error("Non-zero carry");
|
|
4405
|
+
}
|
|
4406
|
+
length2 = i2;
|
|
4407
|
+
pbegin++;
|
|
4408
|
+
}
|
|
4409
|
+
var it2 = size - length2;
|
|
4410
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
4411
|
+
it2++;
|
|
4412
|
+
}
|
|
4413
|
+
var str = LEADER.repeat(zeroes);
|
|
4414
|
+
for (; it2 < size; ++it2) {
|
|
4415
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
4477
4416
|
}
|
|
4417
|
+
return str;
|
|
4478
4418
|
}
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
}
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
{
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4419
|
+
function decodeUnsafe(source) {
|
|
4420
|
+
if (typeof source !== "string") {
|
|
4421
|
+
throw new TypeError("Expected String");
|
|
4422
|
+
}
|
|
4423
|
+
if (source.length === 0) {
|
|
4424
|
+
return new Uint8Array();
|
|
4425
|
+
}
|
|
4426
|
+
var psz = 0;
|
|
4427
|
+
if (source[psz] === " ") {
|
|
4428
|
+
return;
|
|
4429
|
+
}
|
|
4430
|
+
var zeroes = 0;
|
|
4431
|
+
var length2 = 0;
|
|
4432
|
+
while (source[psz] === LEADER) {
|
|
4433
|
+
zeroes++;
|
|
4434
|
+
psz++;
|
|
4435
|
+
}
|
|
4436
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
4437
|
+
var b256 = new Uint8Array(size);
|
|
4438
|
+
while (source[psz]) {
|
|
4439
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
4440
|
+
if (carry === 255) {
|
|
4441
|
+
return;
|
|
4442
|
+
}
|
|
4443
|
+
var i2 = 0;
|
|
4444
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
4445
|
+
carry += BASE * b256[it3] >>> 0;
|
|
4446
|
+
b256[it3] = carry % 256 >>> 0;
|
|
4447
|
+
carry = carry / 256 >>> 0;
|
|
4448
|
+
}
|
|
4449
|
+
if (carry !== 0) {
|
|
4450
|
+
throw new Error("Non-zero carry");
|
|
4451
|
+
}
|
|
4452
|
+
length2 = i2;
|
|
4453
|
+
psz++;
|
|
4454
|
+
}
|
|
4455
|
+
if (source[psz] === " ") {
|
|
4456
|
+
return;
|
|
4457
|
+
}
|
|
4458
|
+
var it4 = size - length2;
|
|
4459
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
4460
|
+
it4++;
|
|
4461
|
+
}
|
|
4462
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
4463
|
+
var j2 = zeroes;
|
|
4464
|
+
while (it4 !== size) {
|
|
4465
|
+
vch[j2++] = b256[it4++];
|
|
4466
|
+
}
|
|
4467
|
+
return vch;
|
|
4468
|
+
}
|
|
4469
|
+
function decode5(string) {
|
|
4470
|
+
var buffer = decodeUnsafe(string);
|
|
4471
|
+
if (buffer) {
|
|
4472
|
+
return buffer;
|
|
4473
|
+
}
|
|
4474
|
+
throw new Error(`Non-${name} character`);
|
|
4475
|
+
}
|
|
4476
|
+
return {
|
|
4477
|
+
encode: encode3,
|
|
4478
|
+
decodeUnsafe,
|
|
4479
|
+
decode: decode5
|
|
4480
|
+
};
|
|
4510
4481
|
}
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4482
|
+
var src = base2;
|
|
4483
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
4484
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
4485
|
+
|
|
4486
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
|
|
4487
|
+
var Encoder = class {
|
|
4488
|
+
constructor(name, prefix, baseEncode) {
|
|
4489
|
+
__publicField(this, "name");
|
|
4490
|
+
__publicField(this, "prefix");
|
|
4491
|
+
__publicField(this, "baseEncode");
|
|
4492
|
+
this.name = name;
|
|
4493
|
+
this.prefix = prefix;
|
|
4494
|
+
this.baseEncode = baseEncode;
|
|
4495
|
+
}
|
|
4496
|
+
encode(bytes) {
|
|
4497
|
+
if (bytes instanceof Uint8Array) {
|
|
4498
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
4499
|
+
} else {
|
|
4500
|
+
throw Error("Unknown type, must be binary type");
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
};
|
|
4504
|
+
var Decoder = class {
|
|
4505
|
+
constructor(name, prefix, baseDecode) {
|
|
4506
|
+
__publicField(this, "name");
|
|
4507
|
+
__publicField(this, "prefix");
|
|
4508
|
+
__publicField(this, "baseDecode");
|
|
4509
|
+
__publicField(this, "prefixCodePoint");
|
|
4510
|
+
this.name = name;
|
|
4511
|
+
this.prefix = prefix;
|
|
4512
|
+
if (prefix.codePointAt(0) === void 0) {
|
|
4513
|
+
throw new Error("Invalid prefix character");
|
|
4514
|
+
}
|
|
4515
|
+
this.prefixCodePoint = prefix.codePointAt(0);
|
|
4516
|
+
this.baseDecode = baseDecode;
|
|
4517
|
+
}
|
|
4518
|
+
decode(text) {
|
|
4519
|
+
if (typeof text === "string") {
|
|
4520
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
4521
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
4522
|
+
}
|
|
4523
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
4524
|
+
} else {
|
|
4525
|
+
throw Error("Can only multibase decode strings");
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
or(decoder) {
|
|
4529
|
+
return or(this, decoder);
|
|
4530
|
+
}
|
|
4531
|
+
};
|
|
4532
|
+
var ComposedDecoder = class {
|
|
4533
|
+
constructor(decoders) {
|
|
4534
|
+
__publicField(this, "decoders");
|
|
4535
|
+
this.decoders = decoders;
|
|
4536
|
+
}
|
|
4537
|
+
or(decoder) {
|
|
4538
|
+
return or(this, decoder);
|
|
4539
|
+
}
|
|
4540
|
+
decode(input) {
|
|
4541
|
+
const prefix = input[0];
|
|
4542
|
+
const decoder = this.decoders[prefix];
|
|
4543
|
+
if (decoder != null) {
|
|
4544
|
+
return decoder.decode(input);
|
|
4545
|
+
} else {
|
|
4546
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
};
|
|
4550
|
+
function or(left, right) {
|
|
4551
|
+
return new ComposedDecoder({
|
|
4552
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
4553
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
4522
4554
|
});
|
|
4523
4555
|
}
|
|
4524
|
-
var
|
|
4525
|
-
constructor({
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
this
|
|
4530
|
-
this
|
|
4556
|
+
var Codec = class {
|
|
4557
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
4558
|
+
__publicField(this, "name");
|
|
4559
|
+
__publicField(this, "prefix");
|
|
4560
|
+
__publicField(this, "baseEncode");
|
|
4561
|
+
__publicField(this, "baseDecode");
|
|
4562
|
+
__publicField(this, "encoder");
|
|
4563
|
+
__publicField(this, "decoder");
|
|
4564
|
+
this.name = name;
|
|
4565
|
+
this.prefix = prefix;
|
|
4566
|
+
this.baseEncode = baseEncode;
|
|
4567
|
+
this.baseDecode = baseDecode;
|
|
4568
|
+
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
4569
|
+
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
4531
4570
|
}
|
|
4532
|
-
|
|
4533
|
-
return
|
|
4534
|
-
...props,
|
|
4535
|
-
publicClient: this.publicClient,
|
|
4536
|
-
chainId: this.chainId
|
|
4537
|
-
});
|
|
4571
|
+
encode(input) {
|
|
4572
|
+
return this.encoder.encode(input);
|
|
4538
4573
|
}
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
account,
|
|
4542
|
-
token,
|
|
4543
|
-
getAdditionalSetupActions
|
|
4544
|
-
}) {
|
|
4545
|
-
return createNew1155Token({
|
|
4546
|
-
contractAddress: contract,
|
|
4547
|
-
account,
|
|
4548
|
-
token,
|
|
4549
|
-
getAdditionalSetupActions,
|
|
4550
|
-
publicClient: this.publicClient,
|
|
4551
|
-
chainId: this.chainId
|
|
4552
|
-
});
|
|
4574
|
+
decode(input) {
|
|
4575
|
+
return this.decoder.decode(input);
|
|
4553
4576
|
}
|
|
4554
4577
|
};
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
account,
|
|
4558
|
-
chainId,
|
|
4559
|
-
token,
|
|
4560
|
-
publicClient,
|
|
4561
|
-
getAdditionalSetupActions
|
|
4562
|
-
}) {
|
|
4563
|
-
const nextTokenId = 1n;
|
|
4564
|
-
const contractVersion = new1155ContractVersion(chainId);
|
|
4565
|
-
const {
|
|
4566
|
-
minter,
|
|
4567
|
-
newToken,
|
|
4568
|
-
setupActions: tokenSetupActions
|
|
4569
|
-
} = prepareSetupActions({
|
|
4570
|
-
chainId,
|
|
4571
|
-
account,
|
|
4572
|
-
contractVersion,
|
|
4573
|
-
nextTokenId,
|
|
4574
|
-
token,
|
|
4575
|
-
getAdditionalSetupActions
|
|
4576
|
-
});
|
|
4577
|
-
const request = makeCreateContractAndTokenCall({
|
|
4578
|
-
contract,
|
|
4579
|
-
account,
|
|
4580
|
-
chainId,
|
|
4581
|
-
tokenSetupActions,
|
|
4582
|
-
fundsRecipient: token.payoutRecipient,
|
|
4583
|
-
royaltyBPS: token.royaltyBPS
|
|
4584
|
-
});
|
|
4585
|
-
const contractAddress = await getDeterministicContractAddress({
|
|
4586
|
-
account,
|
|
4587
|
-
publicClient,
|
|
4588
|
-
setupActions: tokenSetupActions,
|
|
4589
|
-
chainId,
|
|
4590
|
-
contract
|
|
4591
|
-
});
|
|
4592
|
-
return {
|
|
4593
|
-
parameters: request,
|
|
4594
|
-
tokenSetupActions,
|
|
4595
|
-
newTokenId: nextTokenId,
|
|
4596
|
-
newToken,
|
|
4597
|
-
contractAddress,
|
|
4598
|
-
contractVersion,
|
|
4599
|
-
minter
|
|
4600
|
-
};
|
|
4578
|
+
function from({ name, prefix, encode: encode3, decode: decode5 }) {
|
|
4579
|
+
return new Codec(name, prefix, encode3, decode5);
|
|
4601
4580
|
}
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
}) {
|
|
4610
|
-
const { nextTokenId, contractVersion } = await getContractInfoExistingContract({
|
|
4611
|
-
publicClient,
|
|
4612
|
-
contractAddress
|
|
4613
|
-
});
|
|
4614
|
-
const {
|
|
4615
|
-
minter,
|
|
4616
|
-
newToken,
|
|
4617
|
-
setupActions: tokenSetupActions
|
|
4618
|
-
} = prepareSetupActions({
|
|
4619
|
-
chainId,
|
|
4620
|
-
account,
|
|
4621
|
-
contractVersion,
|
|
4622
|
-
nextTokenId,
|
|
4623
|
-
token,
|
|
4624
|
-
getAdditionalSetupActions
|
|
4625
|
-
});
|
|
4626
|
-
const request = makeCreateTokenCall({
|
|
4627
|
-
contractAddress,
|
|
4628
|
-
account,
|
|
4629
|
-
tokenSetupActions
|
|
4630
|
-
});
|
|
4631
|
-
return {
|
|
4632
|
-
parameters: request,
|
|
4633
|
-
tokenSetupActions,
|
|
4634
|
-
newTokenId: nextTokenId,
|
|
4635
|
-
newToken,
|
|
4636
|
-
contractVersion,
|
|
4637
|
-
minter
|
|
4638
|
-
};
|
|
4639
|
-
}
|
|
4640
|
-
function prepareSetupActions({
|
|
4641
|
-
chainId,
|
|
4642
|
-
account,
|
|
4643
|
-
contractVersion,
|
|
4644
|
-
nextTokenId,
|
|
4645
|
-
token,
|
|
4646
|
-
getAdditionalSetupActions
|
|
4647
|
-
}) {
|
|
4648
|
-
const {
|
|
4649
|
-
minter,
|
|
4650
|
-
newToken,
|
|
4651
|
-
setupActions: tokenSetupActions
|
|
4652
|
-
} = constructCreate1155TokenCalls({
|
|
4653
|
-
chainId,
|
|
4654
|
-
ownerAddress: account,
|
|
4655
|
-
contractVersion,
|
|
4656
|
-
nextTokenId,
|
|
4657
|
-
...token
|
|
4581
|
+
function baseX({ name, prefix, alphabet }) {
|
|
4582
|
+
const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
|
|
4583
|
+
return from({
|
|
4584
|
+
prefix,
|
|
4585
|
+
name,
|
|
4586
|
+
encode: encode3,
|
|
4587
|
+
decode: (text) => coerce2(decode5(text))
|
|
4658
4588
|
});
|
|
4659
|
-
const setupActions = getAdditionalSetupActions ? [
|
|
4660
|
-
...getAdditionalSetupActions({
|
|
4661
|
-
tokenId: nextTokenId
|
|
4662
|
-
}),
|
|
4663
|
-
...tokenSetupActions
|
|
4664
|
-
] : tokenSetupActions;
|
|
4665
|
-
return { minter, newToken, setupActions };
|
|
4666
4589
|
}
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4590
|
+
function decode(string, alphabet, bitsPerChar, name) {
|
|
4591
|
+
const codes = {};
|
|
4592
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
4593
|
+
codes[alphabet[i]] = i;
|
|
4594
|
+
}
|
|
4595
|
+
let end = string.length;
|
|
4596
|
+
while (string[end - 1] === "=") {
|
|
4597
|
+
--end;
|
|
4598
|
+
}
|
|
4599
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
4600
|
+
let bits = 0;
|
|
4601
|
+
let buffer = 0;
|
|
4602
|
+
let written = 0;
|
|
4603
|
+
for (let i = 0; i < end; ++i) {
|
|
4604
|
+
const value = codes[string[i]];
|
|
4605
|
+
if (value === void 0) {
|
|
4606
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
4679
4607
|
}
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
};
|
|
4686
|
-
var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
|
|
4687
|
-
const parsed = mintAccountBalances.map((r) => {
|
|
4688
|
-
return {
|
|
4689
|
-
tokenId: BigInt(r.mintToken.id),
|
|
4690
|
-
quantity: BigInt(r.balance),
|
|
4691
|
-
pricePerToken: BigInt(r.mintToken.pricePerToken)
|
|
4692
|
-
};
|
|
4693
|
-
});
|
|
4694
|
-
const sorted = parsed.sort((a, b) => {
|
|
4695
|
-
if (a.pricePerToken < b.pricePerToken) {
|
|
4696
|
-
return -1;
|
|
4608
|
+
buffer = buffer << bitsPerChar | value;
|
|
4609
|
+
bits += bitsPerChar;
|
|
4610
|
+
if (bits >= 8) {
|
|
4611
|
+
bits -= 8;
|
|
4612
|
+
out[written++] = 255 & buffer >> bits;
|
|
4697
4613
|
}
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4614
|
+
}
|
|
4615
|
+
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
4616
|
+
throw new SyntaxError("Unexpected end of data");
|
|
4617
|
+
}
|
|
4618
|
+
return out;
|
|
4619
|
+
}
|
|
4620
|
+
function encode(data, alphabet, bitsPerChar) {
|
|
4621
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
4622
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
4623
|
+
let out = "";
|
|
4624
|
+
let bits = 0;
|
|
4625
|
+
let buffer = 0;
|
|
4626
|
+
for (let i = 0; i < data.length; ++i) {
|
|
4627
|
+
buffer = buffer << 8 | data[i];
|
|
4628
|
+
bits += 8;
|
|
4629
|
+
while (bits > bitsPerChar) {
|
|
4630
|
+
bits -= bitsPerChar;
|
|
4631
|
+
out += alphabet[mask & buffer >> bits];
|
|
4707
4632
|
}
|
|
4708
|
-
const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
|
|
4709
|
-
tokenIds.push(next.tokenId);
|
|
4710
|
-
quantities.push(quantityToUse);
|
|
4711
|
-
remainingQuantity -= quantityToUse;
|
|
4712
4633
|
}
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
}
|
|
4634
|
+
if (bits !== 0) {
|
|
4635
|
+
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
4636
|
+
}
|
|
4637
|
+
if (pad) {
|
|
4638
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
4639
|
+
out += "=";
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
return out;
|
|
4643
|
+
}
|
|
4644
|
+
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
4645
|
+
return from({
|
|
4646
|
+
prefix,
|
|
4647
|
+
name,
|
|
4648
|
+
encode(input) {
|
|
4649
|
+
return encode(input, alphabet, bitsPerChar);
|
|
4650
|
+
},
|
|
4651
|
+
decode(input) {
|
|
4652
|
+
return decode(input, alphabet, bitsPerChar, name);
|
|
4653
|
+
}
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4723
4656
|
|
|
4724
|
-
// src/
|
|
4725
|
-
var
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
quantity,
|
|
4731
|
-
recipient,
|
|
4732
|
-
chainId,
|
|
4733
|
-
pricePerMint,
|
|
4734
|
-
account
|
|
4735
|
-
}) => makeContractParameters({
|
|
4736
|
-
abi: import_protocol_deployments10.zoraSparksManagerImplABI,
|
|
4737
|
-
address: import_protocol_deployments10.zoraSparksManagerImplAddress[chainId],
|
|
4738
|
-
functionName: "mintWithEth",
|
|
4739
|
-
args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
|
|
4740
|
-
value: pricePerMint * quantity,
|
|
4741
|
-
account
|
|
4657
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
|
|
4658
|
+
var base32 = rfc4648({
|
|
4659
|
+
prefix: "b",
|
|
4660
|
+
name: "base32",
|
|
4661
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
4662
|
+
bitsPerChar: 5
|
|
4742
4663
|
});
|
|
4743
|
-
var
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
var mintsBalanceOfAccountParams = ({
|
|
4749
|
-
account,
|
|
4750
|
-
chainId
|
|
4751
|
-
}) => ({
|
|
4752
|
-
abi: import_protocol_deployments10.zoraMints1155Config.abi,
|
|
4753
|
-
address: import_protocol_deployments10.zoraMints1155Config.address[chainId],
|
|
4754
|
-
functionName: "balanceOfAccount",
|
|
4755
|
-
args: [account]
|
|
4664
|
+
var base32upper = rfc4648({
|
|
4665
|
+
prefix: "B",
|
|
4666
|
+
name: "base32upper",
|
|
4667
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
4668
|
+
bitsPerChar: 5
|
|
4756
4669
|
});
|
|
4757
|
-
var
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
}) => (0, import_viem9.encodeFunctionData)({
|
|
4763
|
-
abi: import_protocol_deployments10.zoraMintsManagerImplConfig.abi,
|
|
4764
|
-
functionName: "collect",
|
|
4765
|
-
args: [
|
|
4766
|
-
zoraCreator1155Contract,
|
|
4767
|
-
minter,
|
|
4768
|
-
zoraCreator1155TokenId,
|
|
4769
|
-
mintArguments
|
|
4770
|
-
]
|
|
4670
|
+
var base32pad = rfc4648({
|
|
4671
|
+
prefix: "c",
|
|
4672
|
+
name: "base32pad",
|
|
4673
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
4674
|
+
bitsPerChar: 5
|
|
4771
4675
|
});
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
account,
|
|
4778
|
-
mintArguments,
|
|
4779
|
-
minter,
|
|
4780
|
-
zoraCreator1155Contract,
|
|
4781
|
-
zoraCreator1155TokenId
|
|
4782
|
-
}) {
|
|
4783
|
-
const call = encodeCollectOnManager({
|
|
4784
|
-
tokenIds,
|
|
4785
|
-
quantities,
|
|
4786
|
-
zoraCreator1155Contract,
|
|
4787
|
-
zoraCreator1155TokenId,
|
|
4788
|
-
minter,
|
|
4789
|
-
mintArguments
|
|
4790
|
-
});
|
|
4791
|
-
return makeContractParameters({
|
|
4792
|
-
abi: import_protocol_deployments10.zoraMints1155Config.abi,
|
|
4793
|
-
address: import_protocol_deployments10.zoraMints1155Config.address[chainId],
|
|
4794
|
-
functionName: "transferBatchToManagerAndCall",
|
|
4795
|
-
args: [tokenIds, quantities, call],
|
|
4796
|
-
// if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
|
|
4797
|
-
// for the paid mint cost.
|
|
4798
|
-
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
4799
|
-
account
|
|
4800
|
-
});
|
|
4801
|
-
}
|
|
4802
|
-
function getMintsEthPrice({
|
|
4803
|
-
publicClient
|
|
4804
|
-
}) {
|
|
4805
|
-
const chainId = publicClient.chain?.id;
|
|
4806
|
-
if (!chainId || !import_protocol_deployments10.zoraMintsManagerImplAddress[chainId]) {
|
|
4807
|
-
throw new Error(`Chain id ${chainId} not supported`);
|
|
4808
|
-
}
|
|
4809
|
-
return publicClient.readContract({
|
|
4810
|
-
abi: import_protocol_deployments10.zoraMintsManagerImplABI,
|
|
4811
|
-
address: import_protocol_deployments10.zoraMintsManagerImplAddress[chainId],
|
|
4812
|
-
functionName: "getEthPrice"
|
|
4813
|
-
});
|
|
4814
|
-
}
|
|
4815
|
-
function makePermitTransferBatchAndTypeData({
|
|
4816
|
-
tokenIds,
|
|
4817
|
-
quantities,
|
|
4818
|
-
chainId,
|
|
4819
|
-
mintsOwner,
|
|
4820
|
-
to,
|
|
4821
|
-
nonce,
|
|
4822
|
-
deadline,
|
|
4823
|
-
safeTransferData
|
|
4824
|
-
}) {
|
|
4825
|
-
const permit = {
|
|
4826
|
-
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
4827
|
-
to,
|
|
4828
|
-
tokenIds,
|
|
4829
|
-
quantities,
|
|
4830
|
-
deadline,
|
|
4831
|
-
nonce,
|
|
4832
|
-
safeTransferData
|
|
4833
|
-
};
|
|
4834
|
-
const typedData = {
|
|
4835
|
-
...(0, import_protocol_deployments10.mintsSafeTransferBatchTypedDataDefinition)({
|
|
4836
|
-
chainId,
|
|
4837
|
-
message: permit
|
|
4838
|
-
}),
|
|
4839
|
-
account: mintsOwner
|
|
4840
|
-
};
|
|
4841
|
-
return {
|
|
4842
|
-
permit,
|
|
4843
|
-
typedData
|
|
4844
|
-
};
|
|
4845
|
-
}
|
|
4846
|
-
function makePermitTransferTypeData({
|
|
4847
|
-
tokenId,
|
|
4848
|
-
quantity,
|
|
4849
|
-
chainId,
|
|
4850
|
-
mintsOwner,
|
|
4851
|
-
to,
|
|
4852
|
-
nonce,
|
|
4853
|
-
deadline,
|
|
4854
|
-
safeTransferData
|
|
4855
|
-
}) {
|
|
4856
|
-
const permit = {
|
|
4857
|
-
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
4858
|
-
to,
|
|
4859
|
-
tokenId,
|
|
4860
|
-
quantity,
|
|
4861
|
-
deadline,
|
|
4862
|
-
nonce,
|
|
4863
|
-
safeTransferData
|
|
4864
|
-
};
|
|
4865
|
-
const typedData = {
|
|
4866
|
-
...(0, import_protocol_deployments10.mintsSafeTransferTypedDataDefinition)({
|
|
4867
|
-
chainId,
|
|
4868
|
-
message: permit
|
|
4869
|
-
}),
|
|
4870
|
-
account: mintsOwner
|
|
4871
|
-
};
|
|
4872
|
-
return {
|
|
4873
|
-
permit,
|
|
4874
|
-
typedData
|
|
4875
|
-
};
|
|
4876
|
-
}
|
|
4877
|
-
var encodePremintOnManager = ({
|
|
4878
|
-
contractCreationConfig,
|
|
4879
|
-
premintConfig,
|
|
4880
|
-
premintSignature,
|
|
4881
|
-
mintArguments,
|
|
4882
|
-
signerContract = import_viem9.zeroAddress
|
|
4883
|
-
}) => (0, import_viem9.encodeFunctionData)({
|
|
4884
|
-
abi: import_protocol_deployments10.zoraMintsManagerImplConfig.abi,
|
|
4885
|
-
functionName: "collectPremintV2",
|
|
4886
|
-
args: [
|
|
4887
|
-
contractCreationConfig,
|
|
4888
|
-
premintConfig,
|
|
4889
|
-
premintSignature,
|
|
4890
|
-
mintArguments,
|
|
4891
|
-
signerContract
|
|
4892
|
-
]
|
|
4676
|
+
var base32padupper = rfc4648({
|
|
4677
|
+
prefix: "C",
|
|
4678
|
+
name: "base32padupper",
|
|
4679
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
4680
|
+
bitsPerChar: 5
|
|
4893
4681
|
});
|
|
4894
|
-
var
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4682
|
+
var base32hex = rfc4648({
|
|
4683
|
+
prefix: "v",
|
|
4684
|
+
name: "base32hex",
|
|
4685
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
4686
|
+
bitsPerChar: 5
|
|
4687
|
+
});
|
|
4688
|
+
var base32hexupper = rfc4648({
|
|
4689
|
+
prefix: "V",
|
|
4690
|
+
name: "base32hexupper",
|
|
4691
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
4692
|
+
bitsPerChar: 5
|
|
4693
|
+
});
|
|
4694
|
+
var base32hexpad = rfc4648({
|
|
4695
|
+
prefix: "t",
|
|
4696
|
+
name: "base32hexpad",
|
|
4697
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
4698
|
+
bitsPerChar: 5
|
|
4699
|
+
});
|
|
4700
|
+
var base32hexpadupper = rfc4648({
|
|
4701
|
+
prefix: "T",
|
|
4702
|
+
name: "base32hexpadupper",
|
|
4703
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
4704
|
+
bitsPerChar: 5
|
|
4705
|
+
});
|
|
4706
|
+
var base32z = rfc4648({
|
|
4707
|
+
prefix: "h",
|
|
4708
|
+
name: "base32z",
|
|
4709
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
4710
|
+
bitsPerChar: 5
|
|
4711
|
+
});
|
|
4712
|
+
|
|
4713
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
4714
|
+
var base58btc = baseX({
|
|
4715
|
+
name: "base58btc",
|
|
4716
|
+
prefix: "z",
|
|
4717
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
4718
|
+
});
|
|
4719
|
+
var base58flickr = baseX({
|
|
4720
|
+
name: "base58flickr",
|
|
4721
|
+
prefix: "Z",
|
|
4722
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
4723
|
+
});
|
|
4724
|
+
|
|
4725
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
|
|
4726
|
+
var encode_1 = encode2;
|
|
4727
|
+
var MSB = 128;
|
|
4728
|
+
var REST = 127;
|
|
4729
|
+
var MSBALL = ~REST;
|
|
4730
|
+
var INT = Math.pow(2, 31);
|
|
4731
|
+
function encode2(num, out, offset) {
|
|
4732
|
+
out = out || [];
|
|
4733
|
+
offset = offset || 0;
|
|
4734
|
+
var oldOffset = offset;
|
|
4735
|
+
while (num >= INT) {
|
|
4736
|
+
out[offset++] = num & 255 | MSB;
|
|
4737
|
+
num /= 128;
|
|
4914
4738
|
}
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
safeTransferData,
|
|
4923
|
-
to: import_protocol_deployments10.zoraMintsManagerImplConfig.address[chainId]
|
|
4924
|
-
});
|
|
4925
|
-
};
|
|
4926
|
-
function collectPremintV2WithMintsParams({
|
|
4927
|
-
tokenIds,
|
|
4928
|
-
quantities,
|
|
4929
|
-
paidMintPricePerToken,
|
|
4930
|
-
account,
|
|
4931
|
-
chainId,
|
|
4932
|
-
...rest
|
|
4933
|
-
}) {
|
|
4934
|
-
const call = encodePremintOnManager({
|
|
4935
|
-
...rest
|
|
4936
|
-
});
|
|
4937
|
-
return makeContractParameters({
|
|
4938
|
-
abi: import_protocol_deployments10.zoraMints1155Config.abi,
|
|
4939
|
-
address: import_protocol_deployments10.zoraMints1155Config.address[chainId],
|
|
4940
|
-
functionName: "transferBatchToManagerAndCall",
|
|
4941
|
-
args: [tokenIds, quantities, call],
|
|
4942
|
-
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
4943
|
-
account
|
|
4944
|
-
});
|
|
4739
|
+
while (num & MSBALL) {
|
|
4740
|
+
out[offset++] = num & 255 | MSB;
|
|
4741
|
+
num >>>= 7;
|
|
4742
|
+
}
|
|
4743
|
+
out[offset] = num | 0;
|
|
4744
|
+
encode2.bytes = offset - oldOffset + 1;
|
|
4745
|
+
return out;
|
|
4945
4746
|
}
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4747
|
+
var decode2 = read;
|
|
4748
|
+
var MSB$1 = 128;
|
|
4749
|
+
var REST$1 = 127;
|
|
4750
|
+
function read(buf, offset) {
|
|
4751
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
4752
|
+
do {
|
|
4753
|
+
if (counter >= l) {
|
|
4754
|
+
read.bytes = 0;
|
|
4755
|
+
throw new RangeError("Could not decode varint");
|
|
4756
|
+
}
|
|
4757
|
+
b = buf[counter++];
|
|
4758
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
4759
|
+
shift += 7;
|
|
4760
|
+
} while (b >= MSB$1);
|
|
4761
|
+
read.bytes = counter - offset;
|
|
4762
|
+
return res;
|
|
4954
4763
|
}
|
|
4764
|
+
var N1 = Math.pow(2, 7);
|
|
4765
|
+
var N2 = Math.pow(2, 14);
|
|
4766
|
+
var N3 = Math.pow(2, 21);
|
|
4767
|
+
var N4 = Math.pow(2, 28);
|
|
4768
|
+
var N5 = Math.pow(2, 35);
|
|
4769
|
+
var N6 = Math.pow(2, 42);
|
|
4770
|
+
var N7 = Math.pow(2, 49);
|
|
4771
|
+
var N8 = Math.pow(2, 56);
|
|
4772
|
+
var N9 = Math.pow(2, 63);
|
|
4773
|
+
var length = function(value) {
|
|
4774
|
+
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;
|
|
4775
|
+
};
|
|
4776
|
+
var varint = {
|
|
4777
|
+
encode: encode_1,
|
|
4778
|
+
decode: decode2,
|
|
4779
|
+
encodingLength: length
|
|
4780
|
+
};
|
|
4781
|
+
var _brrp_varint = varint;
|
|
4782
|
+
var varint_default = _brrp_varint;
|
|
4955
4783
|
|
|
4956
|
-
// src/
|
|
4957
|
-
function
|
|
4958
|
-
const
|
|
4959
|
-
|
|
4960
|
-
publicClient: clientConfig.publicClient,
|
|
4961
|
-
premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
|
|
4962
|
-
});
|
|
4963
|
-
const create1155CreatorClient = new Create1155Client({
|
|
4964
|
-
chainId: clientConfig.chainId,
|
|
4965
|
-
publicClient: clientConfig.publicClient
|
|
4966
|
-
});
|
|
4967
|
-
return {
|
|
4968
|
-
createPremint: (p) => premintClient.createPremint(p),
|
|
4969
|
-
updatePremint: (p) => premintClient.updatePremint(p),
|
|
4970
|
-
deletePremint: (p) => premintClient.deletePremint(p),
|
|
4971
|
-
create1155: (p) => create1155CreatorClient.createNew1155(p),
|
|
4972
|
-
create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
|
|
4973
|
-
};
|
|
4784
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
|
|
4785
|
+
function decode3(data, offset = 0) {
|
|
4786
|
+
const code = varint_default.decode(data, offset);
|
|
4787
|
+
return [code, varint_default.decode.bytes];
|
|
4974
4788
|
}
|
|
4975
|
-
function
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
const mintClient = new MintClient({
|
|
4979
|
-
publicClient: params.publicClient,
|
|
4980
|
-
premintGetter: premintGetterToUse,
|
|
4981
|
-
mintGetter: mintGetterToUse
|
|
4982
|
-
});
|
|
4983
|
-
return {
|
|
4984
|
-
getPremint: (p) => premintGetterToUse.get({
|
|
4985
|
-
collectionAddress: p.address,
|
|
4986
|
-
uid: p.uid
|
|
4987
|
-
}),
|
|
4988
|
-
getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
|
|
4989
|
-
getToken: (p) => mintClient.get(p),
|
|
4990
|
-
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
4991
|
-
mint: (p) => mintClient.mint(p),
|
|
4992
|
-
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
4993
|
-
};
|
|
4789
|
+
function encodeTo(int, target, offset = 0) {
|
|
4790
|
+
varint_default.encode(int, target, offset);
|
|
4791
|
+
return target;
|
|
4994
4792
|
}
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
function isArweaveURL(url) {
|
|
4998
|
-
return url && typeof url === "string" ? url.startsWith("ar://") : false;
|
|
4793
|
+
function encodingLength(int) {
|
|
4794
|
+
return varint_default.encodingLength(int);
|
|
4999
4795
|
}
|
|
5000
4796
|
|
|
5001
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
4797
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
|
|
4798
|
+
function create(code, digest) {
|
|
4799
|
+
const size = digest.byteLength;
|
|
4800
|
+
const sizeOffset = encodingLength(code);
|
|
4801
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
4802
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
4803
|
+
encodeTo(code, bytes, 0);
|
|
4804
|
+
encodeTo(size, bytes, sizeOffset);
|
|
4805
|
+
bytes.set(digest, digestOffset);
|
|
4806
|
+
return new Digest(code, size, digest, bytes);
|
|
4807
|
+
}
|
|
4808
|
+
function decode4(multihash) {
|
|
4809
|
+
const bytes = coerce2(multihash);
|
|
4810
|
+
const [code, sizeOffset] = decode3(bytes);
|
|
4811
|
+
const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
|
|
4812
|
+
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
4813
|
+
if (digest.byteLength !== size) {
|
|
4814
|
+
throw new Error("Incorrect length");
|
|
4815
|
+
}
|
|
4816
|
+
return new Digest(code, size, digest, bytes);
|
|
4817
|
+
}
|
|
4818
|
+
function equals2(a, b) {
|
|
4819
|
+
if (a === b) {
|
|
5005
4820
|
return true;
|
|
5006
|
-
|
|
5007
|
-
|
|
4821
|
+
} else {
|
|
4822
|
+
const data = b;
|
|
4823
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
5008
4824
|
}
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
4825
|
+
}
|
|
4826
|
+
var Digest = class {
|
|
4827
|
+
/**
|
|
4828
|
+
* Creates a multihash digest.
|
|
4829
|
+
*/
|
|
4830
|
+
constructor(code, size, digest, bytes) {
|
|
4831
|
+
__publicField(this, "code");
|
|
4832
|
+
__publicField(this, "size");
|
|
4833
|
+
__publicField(this, "digest");
|
|
4834
|
+
__publicField(this, "bytes");
|
|
4835
|
+
this.code = code;
|
|
4836
|
+
this.size = size;
|
|
4837
|
+
this.digest = digest;
|
|
4838
|
+
this.bytes = bytes;
|
|
4839
|
+
}
|
|
4840
|
+
};
|
|
4841
|
+
|
|
4842
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
|
|
4843
|
+
function format(link, base3) {
|
|
4844
|
+
const { bytes, version } = link;
|
|
4845
|
+
switch (version) {
|
|
4846
|
+
case 0:
|
|
4847
|
+
return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
|
|
4848
|
+
default:
|
|
4849
|
+
return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
|
|
5013
4850
|
}
|
|
5014
|
-
return true;
|
|
5015
4851
|
}
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
if (
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
return
|
|
4852
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
4853
|
+
function baseCache(cid) {
|
|
4854
|
+
const baseCache2 = cache.get(cid);
|
|
4855
|
+
if (baseCache2 == null) {
|
|
4856
|
+
const baseCache3 = /* @__PURE__ */ new Map();
|
|
4857
|
+
cache.set(cid, baseCache3);
|
|
4858
|
+
return baseCache3;
|
|
5023
4859
|
}
|
|
5024
|
-
|
|
4860
|
+
return baseCache2;
|
|
5025
4861
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
4862
|
+
var _a;
|
|
4863
|
+
var CID = class _CID {
|
|
4864
|
+
/**
|
|
4865
|
+
* @param version - Version of the CID
|
|
4866
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
4867
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
4868
|
+
*/
|
|
4869
|
+
constructor(version, code, multihash, bytes) {
|
|
4870
|
+
__publicField(this, "code");
|
|
4871
|
+
__publicField(this, "version");
|
|
4872
|
+
__publicField(this, "multihash");
|
|
4873
|
+
__publicField(this, "bytes");
|
|
4874
|
+
__publicField(this, "/");
|
|
4875
|
+
__publicField(this, _a, "CID");
|
|
4876
|
+
this.code = code;
|
|
4877
|
+
this.version = version;
|
|
4878
|
+
this.multihash = multihash;
|
|
4879
|
+
this.bytes = bytes;
|
|
4880
|
+
this["/"] = bytes;
|
|
5031
4881
|
}
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
4882
|
+
/**
|
|
4883
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
4884
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
4885
|
+
*
|
|
4886
|
+
* @deprecated
|
|
4887
|
+
*/
|
|
4888
|
+
get asCID() {
|
|
4889
|
+
return this;
|
|
5035
4890
|
}
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
if (BASE_MAP[xc] !== 255) {
|
|
5040
|
-
throw new TypeError(x + " is ambiguous");
|
|
5041
|
-
}
|
|
5042
|
-
BASE_MAP[xc] = i;
|
|
4891
|
+
// ArrayBufferView
|
|
4892
|
+
get byteOffset() {
|
|
4893
|
+
return this.bytes.byteOffset;
|
|
5043
4894
|
}
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
5053
|
-
} else if (Array.isArray(source)) {
|
|
5054
|
-
source = Uint8Array.from(source);
|
|
5055
|
-
}
|
|
5056
|
-
if (!(source instanceof Uint8Array)) {
|
|
5057
|
-
throw new TypeError("Expected Uint8Array");
|
|
5058
|
-
}
|
|
5059
|
-
if (source.length === 0) {
|
|
5060
|
-
return "";
|
|
5061
|
-
}
|
|
5062
|
-
var zeroes = 0;
|
|
5063
|
-
var length2 = 0;
|
|
5064
|
-
var pbegin = 0;
|
|
5065
|
-
var pend = source.length;
|
|
5066
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
5067
|
-
pbegin++;
|
|
5068
|
-
zeroes++;
|
|
5069
|
-
}
|
|
5070
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
5071
|
-
var b58 = new Uint8Array(size);
|
|
5072
|
-
while (pbegin !== pend) {
|
|
5073
|
-
var carry = source[pbegin];
|
|
5074
|
-
var i2 = 0;
|
|
5075
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
5076
|
-
carry += 256 * b58[it1] >>> 0;
|
|
5077
|
-
b58[it1] = carry % BASE >>> 0;
|
|
5078
|
-
carry = carry / BASE >>> 0;
|
|
4895
|
+
// ArrayBufferView
|
|
4896
|
+
get byteLength() {
|
|
4897
|
+
return this.bytes.byteLength;
|
|
4898
|
+
}
|
|
4899
|
+
toV0() {
|
|
4900
|
+
switch (this.version) {
|
|
4901
|
+
case 0: {
|
|
4902
|
+
return this;
|
|
5079
4903
|
}
|
|
5080
|
-
|
|
5081
|
-
|
|
4904
|
+
case 1: {
|
|
4905
|
+
const { code, multihash } = this;
|
|
4906
|
+
if (code !== DAG_PB_CODE) {
|
|
4907
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
4908
|
+
}
|
|
4909
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
4910
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
4911
|
+
}
|
|
4912
|
+
return _CID.createV0(multihash);
|
|
4913
|
+
}
|
|
4914
|
+
default: {
|
|
4915
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
5082
4916
|
}
|
|
5083
|
-
length2 = i2;
|
|
5084
|
-
pbegin++;
|
|
5085
|
-
}
|
|
5086
|
-
var it2 = size - length2;
|
|
5087
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
5088
|
-
it2++;
|
|
5089
|
-
}
|
|
5090
|
-
var str = LEADER.repeat(zeroes);
|
|
5091
|
-
for (; it2 < size; ++it2) {
|
|
5092
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
5093
4917
|
}
|
|
5094
|
-
return str;
|
|
5095
4918
|
}
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
}
|
|
5103
|
-
var psz = 0;
|
|
5104
|
-
if (source[psz] === " ") {
|
|
5105
|
-
return;
|
|
5106
|
-
}
|
|
5107
|
-
var zeroes = 0;
|
|
5108
|
-
var length2 = 0;
|
|
5109
|
-
while (source[psz] === LEADER) {
|
|
5110
|
-
zeroes++;
|
|
5111
|
-
psz++;
|
|
5112
|
-
}
|
|
5113
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
5114
|
-
var b256 = new Uint8Array(size);
|
|
5115
|
-
while (source[psz]) {
|
|
5116
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
5117
|
-
if (carry === 255) {
|
|
5118
|
-
return;
|
|
4919
|
+
toV1() {
|
|
4920
|
+
switch (this.version) {
|
|
4921
|
+
case 0: {
|
|
4922
|
+
const { code, digest } = this.multihash;
|
|
4923
|
+
const multihash = create(code, digest);
|
|
4924
|
+
return _CID.createV1(this.code, multihash);
|
|
5119
4925
|
}
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
carry += BASE * b256[it3] >>> 0;
|
|
5123
|
-
b256[it3] = carry % 256 >>> 0;
|
|
5124
|
-
carry = carry / 256 >>> 0;
|
|
4926
|
+
case 1: {
|
|
4927
|
+
return this;
|
|
5125
4928
|
}
|
|
5126
|
-
|
|
5127
|
-
throw
|
|
4929
|
+
default: {
|
|
4930
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
5128
4931
|
}
|
|
5129
|
-
length2 = i2;
|
|
5130
|
-
psz++;
|
|
5131
|
-
}
|
|
5132
|
-
if (source[psz] === " ") {
|
|
5133
|
-
return;
|
|
5134
|
-
}
|
|
5135
|
-
var it4 = size - length2;
|
|
5136
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
5137
|
-
it4++;
|
|
5138
|
-
}
|
|
5139
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
5140
|
-
var j2 = zeroes;
|
|
5141
|
-
while (it4 !== size) {
|
|
5142
|
-
vch[j2++] = b256[it4++];
|
|
5143
4932
|
}
|
|
5144
|
-
return vch;
|
|
5145
4933
|
}
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
if (buffer) {
|
|
5149
|
-
return buffer;
|
|
5150
|
-
}
|
|
5151
|
-
throw new Error(`Non-${name} character`);
|
|
4934
|
+
equals(other) {
|
|
4935
|
+
return _CID.equals(this, other);
|
|
5152
4936
|
}
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
decode: decode5
|
|
5157
|
-
};
|
|
5158
|
-
}
|
|
5159
|
-
var src = base2;
|
|
5160
|
-
var _brrp__multiformats_scope_baseX = src;
|
|
5161
|
-
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
5162
|
-
|
|
5163
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
|
|
5164
|
-
var Encoder = class {
|
|
5165
|
-
constructor(name, prefix, baseEncode) {
|
|
5166
|
-
__publicField(this, "name");
|
|
5167
|
-
__publicField(this, "prefix");
|
|
5168
|
-
__publicField(this, "baseEncode");
|
|
5169
|
-
this.name = name;
|
|
5170
|
-
this.prefix = prefix;
|
|
5171
|
-
this.baseEncode = baseEncode;
|
|
4937
|
+
static equals(self, other) {
|
|
4938
|
+
const unknown = other;
|
|
4939
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
5172
4940
|
}
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
4941
|
+
toString(base3) {
|
|
4942
|
+
return format(this, base3);
|
|
4943
|
+
}
|
|
4944
|
+
toJSON() {
|
|
4945
|
+
return { "/": format(this) };
|
|
4946
|
+
}
|
|
4947
|
+
link() {
|
|
4948
|
+
return this;
|
|
4949
|
+
}
|
|
4950
|
+
// Legacy
|
|
4951
|
+
[(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
|
|
4952
|
+
return `CID(${this.toString()})`;
|
|
4953
|
+
}
|
|
4954
|
+
/**
|
|
4955
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
4956
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
4957
|
+
* it will return value back. If `value` is not instance of this CID
|
|
4958
|
+
* class, but is compatible CID it will return new instance of this
|
|
4959
|
+
* `CID` class. Otherwise returns null.
|
|
4960
|
+
*
|
|
4961
|
+
* This allows two different incompatible versions of CID library to
|
|
4962
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
4963
|
+
*/
|
|
4964
|
+
static asCID(input) {
|
|
4965
|
+
if (input == null) {
|
|
4966
|
+
return null;
|
|
4967
|
+
}
|
|
4968
|
+
const value = input;
|
|
4969
|
+
if (value instanceof _CID) {
|
|
4970
|
+
return value;
|
|
4971
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
4972
|
+
const { version, code, multihash, bytes } = value;
|
|
4973
|
+
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
4974
|
+
} else if (value[cidSymbol] === true) {
|
|
4975
|
+
const { version, multihash, code } = value;
|
|
4976
|
+
const digest = decode4(multihash);
|
|
4977
|
+
return _CID.create(version, code, digest);
|
|
5176
4978
|
} else {
|
|
5177
|
-
|
|
4979
|
+
return null;
|
|
5178
4980
|
}
|
|
5179
4981
|
}
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
this.prefix = prefix;
|
|
5189
|
-
if (prefix.codePointAt(0) === void 0) {
|
|
5190
|
-
throw new Error("Invalid prefix character");
|
|
4982
|
+
/**
|
|
4983
|
+
* @param version - Version of the CID
|
|
4984
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
4985
|
+
* @param digest - (Multi)hash of the of the content.
|
|
4986
|
+
*/
|
|
4987
|
+
static create(version, code, digest) {
|
|
4988
|
+
if (typeof code !== "number") {
|
|
4989
|
+
throw new Error("String codecs are no longer supported");
|
|
5191
4990
|
}
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
4991
|
+
if (!(digest.bytes instanceof Uint8Array)) {
|
|
4992
|
+
throw new Error("Invalid digest");
|
|
4993
|
+
}
|
|
4994
|
+
switch (version) {
|
|
4995
|
+
case 0: {
|
|
4996
|
+
if (code !== DAG_PB_CODE) {
|
|
4997
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
4998
|
+
} else {
|
|
4999
|
+
return new _CID(version, code, digest, digest.bytes);
|
|
5000
|
+
}
|
|
5001
|
+
}
|
|
5002
|
+
case 1: {
|
|
5003
|
+
const bytes = encodeCID(version, code, digest.bytes);
|
|
5004
|
+
return new _CID(version, code, digest, bytes);
|
|
5005
|
+
}
|
|
5006
|
+
default: {
|
|
5007
|
+
throw new Error("Invalid version");
|
|
5199
5008
|
}
|
|
5200
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
5201
|
-
} else {
|
|
5202
|
-
throw Error("Can only multibase decode strings");
|
|
5203
5009
|
}
|
|
5204
5010
|
}
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
constructor(decoders) {
|
|
5211
|
-
__publicField(this, "decoders");
|
|
5212
|
-
this.decoders = decoders;
|
|
5011
|
+
/**
|
|
5012
|
+
* Simplified version of `create` for CIDv0.
|
|
5013
|
+
*/
|
|
5014
|
+
static createV0(digest) {
|
|
5015
|
+
return _CID.create(0, DAG_PB_CODE, digest);
|
|
5213
5016
|
}
|
|
5214
|
-
|
|
5215
|
-
|
|
5017
|
+
/**
|
|
5018
|
+
* Simplified version of `create` for CIDv1.
|
|
5019
|
+
*
|
|
5020
|
+
* @param code - Content encoding format code.
|
|
5021
|
+
* @param digest - Multihash of the content.
|
|
5022
|
+
*/
|
|
5023
|
+
static createV1(code, digest) {
|
|
5024
|
+
return _CID.create(1, code, digest);
|
|
5216
5025
|
}
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5026
|
+
/**
|
|
5027
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
5028
|
+
* only the CID with no additional bytes.
|
|
5029
|
+
*
|
|
5030
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
5031
|
+
* binary representation of a CID.
|
|
5032
|
+
*/
|
|
5033
|
+
static decode(bytes) {
|
|
5034
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
5035
|
+
if (remainder.length !== 0) {
|
|
5036
|
+
throw new Error("Incorrect length");
|
|
5224
5037
|
}
|
|
5038
|
+
return cid;
|
|
5225
5039
|
}
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
5040
|
+
/**
|
|
5041
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
5042
|
+
* array.
|
|
5043
|
+
*
|
|
5044
|
+
* Returns an array with the first element containing the CID and the second
|
|
5045
|
+
* element containing the remainder of the original byte array. The remainder
|
|
5046
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
5047
|
+
* binary CID representation.
|
|
5048
|
+
*/
|
|
5049
|
+
static decodeFirst(bytes) {
|
|
5050
|
+
const specs = _CID.inspectBytes(bytes);
|
|
5051
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
5052
|
+
const multihashBytes = coerce2(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
5053
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
5054
|
+
throw new Error("Incorrect length");
|
|
5055
|
+
}
|
|
5056
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
5057
|
+
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
5058
|
+
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
5059
|
+
return [cid, bytes.subarray(specs.size)];
|
|
5247
5060
|
}
|
|
5248
|
-
|
|
5249
|
-
|
|
5061
|
+
/**
|
|
5062
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
5063
|
+
*
|
|
5064
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
5065
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
5066
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
5067
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
5068
|
+
* inspection.
|
|
5069
|
+
*/
|
|
5070
|
+
static inspectBytes(initialBytes) {
|
|
5071
|
+
let offset = 0;
|
|
5072
|
+
const next = () => {
|
|
5073
|
+
const [i, length2] = decode3(initialBytes.subarray(offset));
|
|
5074
|
+
offset += length2;
|
|
5075
|
+
return i;
|
|
5076
|
+
};
|
|
5077
|
+
let version = next();
|
|
5078
|
+
let codec = DAG_PB_CODE;
|
|
5079
|
+
if (version === 18) {
|
|
5080
|
+
version = 0;
|
|
5081
|
+
offset = 0;
|
|
5082
|
+
} else {
|
|
5083
|
+
codec = next();
|
|
5084
|
+
}
|
|
5085
|
+
if (version !== 0 && version !== 1) {
|
|
5086
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
5087
|
+
}
|
|
5088
|
+
const prefixSize = offset;
|
|
5089
|
+
const multihashCode = next();
|
|
5090
|
+
const digestSize = next();
|
|
5091
|
+
const size = offset + digestSize;
|
|
5092
|
+
const multihashSize = size - prefixSize;
|
|
5093
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
5250
5094
|
}
|
|
5251
|
-
|
|
5252
|
-
|
|
5095
|
+
/**
|
|
5096
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
5097
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
5098
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
5099
|
+
* a default decoder).
|
|
5100
|
+
*/
|
|
5101
|
+
static parse(source, base3) {
|
|
5102
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
5103
|
+
const cid = _CID.decode(bytes);
|
|
5104
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
5105
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
5106
|
+
}
|
|
5107
|
+
baseCache(cid).set(prefix, source);
|
|
5108
|
+
return cid;
|
|
5253
5109
|
}
|
|
5254
5110
|
};
|
|
5255
|
-
function
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
encode: encode3,
|
|
5264
|
-
decode: (text) => coerce4(decode5(text))
|
|
5265
|
-
});
|
|
5266
|
-
}
|
|
5267
|
-
function decode(string, alphabet, bitsPerChar, name) {
|
|
5268
|
-
const codes = {};
|
|
5269
|
-
for (let i = 0; i < alphabet.length; ++i) {
|
|
5270
|
-
codes[alphabet[i]] = i;
|
|
5271
|
-
}
|
|
5272
|
-
let end = string.length;
|
|
5273
|
-
while (string[end - 1] === "=") {
|
|
5274
|
-
--end;
|
|
5275
|
-
}
|
|
5276
|
-
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
5277
|
-
let bits = 0;
|
|
5278
|
-
let buffer = 0;
|
|
5279
|
-
let written = 0;
|
|
5280
|
-
for (let i = 0; i < end; ++i) {
|
|
5281
|
-
const value = codes[string[i]];
|
|
5282
|
-
if (value === void 0) {
|
|
5283
|
-
throw new SyntaxError(`Non-${name} character`);
|
|
5111
|
+
function parseCIDtoBytes(source, base3) {
|
|
5112
|
+
switch (source[0]) {
|
|
5113
|
+
case "Q": {
|
|
5114
|
+
const decoder = base3 ?? base58btc;
|
|
5115
|
+
return [
|
|
5116
|
+
base58btc.prefix,
|
|
5117
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
5118
|
+
];
|
|
5284
5119
|
}
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
bits -= 8;
|
|
5289
|
-
out[written++] = 255 & buffer >> bits;
|
|
5120
|
+
case base58btc.prefix: {
|
|
5121
|
+
const decoder = base3 ?? base58btc;
|
|
5122
|
+
return [base58btc.prefix, decoder.decode(source)];
|
|
5290
5123
|
}
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
}
|
|
5295
|
-
return out;
|
|
5296
|
-
}
|
|
5297
|
-
function encode(data, alphabet, bitsPerChar) {
|
|
5298
|
-
const pad = alphabet[alphabet.length - 1] === "=";
|
|
5299
|
-
const mask = (1 << bitsPerChar) - 1;
|
|
5300
|
-
let out = "";
|
|
5301
|
-
let bits = 0;
|
|
5302
|
-
let buffer = 0;
|
|
5303
|
-
for (let i = 0; i < data.length; ++i) {
|
|
5304
|
-
buffer = buffer << 8 | data[i];
|
|
5305
|
-
bits += 8;
|
|
5306
|
-
while (bits > bitsPerChar) {
|
|
5307
|
-
bits -= bitsPerChar;
|
|
5308
|
-
out += alphabet[mask & buffer >> bits];
|
|
5124
|
+
case base32.prefix: {
|
|
5125
|
+
const decoder = base3 ?? base32;
|
|
5126
|
+
return [base32.prefix, decoder.decode(source)];
|
|
5309
5127
|
}
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
5316
|
-
out += "=";
|
|
5128
|
+
default: {
|
|
5129
|
+
if (base3 == null) {
|
|
5130
|
+
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
5131
|
+
}
|
|
5132
|
+
return [source[0], base3.decode(source)];
|
|
5317
5133
|
}
|
|
5318
5134
|
}
|
|
5319
|
-
return out;
|
|
5320
|
-
}
|
|
5321
|
-
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
5322
|
-
return from({
|
|
5323
|
-
prefix,
|
|
5324
|
-
name,
|
|
5325
|
-
encode(input) {
|
|
5326
|
-
return encode(input, alphabet, bitsPerChar);
|
|
5327
|
-
},
|
|
5328
|
-
decode(input) {
|
|
5329
|
-
return decode(input, alphabet, bitsPerChar, name);
|
|
5330
|
-
}
|
|
5331
|
-
});
|
|
5332
5135
|
}
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
name: "base32",
|
|
5338
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
5339
|
-
bitsPerChar: 5
|
|
5340
|
-
});
|
|
5341
|
-
var base32upper = rfc4648({
|
|
5342
|
-
prefix: "B",
|
|
5343
|
-
name: "base32upper",
|
|
5344
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
5345
|
-
bitsPerChar: 5
|
|
5346
|
-
});
|
|
5347
|
-
var base32pad = rfc4648({
|
|
5348
|
-
prefix: "c",
|
|
5349
|
-
name: "base32pad",
|
|
5350
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
5351
|
-
bitsPerChar: 5
|
|
5352
|
-
});
|
|
5353
|
-
var base32padupper = rfc4648({
|
|
5354
|
-
prefix: "C",
|
|
5355
|
-
name: "base32padupper",
|
|
5356
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
5357
|
-
bitsPerChar: 5
|
|
5358
|
-
});
|
|
5359
|
-
var base32hex = rfc4648({
|
|
5360
|
-
prefix: "v",
|
|
5361
|
-
name: "base32hex",
|
|
5362
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
5363
|
-
bitsPerChar: 5
|
|
5364
|
-
});
|
|
5365
|
-
var base32hexupper = rfc4648({
|
|
5366
|
-
prefix: "V",
|
|
5367
|
-
name: "base32hexupper",
|
|
5368
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
5369
|
-
bitsPerChar: 5
|
|
5370
|
-
});
|
|
5371
|
-
var base32hexpad = rfc4648({
|
|
5372
|
-
prefix: "t",
|
|
5373
|
-
name: "base32hexpad",
|
|
5374
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
5375
|
-
bitsPerChar: 5
|
|
5376
|
-
});
|
|
5377
|
-
var base32hexpadupper = rfc4648({
|
|
5378
|
-
prefix: "T",
|
|
5379
|
-
name: "base32hexpadupper",
|
|
5380
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
5381
|
-
bitsPerChar: 5
|
|
5382
|
-
});
|
|
5383
|
-
var base32z = rfc4648({
|
|
5384
|
-
prefix: "h",
|
|
5385
|
-
name: "base32z",
|
|
5386
|
-
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
5387
|
-
bitsPerChar: 5
|
|
5388
|
-
});
|
|
5389
|
-
|
|
5390
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
5391
|
-
var base58btc = baseX({
|
|
5392
|
-
name: "base58btc",
|
|
5393
|
-
prefix: "z",
|
|
5394
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
5395
|
-
});
|
|
5396
|
-
var base58flickr = baseX({
|
|
5397
|
-
name: "base58flickr",
|
|
5398
|
-
prefix: "Z",
|
|
5399
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
5400
|
-
});
|
|
5401
|
-
|
|
5402
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
|
|
5403
|
-
var encode_1 = encode2;
|
|
5404
|
-
var MSB = 128;
|
|
5405
|
-
var REST = 127;
|
|
5406
|
-
var MSBALL = ~REST;
|
|
5407
|
-
var INT = Math.pow(2, 31);
|
|
5408
|
-
function encode2(num, out, offset) {
|
|
5409
|
-
out = out || [];
|
|
5410
|
-
offset = offset || 0;
|
|
5411
|
-
var oldOffset = offset;
|
|
5412
|
-
while (num >= INT) {
|
|
5413
|
-
out[offset++] = num & 255 | MSB;
|
|
5414
|
-
num /= 128;
|
|
5136
|
+
function toStringV0(bytes, cache2, base3) {
|
|
5137
|
+
const { prefix } = base3;
|
|
5138
|
+
if (prefix !== base58btc.prefix) {
|
|
5139
|
+
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
5415
5140
|
}
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5141
|
+
const cid = cache2.get(prefix);
|
|
5142
|
+
if (cid == null) {
|
|
5143
|
+
const cid2 = base3.encode(bytes).slice(1);
|
|
5144
|
+
cache2.set(prefix, cid2);
|
|
5145
|
+
return cid2;
|
|
5146
|
+
} else {
|
|
5147
|
+
return cid;
|
|
5419
5148
|
}
|
|
5420
|
-
out[offset] = num | 0;
|
|
5421
|
-
encode2.bytes = offset - oldOffset + 1;
|
|
5422
|
-
return out;
|
|
5423
|
-
}
|
|
5424
|
-
var decode2 = read;
|
|
5425
|
-
var MSB$1 = 128;
|
|
5426
|
-
var REST$1 = 127;
|
|
5427
|
-
function read(buf, offset) {
|
|
5428
|
-
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
5429
|
-
do {
|
|
5430
|
-
if (counter >= l) {
|
|
5431
|
-
read.bytes = 0;
|
|
5432
|
-
throw new RangeError("Could not decode varint");
|
|
5433
|
-
}
|
|
5434
|
-
b = buf[counter++];
|
|
5435
|
-
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
5436
|
-
shift += 7;
|
|
5437
|
-
} while (b >= MSB$1);
|
|
5438
|
-
read.bytes = counter - offset;
|
|
5439
|
-
return res;
|
|
5440
|
-
}
|
|
5441
|
-
var N1 = Math.pow(2, 7);
|
|
5442
|
-
var N2 = Math.pow(2, 14);
|
|
5443
|
-
var N3 = Math.pow(2, 21);
|
|
5444
|
-
var N4 = Math.pow(2, 28);
|
|
5445
|
-
var N5 = Math.pow(2, 35);
|
|
5446
|
-
var N6 = Math.pow(2, 42);
|
|
5447
|
-
var N7 = Math.pow(2, 49);
|
|
5448
|
-
var N8 = Math.pow(2, 56);
|
|
5449
|
-
var N9 = Math.pow(2, 63);
|
|
5450
|
-
var length = function(value) {
|
|
5451
|
-
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;
|
|
5452
|
-
};
|
|
5453
|
-
var varint = {
|
|
5454
|
-
encode: encode_1,
|
|
5455
|
-
decode: decode2,
|
|
5456
|
-
encodingLength: length
|
|
5457
|
-
};
|
|
5458
|
-
var _brrp_varint = varint;
|
|
5459
|
-
var varint_default = _brrp_varint;
|
|
5460
|
-
|
|
5461
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
|
|
5462
|
-
function decode3(data, offset = 0) {
|
|
5463
|
-
const code = varint_default.decode(data, offset);
|
|
5464
|
-
return [code, varint_default.decode.bytes];
|
|
5465
5149
|
}
|
|
5466
|
-
function
|
|
5467
|
-
|
|
5468
|
-
|
|
5150
|
+
function toStringV1(bytes, cache2, base3) {
|
|
5151
|
+
const { prefix } = base3;
|
|
5152
|
+
const cid = cache2.get(prefix);
|
|
5153
|
+
if (cid == null) {
|
|
5154
|
+
const cid2 = base3.encode(bytes);
|
|
5155
|
+
cache2.set(prefix, cid2);
|
|
5156
|
+
return cid2;
|
|
5157
|
+
} else {
|
|
5158
|
+
return cid;
|
|
5159
|
+
}
|
|
5469
5160
|
}
|
|
5470
|
-
|
|
5471
|
-
|
|
5161
|
+
var DAG_PB_CODE = 112;
|
|
5162
|
+
var SHA_256_CODE = 18;
|
|
5163
|
+
function encodeCID(version, code, multihash) {
|
|
5164
|
+
const codeOffset = encodingLength(version);
|
|
5165
|
+
const hashOffset = codeOffset + encodingLength(code);
|
|
5166
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
5167
|
+
encodeTo(version, bytes, 0);
|
|
5168
|
+
encodeTo(code, bytes, codeOffset);
|
|
5169
|
+
bytes.set(multihash, hashOffset);
|
|
5170
|
+
return bytes;
|
|
5472
5171
|
}
|
|
5172
|
+
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
5473
5173
|
|
|
5474
|
-
//
|
|
5475
|
-
function
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
encodeTo(code, bytes, 0);
|
|
5481
|
-
encodeTo(size, bytes, sizeOffset);
|
|
5482
|
-
bytes.set(digest, digestOffset);
|
|
5483
|
-
return new Digest(code, size, digest, bytes);
|
|
5484
|
-
}
|
|
5485
|
-
function decode4(multihash) {
|
|
5486
|
-
const bytes = coerce4(multihash);
|
|
5487
|
-
const [code, sizeOffset] = decode3(bytes);
|
|
5488
|
-
const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
|
|
5489
|
-
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
5490
|
-
if (digest.byteLength !== size) {
|
|
5491
|
-
throw new Error("Incorrect length");
|
|
5492
|
-
}
|
|
5493
|
-
return new Digest(code, size, digest, bytes);
|
|
5494
|
-
}
|
|
5495
|
-
function equals2(a, b) {
|
|
5496
|
-
if (a === b) {
|
|
5174
|
+
// src/ipfs/ipfs.ts
|
|
5175
|
+
function isCID(str) {
|
|
5176
|
+
if (!str)
|
|
5177
|
+
return false;
|
|
5178
|
+
try {
|
|
5179
|
+
CID.parse(str);
|
|
5497
5180
|
return true;
|
|
5498
|
-
}
|
|
5499
|
-
|
|
5500
|
-
|
|
5181
|
+
} catch (e) {
|
|
5182
|
+
if (/^(bafy|Qm)/.test(str))
|
|
5183
|
+
return true;
|
|
5184
|
+
return false;
|
|
5501
5185
|
}
|
|
5502
5186
|
}
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
}
|
|
5518
|
-
|
|
5519
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
|
|
5520
|
-
function format(link, base3) {
|
|
5521
|
-
const { bytes, version } = link;
|
|
5522
|
-
switch (version) {
|
|
5523
|
-
case 0:
|
|
5524
|
-
return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
|
|
5525
|
-
default:
|
|
5526
|
-
return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
|
|
5187
|
+
function normalizeIPFSUrl(url) {
|
|
5188
|
+
if (!url || typeof url !== "string")
|
|
5189
|
+
return null;
|
|
5190
|
+
url = url.replace(/"/g, "");
|
|
5191
|
+
if (isNormalizedIPFSURL(url))
|
|
5192
|
+
return url;
|
|
5193
|
+
if (isCID(url))
|
|
5194
|
+
return `ipfs://${url}`;
|
|
5195
|
+
if (!isIPFSUrl(url))
|
|
5196
|
+
return null;
|
|
5197
|
+
if (isGatewayIPFSUrl(url)) {
|
|
5198
|
+
const parsed = new URL(url.replace(/^\/\//, "http://"));
|
|
5199
|
+
parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
|
|
5200
|
+
const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
|
|
5201
|
+
return `ipfs://${cid}`;
|
|
5527
5202
|
}
|
|
5203
|
+
return null;
|
|
5528
5204
|
}
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
const baseCache2 = cache.get(cid);
|
|
5532
|
-
if (baseCache2 == null) {
|
|
5533
|
-
const baseCache3 = /* @__PURE__ */ new Map();
|
|
5534
|
-
cache.set(cid, baseCache3);
|
|
5535
|
-
return baseCache3;
|
|
5536
|
-
}
|
|
5537
|
-
return baseCache2;
|
|
5205
|
+
function isNormalizedIPFSURL(url) {
|
|
5206
|
+
return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
|
|
5538
5207
|
}
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
__publicField(this, "code");
|
|
5548
|
-
__publicField(this, "version");
|
|
5549
|
-
__publicField(this, "multihash");
|
|
5550
|
-
__publicField(this, "bytes");
|
|
5551
|
-
__publicField(this, "/");
|
|
5552
|
-
__publicField(this, _a, "CID");
|
|
5553
|
-
this.code = code;
|
|
5554
|
-
this.version = version;
|
|
5555
|
-
this.multihash = multihash;
|
|
5556
|
-
this.bytes = bytes;
|
|
5557
|
-
this["/"] = bytes;
|
|
5208
|
+
function isGatewayIPFSUrl(url) {
|
|
5209
|
+
if (url && typeof url === "string") {
|
|
5210
|
+
try {
|
|
5211
|
+
const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
|
|
5212
|
+
return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
|
|
5213
|
+
} catch {
|
|
5214
|
+
return false;
|
|
5215
|
+
}
|
|
5558
5216
|
}
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5217
|
+
return false;
|
|
5218
|
+
}
|
|
5219
|
+
function isIPFSUrl(url) {
|
|
5220
|
+
return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
|
|
5221
|
+
}
|
|
5222
|
+
function isNormalizeableIPFSUrl(url) {
|
|
5223
|
+
return url ? isIPFSUrl(url) || isCID(url) : false;
|
|
5224
|
+
}
|
|
5225
|
+
|
|
5226
|
+
// src/ipfs/gateway.ts
|
|
5227
|
+
var IPFS_GATEWAY = "https://magic.decentralized-content.com";
|
|
5228
|
+
var ARWEAVE_GATEWAY = "https://arweave.net";
|
|
5229
|
+
function arweaveGatewayUrl(normalizedArweaveUrl) {
|
|
5230
|
+
if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
|
|
5231
|
+
return null;
|
|
5232
|
+
return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
|
|
5233
|
+
}
|
|
5234
|
+
function ipfsGatewayUrl(url) {
|
|
5235
|
+
if (!url || typeof url !== "string")
|
|
5236
|
+
return null;
|
|
5237
|
+
const normalizedIPFSUrl = normalizeIPFSUrl(url);
|
|
5238
|
+
if (normalizedIPFSUrl) {
|
|
5239
|
+
return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
|
|
5567
5240
|
}
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5241
|
+
return null;
|
|
5242
|
+
}
|
|
5243
|
+
function getFetchableUrl(uri) {
|
|
5244
|
+
if (!uri || typeof uri !== "string")
|
|
5245
|
+
return null;
|
|
5246
|
+
if (uri.startsWith("http://"))
|
|
5247
|
+
return null;
|
|
5248
|
+
if (isNormalizeableIPFSUrl(uri)) {
|
|
5249
|
+
return ipfsGatewayUrl(uri);
|
|
5571
5250
|
}
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
return this.bytes.byteLength;
|
|
5251
|
+
if (isArweaveURL(uri)) {
|
|
5252
|
+
return arweaveGatewayUrl(uri);
|
|
5575
5253
|
}
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
case 0: {
|
|
5579
|
-
return this;
|
|
5580
|
-
}
|
|
5581
|
-
case 1: {
|
|
5582
|
-
const { code, multihash } = this;
|
|
5583
|
-
if (code !== DAG_PB_CODE) {
|
|
5584
|
-
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
5585
|
-
}
|
|
5586
|
-
if (multihash.code !== SHA_256_CODE) {
|
|
5587
|
-
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
5588
|
-
}
|
|
5589
|
-
return _CID.createV0(multihash);
|
|
5590
|
-
}
|
|
5591
|
-
default: {
|
|
5592
|
-
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
5593
|
-
}
|
|
5594
|
-
}
|
|
5254
|
+
if (/^(https|data|blob):/.test(uri)) {
|
|
5255
|
+
return uri;
|
|
5595
5256
|
}
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5257
|
+
return null;
|
|
5258
|
+
}
|
|
5259
|
+
|
|
5260
|
+
// src/ipfs/mimeTypes.ts
|
|
5261
|
+
var HTML = "text/html";
|
|
5262
|
+
var MARKDOWN = "text/markdown";
|
|
5263
|
+
var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
|
|
5264
|
+
var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
|
|
5265
|
+
var TEXT_PLAIN = "text/plain";
|
|
5266
|
+
var CSV = "text/csv";
|
|
5267
|
+
var NUMBERS = ".numbers";
|
|
5268
|
+
var EXCEL = ".xlsx";
|
|
5269
|
+
var PDF = "application/pdf";
|
|
5270
|
+
var JPG = "image/jpg";
|
|
5271
|
+
var JPEG = "image/jpeg";
|
|
5272
|
+
var PNG = "image/png";
|
|
5273
|
+
var WEBP = "image/webp";
|
|
5274
|
+
var SVG = "image/svg+xml";
|
|
5275
|
+
var TIFF = "image/tiff";
|
|
5276
|
+
var GIF = "image/gif";
|
|
5277
|
+
var isImage = (mimeType) => {
|
|
5278
|
+
if (!mimeType)
|
|
5279
|
+
return false;
|
|
5280
|
+
return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
|
|
5281
|
+
};
|
|
5282
|
+
var DEFAULT_THUMBNAIL_CID_HASHES = {
|
|
5283
|
+
["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
|
|
5284
|
+
["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
|
|
5285
|
+
["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
|
|
5286
|
+
["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
|
|
5287
|
+
// assuming all zip files are html directories
|
|
5288
|
+
["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
|
|
5289
|
+
default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
|
|
5290
|
+
};
|
|
5291
|
+
var MP4 = "video/mp4";
|
|
5292
|
+
var QUICKTIME = "video/quicktime";
|
|
5293
|
+
var M4V = "video/x-m4v";
|
|
5294
|
+
var WEBM = "video/webm";
|
|
5295
|
+
var M4A = "audio/x-m4a";
|
|
5296
|
+
var MPEG = "audio/mpeg";
|
|
5297
|
+
var MP3 = "audio/mp3";
|
|
5298
|
+
var WAV = "audio/wav";
|
|
5299
|
+
var VND_WAV = "audio/vnd.wav";
|
|
5300
|
+
var VND_WAVE = "audio/vnd.wave";
|
|
5301
|
+
var WAVE = "audio/wave";
|
|
5302
|
+
var X_WAV = "audio/x-wav";
|
|
5303
|
+
var AIFF = "audio/aiff";
|
|
5304
|
+
var GLTF = "model/gltf+json";
|
|
5305
|
+
var GLB = "model/gltf-binary";
|
|
5306
|
+
var GLTF_EXT = ".gltf";
|
|
5307
|
+
var GLB_EXT = ".glb";
|
|
5308
|
+
var JSON_MIME_TYPE = "application/json";
|
|
5309
|
+
var ZIP = "application/zip";
|
|
5310
|
+
var mimeToMediaType = {
|
|
5311
|
+
[HTML]: "HTML" /* HTML */,
|
|
5312
|
+
[JPG]: "IMAGE" /* IMAGE */,
|
|
5313
|
+
[JPEG]: "IMAGE" /* IMAGE */,
|
|
5314
|
+
[PNG]: "IMAGE" /* IMAGE */,
|
|
5315
|
+
[WEBP]: "IMAGE" /* IMAGE */,
|
|
5316
|
+
[SVG]: "IMAGE" /* IMAGE */,
|
|
5317
|
+
[TIFF]: "TIFF" /* TIFF */,
|
|
5318
|
+
[GIF]: "IMAGE" /* IMAGE */,
|
|
5319
|
+
[MP4]: "VIDEO" /* VIDEO */,
|
|
5320
|
+
[WEBM]: "VIDEO" /* VIDEO */,
|
|
5321
|
+
[QUICKTIME]: "VIDEO" /* VIDEO */,
|
|
5322
|
+
[M4V]: "VIDEO" /* VIDEO */,
|
|
5323
|
+
[MPEG]: "AUDIO" /* AUDIO */,
|
|
5324
|
+
[MP3]: "AUDIO" /* AUDIO */,
|
|
5325
|
+
[M4A]: "AUDIO" /* AUDIO */,
|
|
5326
|
+
[VND_WAV]: "AUDIO" /* AUDIO */,
|
|
5327
|
+
[VND_WAVE]: "AUDIO" /* AUDIO */,
|
|
5328
|
+
[WAV]: "AUDIO" /* AUDIO */,
|
|
5329
|
+
[WAVE]: "AUDIO" /* AUDIO */,
|
|
5330
|
+
[X_WAV]: "AUDIO" /* AUDIO */,
|
|
5331
|
+
[AIFF]: "AUDIO" /* AUDIO */,
|
|
5332
|
+
[TEXT_PLAIN]: "TEXT" /* TEXT */,
|
|
5333
|
+
[TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
|
|
5334
|
+
[MARKDOWN]: "TEXT" /* TEXT */,
|
|
5335
|
+
[MARKDOWN_UTF8]: "TEXT" /* TEXT */,
|
|
5336
|
+
[CSV]: "CSV" /* CSV */,
|
|
5337
|
+
[NUMBERS]: "NUMBERS" /* NUMBERS */,
|
|
5338
|
+
[EXCEL]: "EXCEL" /* EXCEL */,
|
|
5339
|
+
[PDF]: "PDF" /* PDF */,
|
|
5340
|
+
[ZIP]: "ZIP" /* ZIP */,
|
|
5341
|
+
[GLTF]: "MODEL" /* MODEL */,
|
|
5342
|
+
[GLTF_EXT]: "MODEL" /* MODEL */,
|
|
5343
|
+
[GLB]: "MODEL" /* MODEL */,
|
|
5344
|
+
// GLTF returns 'application/json' as the mimetype,
|
|
5345
|
+
// and as the only JSON-encoded media we currently support,
|
|
5346
|
+
// we assume that if the mimetype is JSON, it's a GLTF
|
|
5347
|
+
[JSON_MIME_TYPE]: "MODEL" /* MODEL */,
|
|
5348
|
+
[GLB_EXT]: "MODEL" /* MODEL */
|
|
5349
|
+
};
|
|
5350
|
+
function mimeTypeToMedia(mimeType) {
|
|
5351
|
+
if (!mimeType)
|
|
5352
|
+
return "UNKNOWN" /* UNKNOWN */;
|
|
5353
|
+
return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
|
|
5354
|
+
}
|
|
5355
|
+
async function getMimeType(uri) {
|
|
5356
|
+
if (!uri)
|
|
5357
|
+
return uri;
|
|
5358
|
+
const res = await fetch(uri, { method: "HEAD" });
|
|
5359
|
+
let mimeType = res.headers.get("content-type");
|
|
5360
|
+
return mimeType;
|
|
5361
|
+
}
|
|
5362
|
+
|
|
5363
|
+
// src/ipfs/token-metadata.ts
|
|
5364
|
+
var makeTextTokenMetadata = (parameters) => {
|
|
5365
|
+
const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
|
|
5366
|
+
const content = textFileUrl ? {
|
|
5367
|
+
mime: TEXT_PLAIN,
|
|
5368
|
+
uri: textFileUrl
|
|
5369
|
+
} : null;
|
|
5370
|
+
const image = thumbnailUrl;
|
|
5371
|
+
const animation_url = textFileUrl;
|
|
5372
|
+
return {
|
|
5373
|
+
name,
|
|
5374
|
+
image,
|
|
5375
|
+
animation_url,
|
|
5376
|
+
content,
|
|
5377
|
+
attributes
|
|
5378
|
+
};
|
|
5379
|
+
};
|
|
5380
|
+
var makeMediaTokenMetadata = async ({
|
|
5381
|
+
name,
|
|
5382
|
+
description,
|
|
5383
|
+
attributes = [],
|
|
5384
|
+
mediaUrl,
|
|
5385
|
+
thumbnailUrl
|
|
5386
|
+
}) => {
|
|
5387
|
+
const contentUrl = mediaUrl;
|
|
5388
|
+
const fetchableContentUrl = getFetchableUrl(contentUrl);
|
|
5389
|
+
if (!fetchableContentUrl)
|
|
5390
|
+
throw new Error(`Content url (${contentUrl}) is not fetchable`);
|
|
5391
|
+
const mimeType = await getMimeType(fetchableContentUrl);
|
|
5392
|
+
const mediaType = mimeTypeToMedia(mimeType);
|
|
5393
|
+
let image = void 0;
|
|
5394
|
+
let animation_url = null;
|
|
5395
|
+
if (isImage(mimeType)) {
|
|
5396
|
+
image = contentUrl;
|
|
5397
|
+
} else {
|
|
5398
|
+
image = thumbnailUrl;
|
|
5399
|
+
animation_url = mediaUrl;
|
|
5610
5400
|
}
|
|
5611
|
-
|
|
5612
|
-
|
|
5401
|
+
if (!image)
|
|
5402
|
+
image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
|
|
5403
|
+
const content = contentUrl ? {
|
|
5404
|
+
mime: mimeType || "application/octet-stream",
|
|
5405
|
+
uri: contentUrl
|
|
5406
|
+
} : null;
|
|
5407
|
+
return {
|
|
5408
|
+
name,
|
|
5409
|
+
description,
|
|
5410
|
+
image,
|
|
5411
|
+
animation_url,
|
|
5412
|
+
content,
|
|
5413
|
+
attributes
|
|
5414
|
+
};
|
|
5415
|
+
};
|
|
5416
|
+
async function fetchTokenMetadata(tokenMetadataURI) {
|
|
5417
|
+
const fetchableUrl = getFetchableUrl(tokenMetadataURI);
|
|
5418
|
+
if (!fetchableUrl) {
|
|
5419
|
+
throw new Error(`Invalid token metadata URI: ${tokenMetadataURI}`);
|
|
5613
5420
|
}
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5421
|
+
const json = await (await fetch(fetchableUrl)).json();
|
|
5422
|
+
if (!json) {
|
|
5423
|
+
throw new Error(`Failed to fetch metadata from ${fetchableUrl}`);
|
|
5617
5424
|
}
|
|
5618
|
-
|
|
5619
|
-
|
|
5425
|
+
return json;
|
|
5426
|
+
}
|
|
5427
|
+
|
|
5428
|
+
// src/create/minter-defaults.ts
|
|
5429
|
+
var SALE_END_FOREVER = 18446744073709551615n;
|
|
5430
|
+
var DEFAULT_SALE_START_AND_END = {
|
|
5431
|
+
// Sale start time – defaults to beginning of unix time
|
|
5432
|
+
saleStart: 0n,
|
|
5433
|
+
// This is the end of uint64, plenty of time
|
|
5434
|
+
saleEnd: SALE_END_FOREVER
|
|
5435
|
+
};
|
|
5436
|
+
var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
|
|
5437
|
+
maxTokensPerAddress: 0n
|
|
5438
|
+
};
|
|
5439
|
+
var erc20SaleSettingsWithDefaults = (params) => ({
|
|
5440
|
+
...DEFAULT_SALE_START_AND_END,
|
|
5441
|
+
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
5442
|
+
...params
|
|
5443
|
+
});
|
|
5444
|
+
var allowListWithDefaults = (allowlist) => {
|
|
5445
|
+
return {
|
|
5446
|
+
...DEFAULT_SALE_START_AND_END,
|
|
5447
|
+
...allowlist
|
|
5448
|
+
};
|
|
5449
|
+
};
|
|
5450
|
+
var fixedPriceSettingsWithDefaults = (params) => ({
|
|
5451
|
+
...DEFAULT_SALE_START_AND_END,
|
|
5452
|
+
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
5453
|
+
type: "fixedPrice",
|
|
5454
|
+
...params
|
|
5455
|
+
});
|
|
5456
|
+
var parseNameIntoSymbol = (name) => {
|
|
5457
|
+
if (name === "") {
|
|
5458
|
+
throw new Error("Name must be provided to generate a symbol");
|
|
5620
5459
|
}
|
|
5621
|
-
|
|
5622
|
-
|
|
5460
|
+
const result = "$" + name.replace(/[^a-zA-Z0-9]/g, "").replace(/^\$+/, "").toUpperCase().replace(/[AEIOU\s]/g, "").slice(0, 4);
|
|
5461
|
+
if (result === "$") {
|
|
5462
|
+
throw new Error("Not enough valid characters to generate a symbol");
|
|
5623
5463
|
}
|
|
5624
|
-
|
|
5625
|
-
|
|
5464
|
+
return result;
|
|
5465
|
+
};
|
|
5466
|
+
async function fetchTokenNameFromMetadata(tokenMetadataURI) {
|
|
5467
|
+
const tokenMetadata = await fetchTokenMetadata(tokenMetadataURI);
|
|
5468
|
+
if (!tokenMetadata.name) {
|
|
5469
|
+
throw new Error("No name found in token metadata");
|
|
5626
5470
|
}
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5471
|
+
return tokenMetadata.name;
|
|
5472
|
+
}
|
|
5473
|
+
var timedSaleSettingsWithDefaults = async (params, tokenMetadataURI) => {
|
|
5474
|
+
const erc20Name = params.erc20Name || await fetchTokenNameFromMetadata(tokenMetadataURI);
|
|
5475
|
+
const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
|
|
5476
|
+
return {
|
|
5477
|
+
type: "timed",
|
|
5478
|
+
...DEFAULT_SALE_START_AND_END,
|
|
5479
|
+
erc20Name,
|
|
5480
|
+
erc20Symbol: symbol
|
|
5481
|
+
};
|
|
5482
|
+
};
|
|
5483
|
+
var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
5484
|
+
var isErc20 = (salesConfig) => salesConfig.type === "erc20Mint";
|
|
5485
|
+
var isFixedPrice = (salesConfig) => {
|
|
5486
|
+
return salesConfig.pricePerToken > 0n;
|
|
5487
|
+
};
|
|
5488
|
+
var getSalesConfigWithDefaults = async (salesConfig, tokenMetadataURI) => {
|
|
5489
|
+
if (!salesConfig)
|
|
5490
|
+
return timedSaleSettingsWithDefaults({}, tokenMetadataURI);
|
|
5491
|
+
if (isAllowList(salesConfig)) {
|
|
5492
|
+
return allowListWithDefaults(salesConfig);
|
|
5630
5493
|
}
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
5634
|
-
* it will return value back. If `value` is not instance of this CID
|
|
5635
|
-
* class, but is compatible CID it will return new instance of this
|
|
5636
|
-
* `CID` class. Otherwise returns null.
|
|
5637
|
-
*
|
|
5638
|
-
* This allows two different incompatible versions of CID library to
|
|
5639
|
-
* co-exist and interop as long as binary interface is compatible.
|
|
5640
|
-
*/
|
|
5641
|
-
static asCID(input) {
|
|
5642
|
-
if (input == null) {
|
|
5643
|
-
return null;
|
|
5644
|
-
}
|
|
5645
|
-
const value = input;
|
|
5646
|
-
if (value instanceof _CID) {
|
|
5647
|
-
return value;
|
|
5648
|
-
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
5649
|
-
const { version, code, multihash, bytes } = value;
|
|
5650
|
-
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
5651
|
-
} else if (value[cidSymbol] === true) {
|
|
5652
|
-
const { version, multihash, code } = value;
|
|
5653
|
-
const digest = decode4(multihash);
|
|
5654
|
-
return _CID.create(version, code, digest);
|
|
5655
|
-
} else {
|
|
5656
|
-
return null;
|
|
5657
|
-
}
|
|
5494
|
+
if (isErc20(salesConfig)) {
|
|
5495
|
+
return erc20SaleSettingsWithDefaults(salesConfig);
|
|
5658
5496
|
}
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5497
|
+
if (isFixedPrice(salesConfig)) {
|
|
5498
|
+
return fixedPriceSettingsWithDefaults(salesConfig);
|
|
5499
|
+
}
|
|
5500
|
+
return timedSaleSettingsWithDefaults(salesConfig, tokenMetadataURI);
|
|
5501
|
+
};
|
|
5502
|
+
|
|
5503
|
+
// src/create/minter-setup.ts
|
|
5504
|
+
var import_protocol_deployments8 = require("@zoralabs/protocol-deployments");
|
|
5505
|
+
var import_viem7 = require("viem");
|
|
5506
|
+
var PERMISSION_BITS = {
|
|
5507
|
+
MINTER: 2n ** 2n
|
|
5508
|
+
};
|
|
5509
|
+
function setupErc20Minter({
|
|
5510
|
+
pricePerToken,
|
|
5511
|
+
chainId,
|
|
5512
|
+
tokenId: nextTokenId,
|
|
5513
|
+
currency,
|
|
5514
|
+
saleStart,
|
|
5515
|
+
saleEnd,
|
|
5516
|
+
maxTokensPerAddress: mintLimit,
|
|
5517
|
+
fundsRecipient
|
|
5518
|
+
}) {
|
|
5519
|
+
const erc20MinterAddress = import_protocol_deployments8.erc20MinterAddress[chainId];
|
|
5520
|
+
if (!erc20MinterAddress)
|
|
5521
|
+
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
5522
|
+
const erc20MinterApproval = (0, import_viem7.encodeFunctionData)({
|
|
5523
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5524
|
+
functionName: "addPermission",
|
|
5525
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
|
|
5526
|
+
});
|
|
5527
|
+
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
5528
|
+
abi: import_protocol_deployments8.erc20MinterABI,
|
|
5529
|
+
functionName: "setSale",
|
|
5530
|
+
args: [
|
|
5531
|
+
BigInt(nextTokenId),
|
|
5532
|
+
{
|
|
5533
|
+
saleStart: saleStart || BigInt(0),
|
|
5534
|
+
saleEnd: saleEnd || BigInt(0),
|
|
5535
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
5536
|
+
pricePerToken,
|
|
5537
|
+
fundsRecipient,
|
|
5538
|
+
currency
|
|
5678
5539
|
}
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5540
|
+
]
|
|
5541
|
+
});
|
|
5542
|
+
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
5543
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5544
|
+
functionName: "callSale",
|
|
5545
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
|
|
5546
|
+
});
|
|
5547
|
+
return {
|
|
5548
|
+
minter: erc20MinterAddress,
|
|
5549
|
+
setupActions: [erc20MinterApproval, callSale]
|
|
5550
|
+
};
|
|
5551
|
+
}
|
|
5552
|
+
function setupFixedPriceMinter({
|
|
5553
|
+
pricePerToken: price,
|
|
5554
|
+
tokenId: nextTokenId,
|
|
5555
|
+
chainId,
|
|
5556
|
+
saleStart,
|
|
5557
|
+
saleEnd,
|
|
5558
|
+
maxTokensPerAddress: mintLimit,
|
|
5559
|
+
fundsRecipient
|
|
5560
|
+
}) {
|
|
5561
|
+
const fixedPriceStrategyAddress = import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyAddress[chainId];
|
|
5562
|
+
const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
|
|
5563
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5564
|
+
functionName: "addPermission",
|
|
5565
|
+
args: [
|
|
5566
|
+
BigInt(nextTokenId),
|
|
5567
|
+
fixedPriceStrategyAddress,
|
|
5568
|
+
PERMISSION_BITS.MINTER
|
|
5569
|
+
]
|
|
5570
|
+
});
|
|
5571
|
+
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
5572
|
+
abi: import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyABI,
|
|
5573
|
+
functionName: "setSale",
|
|
5574
|
+
args: [
|
|
5575
|
+
BigInt(nextTokenId),
|
|
5576
|
+
{
|
|
5577
|
+
pricePerToken: price,
|
|
5578
|
+
saleStart: saleStart || BigInt(0),
|
|
5579
|
+
saleEnd: saleEnd || BigInt(0),
|
|
5580
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
5581
|
+
fundsRecipient
|
|
5682
5582
|
}
|
|
5683
|
-
|
|
5684
|
-
|
|
5583
|
+
]
|
|
5584
|
+
});
|
|
5585
|
+
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
5586
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5587
|
+
functionName: "callSale",
|
|
5588
|
+
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
|
|
5589
|
+
});
|
|
5590
|
+
return {
|
|
5591
|
+
minter: fixedPriceStrategyAddress,
|
|
5592
|
+
setupActions: [fixedPriceApproval, callSale]
|
|
5593
|
+
};
|
|
5594
|
+
}
|
|
5595
|
+
function setupTimedSaleMinter({
|
|
5596
|
+
chainId,
|
|
5597
|
+
tokenId,
|
|
5598
|
+
erc20Name: erc20zName,
|
|
5599
|
+
erc20Symbol: erc20zSymbol,
|
|
5600
|
+
saleStart,
|
|
5601
|
+
saleEnd
|
|
5602
|
+
}) {
|
|
5603
|
+
const minterAddress = import_protocol_deployments8.zoraTimedSaleStrategyAddress[chainId];
|
|
5604
|
+
const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
|
|
5605
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5606
|
+
functionName: "addPermission",
|
|
5607
|
+
args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER]
|
|
5608
|
+
});
|
|
5609
|
+
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
5610
|
+
abi: import_protocol_deployments8.zoraTimedSaleStrategyABI,
|
|
5611
|
+
functionName: "setSale",
|
|
5612
|
+
args: [
|
|
5613
|
+
BigInt(tokenId),
|
|
5614
|
+
{
|
|
5615
|
+
saleStart,
|
|
5616
|
+
saleEnd,
|
|
5617
|
+
name: erc20zName,
|
|
5618
|
+
symbol: erc20zSymbol
|
|
5685
5619
|
}
|
|
5686
|
-
|
|
5687
|
-
}
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5620
|
+
]
|
|
5621
|
+
});
|
|
5622
|
+
const callSale = (0, import_viem7.encodeFunctionData)({
|
|
5623
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5624
|
+
functionName: "callSale",
|
|
5625
|
+
args: [BigInt(tokenId), minterAddress, saleData]
|
|
5626
|
+
});
|
|
5627
|
+
return {
|
|
5628
|
+
minter: minterAddress,
|
|
5629
|
+
setupActions: [fixedPriceApproval, callSale]
|
|
5630
|
+
};
|
|
5631
|
+
}
|
|
5632
|
+
function setupAllowListMinter({
|
|
5633
|
+
chainId,
|
|
5634
|
+
tokenId: nextTokenId,
|
|
5635
|
+
allowlist,
|
|
5636
|
+
fundsRecipient
|
|
5637
|
+
}) {
|
|
5638
|
+
const merkleSaleStrategyAddress = import_protocol_deployments8.zoraCreatorMerkleMinterStrategyAddress[chainId];
|
|
5639
|
+
const merkleApproval = (0, import_viem7.encodeFunctionData)({
|
|
5640
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5641
|
+
functionName: "addPermission",
|
|
5642
|
+
args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER]
|
|
5643
|
+
});
|
|
5644
|
+
const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x") ? allowlist.presaleMerkleRoot : `0x${allowlist.presaleMerkleRoot}`;
|
|
5645
|
+
const saleData = (0, import_viem7.encodeFunctionData)({
|
|
5646
|
+
abi: import_protocol_deployments8.zoraCreatorMerkleMinterStrategyABI,
|
|
5647
|
+
functionName: "setSale",
|
|
5648
|
+
args: [
|
|
5649
|
+
BigInt(nextTokenId),
|
|
5650
|
+
{
|
|
5651
|
+
presaleStart: allowlist.saleStart,
|
|
5652
|
+
presaleEnd: allowlist.saleEnd,
|
|
5653
|
+
merkleRoot,
|
|
5654
|
+
fundsRecipient
|
|
5655
|
+
}
|
|
5656
|
+
]
|
|
5657
|
+
});
|
|
5658
|
+
const callSaleMerkle = (0, import_viem7.encodeFunctionData)({
|
|
5659
|
+
abi: import_protocol_deployments8.zoraCreator1155ImplABI,
|
|
5660
|
+
functionName: "callSale",
|
|
5661
|
+
args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData]
|
|
5662
|
+
});
|
|
5663
|
+
return {
|
|
5664
|
+
minter: merkleSaleStrategyAddress,
|
|
5665
|
+
setupActions: [merkleApproval, callSaleMerkle]
|
|
5666
|
+
};
|
|
5667
|
+
}
|
|
5668
|
+
var isAllowList2 = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
5669
|
+
var isErc202 = (salesConfig) => salesConfig.type === "erc20Mint";
|
|
5670
|
+
var isFixedPrice2 = (salesConfig) => salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > BigInt(0);
|
|
5671
|
+
function setupMinters({ salesConfig, ...rest }) {
|
|
5672
|
+
if (isErc202(salesConfig)) {
|
|
5673
|
+
return setupErc20Minter({
|
|
5674
|
+
...salesConfig,
|
|
5675
|
+
...rest
|
|
5676
|
+
});
|
|
5702
5677
|
}
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
* binary representation of a CID.
|
|
5709
|
-
*/
|
|
5710
|
-
static decode(bytes) {
|
|
5711
|
-
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
5712
|
-
if (remainder.length !== 0) {
|
|
5713
|
-
throw new Error("Incorrect length");
|
|
5714
|
-
}
|
|
5715
|
-
return cid;
|
|
5678
|
+
if (isAllowList2(salesConfig)) {
|
|
5679
|
+
return setupAllowListMinter({
|
|
5680
|
+
allowlist: salesConfig,
|
|
5681
|
+
...rest
|
|
5682
|
+
});
|
|
5716
5683
|
}
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5684
|
+
if (isFixedPrice2(salesConfig))
|
|
5685
|
+
return setupFixedPriceMinter({
|
|
5686
|
+
...salesConfig,
|
|
5687
|
+
...rest
|
|
5688
|
+
});
|
|
5689
|
+
return setupTimedSaleMinter({
|
|
5690
|
+
...salesConfig,
|
|
5691
|
+
...rest
|
|
5692
|
+
});
|
|
5693
|
+
}
|
|
5694
|
+
|
|
5695
|
+
// src/create/token-setup.ts
|
|
5696
|
+
async function applyNew1155Defaults(props, ownerAddress) {
|
|
5697
|
+
const { payoutRecipient: fundsRecipient } = props;
|
|
5698
|
+
const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== import_viem8.zeroAddress ? fundsRecipient : ownerAddress;
|
|
5699
|
+
return {
|
|
5700
|
+
payoutRecipient: fundsRecipientOrOwner,
|
|
5701
|
+
createReferral: props.createReferral || import_viem8.zeroAddress,
|
|
5702
|
+
maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
|
|
5703
|
+
royaltyBPS: props.royaltyBPS || 1e3,
|
|
5704
|
+
tokenMetadataURI: props.tokenMetadataURI,
|
|
5705
|
+
salesConfig: await getSalesConfigWithDefaults(
|
|
5706
|
+
props.salesConfig,
|
|
5707
|
+
props.tokenMetadataURI
|
|
5708
|
+
)
|
|
5709
|
+
};
|
|
5710
|
+
}
|
|
5711
|
+
function buildSetupNewToken({
|
|
5712
|
+
tokenURI,
|
|
5713
|
+
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
5714
|
+
createReferral = import_viem8.zeroAddress,
|
|
5715
|
+
contractVersion
|
|
5716
|
+
}) {
|
|
5717
|
+
if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
|
|
5718
|
+
return (0, import_viem8.encodeFunctionData)({
|
|
5719
|
+
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
5720
|
+
functionName: "setupNewTokenWithCreateReferral",
|
|
5721
|
+
args: [tokenURI, BigInt(maxSupply), createReferral]
|
|
5722
|
+
});
|
|
5737
5723
|
}
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
* bytes but for larger multicodec code values and larger multihash digest
|
|
5743
|
-
* lengths these varints can be quite large. It is recommended that at least
|
|
5744
|
-
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
5745
|
-
* inspection.
|
|
5746
|
-
*/
|
|
5747
|
-
static inspectBytes(initialBytes) {
|
|
5748
|
-
let offset = 0;
|
|
5749
|
-
const next = () => {
|
|
5750
|
-
const [i, length2] = decode3(initialBytes.subarray(offset));
|
|
5751
|
-
offset += length2;
|
|
5752
|
-
return i;
|
|
5753
|
-
};
|
|
5754
|
-
let version = next();
|
|
5755
|
-
let codec = DAG_PB_CODE;
|
|
5756
|
-
if (version === 18) {
|
|
5757
|
-
version = 0;
|
|
5758
|
-
offset = 0;
|
|
5759
|
-
} else {
|
|
5760
|
-
codec = next();
|
|
5761
|
-
}
|
|
5762
|
-
if (version !== 0 && version !== 1) {
|
|
5763
|
-
throw new RangeError(`Invalid CID version ${version}`);
|
|
5764
|
-
}
|
|
5765
|
-
const prefixSize = offset;
|
|
5766
|
-
const multihashCode = next();
|
|
5767
|
-
const digestSize = next();
|
|
5768
|
-
const size = offset + digestSize;
|
|
5769
|
-
const multihashSize = size - prefixSize;
|
|
5770
|
-
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
5724
|
+
if (createReferral !== import_viem8.zeroAddress) {
|
|
5725
|
+
throw new Error(
|
|
5726
|
+
"Contract does not support create referral, but one was provided"
|
|
5727
|
+
);
|
|
5771
5728
|
}
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5729
|
+
return (0, import_viem8.encodeFunctionData)({
|
|
5730
|
+
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
5731
|
+
functionName: "setupNewToken",
|
|
5732
|
+
args: [tokenURI, BigInt(maxSupply)]
|
|
5733
|
+
});
|
|
5734
|
+
}
|
|
5735
|
+
function setupRoyaltyConfig({
|
|
5736
|
+
royaltyBPS,
|
|
5737
|
+
royaltyRecipient,
|
|
5738
|
+
nextTokenId
|
|
5739
|
+
}) {
|
|
5740
|
+
if (royaltyBPS > 0 && royaltyRecipient != import_viem8.zeroAddress) {
|
|
5741
|
+
return (0, import_viem8.encodeFunctionData)({
|
|
5742
|
+
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
5743
|
+
functionName: "updateRoyaltiesForToken",
|
|
5744
|
+
args: [
|
|
5745
|
+
nextTokenId,
|
|
5746
|
+
{
|
|
5747
|
+
royaltyBPS,
|
|
5748
|
+
royaltyRecipient,
|
|
5749
|
+
royaltyMintSchedule: 0
|
|
5750
|
+
}
|
|
5751
|
+
]
|
|
5752
|
+
});
|
|
5786
5753
|
}
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
}
|
|
5797
|
-
case base58btc.prefix: {
|
|
5798
|
-
const decoder = base3 ?? base58btc;
|
|
5799
|
-
return [base58btc.prefix, decoder.decode(source)];
|
|
5800
|
-
}
|
|
5801
|
-
case base32.prefix: {
|
|
5802
|
-
const decoder = base3 ?? base32;
|
|
5803
|
-
return [base32.prefix, decoder.decode(source)];
|
|
5804
|
-
}
|
|
5805
|
-
default: {
|
|
5806
|
-
if (base3 == null) {
|
|
5807
|
-
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
5808
|
-
}
|
|
5809
|
-
return [source[0], base3.decode(source)];
|
|
5810
|
-
}
|
|
5754
|
+
return null;
|
|
5755
|
+
}
|
|
5756
|
+
function makeAdminMintCall({
|
|
5757
|
+
ownerAddress,
|
|
5758
|
+
mintQuantity,
|
|
5759
|
+
nextTokenId
|
|
5760
|
+
}) {
|
|
5761
|
+
if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
|
|
5762
|
+
return null;
|
|
5811
5763
|
}
|
|
5764
|
+
return (0, import_viem8.encodeFunctionData)({
|
|
5765
|
+
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
5766
|
+
functionName: "adminMint",
|
|
5767
|
+
args: [ownerAddress, nextTokenId, BigInt(mintQuantity), import_viem8.zeroAddress]
|
|
5768
|
+
});
|
|
5812
5769
|
}
|
|
5813
|
-
function
|
|
5814
|
-
const {
|
|
5815
|
-
|
|
5816
|
-
|
|
5770
|
+
async function constructCreate1155TokenCalls(props) {
|
|
5771
|
+
const {
|
|
5772
|
+
chainId,
|
|
5773
|
+
nextTokenId,
|
|
5774
|
+
mintToCreatorCount,
|
|
5775
|
+
ownerAddress,
|
|
5776
|
+
contractVersion
|
|
5777
|
+
} = props;
|
|
5778
|
+
const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
|
|
5779
|
+
props,
|
|
5780
|
+
ownerAddress
|
|
5781
|
+
);
|
|
5782
|
+
const verifyTokenIdExpected = (0, import_viem8.encodeFunctionData)({
|
|
5783
|
+
abi: import_protocol_deployments9.zoraCreator1155ImplABI,
|
|
5784
|
+
functionName: "assumeLastTokenIdMatches",
|
|
5785
|
+
args: [nextTokenId - 1n]
|
|
5786
|
+
});
|
|
5787
|
+
const setupNewToken = buildSetupNewToken({
|
|
5788
|
+
tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
|
|
5789
|
+
maxSupply: new1155TokenPropsWithDefaults.maxSupply,
|
|
5790
|
+
createReferral: new1155TokenPropsWithDefaults.createReferral,
|
|
5791
|
+
contractVersion
|
|
5792
|
+
});
|
|
5793
|
+
const royaltyConfig = setupRoyaltyConfig({
|
|
5794
|
+
royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
|
|
5795
|
+
royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
5796
|
+
nextTokenId
|
|
5797
|
+
});
|
|
5798
|
+
const { minter, setupActions: mintersSetup } = setupMinters({
|
|
5799
|
+
tokenId: nextTokenId,
|
|
5800
|
+
chainId,
|
|
5801
|
+
fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
5802
|
+
salesConfig: new1155TokenPropsWithDefaults.salesConfig
|
|
5803
|
+
});
|
|
5804
|
+
const adminMintCall = makeAdminMintCall({
|
|
5805
|
+
ownerAddress,
|
|
5806
|
+
mintQuantity: mintToCreatorCount,
|
|
5807
|
+
nextTokenId
|
|
5808
|
+
});
|
|
5809
|
+
const setupActions = [
|
|
5810
|
+
verifyTokenIdExpected,
|
|
5811
|
+
setupNewToken,
|
|
5812
|
+
...mintersSetup,
|
|
5813
|
+
royaltyConfig,
|
|
5814
|
+
adminMintCall
|
|
5815
|
+
].filter((item) => item !== null);
|
|
5816
|
+
return {
|
|
5817
|
+
setupActions,
|
|
5818
|
+
minter,
|
|
5819
|
+
newToken: new1155TokenPropsWithDefaults
|
|
5820
|
+
};
|
|
5821
|
+
}
|
|
5822
|
+
var contractSupportsMintRewards = (contractVersion, contractStandard) => {
|
|
5823
|
+
if (!contractStandard || !contractVersion) {
|
|
5824
|
+
return false;
|
|
5817
5825
|
}
|
|
5818
|
-
const
|
|
5819
|
-
if (
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
return
|
|
5826
|
+
const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
|
|
5827
|
+
if (!semVerContractVersion)
|
|
5828
|
+
return false;
|
|
5829
|
+
if (contractStandard === "ERC1155") {
|
|
5830
|
+
return semver2.gte(semVerContractVersion, "1.3.5");
|
|
5823
5831
|
} else {
|
|
5824
|
-
return
|
|
5832
|
+
return semver2.gte(semVerContractVersion, "14.0.0");
|
|
5833
|
+
}
|
|
5834
|
+
};
|
|
5835
|
+
|
|
5836
|
+
// src/create/mint-from-create.ts
|
|
5837
|
+
var import_viem9 = require("viem");
|
|
5838
|
+
var import_protocol_deployments10 = require("@zoralabs/protocol-deployments");
|
|
5839
|
+
async function toSalesStrategyFromSubgraph({
|
|
5840
|
+
minter,
|
|
5841
|
+
salesConfig,
|
|
5842
|
+
publicClient,
|
|
5843
|
+
contractAddress
|
|
5844
|
+
}) {
|
|
5845
|
+
if (salesConfig.type === "timed") {
|
|
5846
|
+
return {
|
|
5847
|
+
saleType: "timed",
|
|
5848
|
+
address: minter,
|
|
5849
|
+
// for now we hardcode this
|
|
5850
|
+
mintFeePerQuantity: (0, import_viem9.parseEther)("0.000111"),
|
|
5851
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
5852
|
+
saleEnd: salesConfig.saleEnd.toString(),
|
|
5853
|
+
// the following are not needed for now but we wanna satisfy concrete
|
|
5854
|
+
erc20Z: import_viem9.zeroAddress,
|
|
5855
|
+
mintFee: 0n,
|
|
5856
|
+
pool: import_viem9.zeroAddress,
|
|
5857
|
+
secondaryActivated: false
|
|
5858
|
+
};
|
|
5859
|
+
}
|
|
5860
|
+
if (salesConfig.type === "erc20Mint") {
|
|
5861
|
+
return {
|
|
5862
|
+
saleType: "erc20",
|
|
5863
|
+
address: minter,
|
|
5864
|
+
mintFeePerQuantity: 0n,
|
|
5865
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
5866
|
+
saleEnd: salesConfig.saleEnd.toString(),
|
|
5867
|
+
currency: salesConfig.currency,
|
|
5868
|
+
pricePerToken: salesConfig.pricePerToken,
|
|
5869
|
+
maxTokensPerAddress: salesConfig.maxTokensPerAddress
|
|
5870
|
+
};
|
|
5825
5871
|
}
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5872
|
+
const contractMintFee = await publicClient.readContract({
|
|
5873
|
+
abi: import_protocol_deployments10.zoraCreator1155ImplABI,
|
|
5874
|
+
address: contractAddress,
|
|
5875
|
+
functionName: "mintFee"
|
|
5876
|
+
});
|
|
5877
|
+
if (salesConfig.type === "fixedPrice") {
|
|
5878
|
+
return {
|
|
5879
|
+
saleType: "fixedPrice",
|
|
5880
|
+
address: minter,
|
|
5881
|
+
maxTokensPerAddress: salesConfig.maxTokensPerAddress,
|
|
5882
|
+
mintFeePerQuantity: contractMintFee,
|
|
5883
|
+
pricePerToken: salesConfig.pricePerToken,
|
|
5884
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
5885
|
+
saleEnd: salesConfig.saleEnd.toString()
|
|
5886
|
+
};
|
|
5836
5887
|
}
|
|
5888
|
+
return {
|
|
5889
|
+
saleType: "allowlist",
|
|
5890
|
+
address: minter,
|
|
5891
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
5892
|
+
saleEnd: salesConfig.saleEnd.toString(),
|
|
5893
|
+
merkleRoot: salesConfig.presaleMerkleRoot,
|
|
5894
|
+
mintFeePerQuantity: contractMintFee
|
|
5895
|
+
};
|
|
5837
5896
|
}
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5897
|
+
function makeOnchainPrepareMintFromCreate({
|
|
5898
|
+
contractAddress,
|
|
5899
|
+
tokenId,
|
|
5900
|
+
result,
|
|
5901
|
+
minter,
|
|
5902
|
+
publicClient,
|
|
5903
|
+
contractVersion
|
|
5904
|
+
}) {
|
|
5905
|
+
return async (params) => {
|
|
5906
|
+
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
5907
|
+
minter,
|
|
5908
|
+
contractAddress,
|
|
5909
|
+
publicClient,
|
|
5910
|
+
salesConfig: result
|
|
5911
|
+
});
|
|
5912
|
+
return {
|
|
5913
|
+
parameters: makePrepareMint1155TokenParams({
|
|
5914
|
+
salesConfigAndTokenInfo: {
|
|
5915
|
+
salesConfig: subgraphSalesConfig,
|
|
5916
|
+
contractVersion
|
|
5917
|
+
},
|
|
5918
|
+
...params,
|
|
5919
|
+
tokenContract: contractAddress,
|
|
5920
|
+
tokenId
|
|
5921
|
+
}),
|
|
5922
|
+
costs: parseMintCosts({
|
|
5923
|
+
allowListEntry: params.allowListEntry,
|
|
5924
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
5925
|
+
salesConfig: subgraphSalesConfig
|
|
5926
|
+
}),
|
|
5927
|
+
erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
|
|
5928
|
+
};
|
|
5929
|
+
};
|
|
5848
5930
|
}
|
|
5849
|
-
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
5850
5931
|
|
|
5851
|
-
// src/
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5932
|
+
// src/create/1155-create-helper.ts
|
|
5933
|
+
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
5934
|
+
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
5935
|
+
for (const data of receipt.logs) {
|
|
5936
|
+
try {
|
|
5937
|
+
const decodedLog = (0, import_viem10.decodeEventLog)({
|
|
5938
|
+
abi: import_protocol_deployments11.zoraCreator1155ImplABI,
|
|
5939
|
+
eventName: "SetupNewToken",
|
|
5940
|
+
...data
|
|
5941
|
+
});
|
|
5942
|
+
if (decodedLog && decodedLog.eventName === "SetupNewToken") {
|
|
5943
|
+
return decodedLog.args.tokenId;
|
|
5944
|
+
}
|
|
5945
|
+
} catch (err) {
|
|
5946
|
+
}
|
|
5862
5947
|
}
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5948
|
+
throw new Error(
|
|
5949
|
+
"No event found in receipt that could be used to get tokenId"
|
|
5950
|
+
);
|
|
5951
|
+
};
|
|
5952
|
+
var getContractAddressFromReceipt = (receipt) => {
|
|
5953
|
+
for (const data of receipt.logs) {
|
|
5954
|
+
try {
|
|
5955
|
+
const decodedLog = (0, import_viem10.decodeEventLog)({
|
|
5956
|
+
abi: import_protocol_deployments11.zoraCreator1155FactoryImplABI,
|
|
5957
|
+
eventName: "SetupNewContract",
|
|
5958
|
+
...data
|
|
5959
|
+
});
|
|
5960
|
+
if (decodedLog && decodedLog.eventName === "SetupNewContract") {
|
|
5961
|
+
return decodedLog.args.newContract;
|
|
5962
|
+
}
|
|
5963
|
+
} catch (err) {
|
|
5964
|
+
}
|
|
5879
5965
|
}
|
|
5880
|
-
|
|
5966
|
+
throw new Error(
|
|
5967
|
+
"No event found in receipt that could be used to get contract address"
|
|
5968
|
+
);
|
|
5969
|
+
};
|
|
5970
|
+
function makeCreateContractAndTokenCall({
|
|
5971
|
+
account,
|
|
5972
|
+
contract,
|
|
5973
|
+
royaltyBPS,
|
|
5974
|
+
fundsRecipient,
|
|
5975
|
+
tokenSetupActions,
|
|
5976
|
+
chainId
|
|
5977
|
+
}) {
|
|
5978
|
+
const accountAddress = typeof account === "string" ? account : account.address;
|
|
5979
|
+
return makeContractParameters({
|
|
5980
|
+
abi: import_protocol_deployments11.zoraCreator1155FactoryImplABI,
|
|
5981
|
+
functionName: "createContractDeterministic",
|
|
5982
|
+
account,
|
|
5983
|
+
address: import_protocol_deployments11.zoraCreator1155FactoryImplAddress[chainId],
|
|
5984
|
+
args: [
|
|
5985
|
+
contract.uri,
|
|
5986
|
+
contract.name,
|
|
5987
|
+
{
|
|
5988
|
+
// deprecated
|
|
5989
|
+
royaltyMintSchedule: 0,
|
|
5990
|
+
royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
5991
|
+
royaltyRecipient: fundsRecipient || accountAddress
|
|
5992
|
+
},
|
|
5993
|
+
contract.defaultAdmin || accountAddress,
|
|
5994
|
+
tokenSetupActions
|
|
5995
|
+
]
|
|
5996
|
+
});
|
|
5881
5997
|
}
|
|
5882
|
-
function
|
|
5883
|
-
|
|
5998
|
+
function makeCreateTokenCall({
|
|
5999
|
+
contractAddress,
|
|
6000
|
+
account,
|
|
6001
|
+
tokenSetupActions
|
|
6002
|
+
}) {
|
|
6003
|
+
return makeContractParameters({
|
|
6004
|
+
abi: import_protocol_deployments11.zoraCreator1155ImplABI,
|
|
6005
|
+
functionName: "multicall",
|
|
6006
|
+
account,
|
|
6007
|
+
address: contractAddress,
|
|
6008
|
+
args: [tokenSetupActions]
|
|
6009
|
+
});
|
|
5884
6010
|
}
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
}
|
|
6011
|
+
var Create1155Client = class {
|
|
6012
|
+
constructor({
|
|
6013
|
+
chainId,
|
|
6014
|
+
publicClient
|
|
6015
|
+
}) {
|
|
6016
|
+
this.chainId = chainId;
|
|
6017
|
+
this.publicClient = publicClient;
|
|
5893
6018
|
}
|
|
5894
|
-
|
|
6019
|
+
async createNew1155(props) {
|
|
6020
|
+
return createNew1155ContractAndToken({
|
|
6021
|
+
...props,
|
|
6022
|
+
publicClient: this.publicClient,
|
|
6023
|
+
chainId: this.chainId
|
|
6024
|
+
});
|
|
6025
|
+
}
|
|
6026
|
+
async createNew1155OnExistingContract({
|
|
6027
|
+
contractAddress: contract,
|
|
6028
|
+
account,
|
|
6029
|
+
token,
|
|
6030
|
+
getAdditionalSetupActions
|
|
6031
|
+
}) {
|
|
6032
|
+
return createNew1155Token({
|
|
6033
|
+
contractAddress: contract,
|
|
6034
|
+
account,
|
|
6035
|
+
token,
|
|
6036
|
+
getAdditionalSetupActions,
|
|
6037
|
+
publicClient: this.publicClient,
|
|
6038
|
+
chainId: this.chainId
|
|
6039
|
+
});
|
|
6040
|
+
}
|
|
6041
|
+
};
|
|
6042
|
+
async function createNew1155ContractAndToken({
|
|
6043
|
+
contract,
|
|
6044
|
+
account,
|
|
6045
|
+
chainId,
|
|
6046
|
+
token,
|
|
6047
|
+
publicClient,
|
|
6048
|
+
getAdditionalSetupActions
|
|
6049
|
+
}) {
|
|
6050
|
+
const nextTokenId = 1n;
|
|
6051
|
+
const contractVersion = new1155ContractVersion(chainId);
|
|
6052
|
+
const {
|
|
6053
|
+
minter,
|
|
6054
|
+
newToken,
|
|
6055
|
+
setupActions: tokenSetupActions
|
|
6056
|
+
} = await prepareSetupActions({
|
|
6057
|
+
chainId,
|
|
6058
|
+
account,
|
|
6059
|
+
contractVersion,
|
|
6060
|
+
nextTokenId,
|
|
6061
|
+
token,
|
|
6062
|
+
getAdditionalSetupActions
|
|
6063
|
+
});
|
|
6064
|
+
const request = makeCreateContractAndTokenCall({
|
|
6065
|
+
contract,
|
|
6066
|
+
account,
|
|
6067
|
+
chainId,
|
|
6068
|
+
tokenSetupActions,
|
|
6069
|
+
fundsRecipient: token.payoutRecipient,
|
|
6070
|
+
royaltyBPS: token.royaltyBPS
|
|
6071
|
+
});
|
|
6072
|
+
const contractAddress = await getDeterministicContractAddress({
|
|
6073
|
+
account,
|
|
6074
|
+
publicClient,
|
|
6075
|
+
setupActions: tokenSetupActions,
|
|
6076
|
+
chainId,
|
|
6077
|
+
contract
|
|
6078
|
+
});
|
|
6079
|
+
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
6080
|
+
contractAddress,
|
|
6081
|
+
contractVersion,
|
|
6082
|
+
minter,
|
|
6083
|
+
publicClient,
|
|
6084
|
+
result: newToken.salesConfig,
|
|
6085
|
+
tokenId: nextTokenId
|
|
6086
|
+
});
|
|
6087
|
+
return {
|
|
6088
|
+
parameters: request,
|
|
6089
|
+
tokenSetupActions,
|
|
6090
|
+
newTokenId: nextTokenId,
|
|
6091
|
+
newToken,
|
|
6092
|
+
contractAddress,
|
|
6093
|
+
contractVersion,
|
|
6094
|
+
minter,
|
|
6095
|
+
prepareMint
|
|
6096
|
+
};
|
|
5895
6097
|
}
|
|
5896
|
-
function
|
|
5897
|
-
|
|
6098
|
+
async function createNew1155Token({
|
|
6099
|
+
contractAddress,
|
|
6100
|
+
account,
|
|
6101
|
+
getAdditionalSetupActions,
|
|
6102
|
+
token,
|
|
6103
|
+
publicClient,
|
|
6104
|
+
chainId
|
|
6105
|
+
}) {
|
|
6106
|
+
const { nextTokenId, contractVersion } = await getContractInfoExistingContract({
|
|
6107
|
+
publicClient,
|
|
6108
|
+
contractAddress
|
|
6109
|
+
});
|
|
6110
|
+
const {
|
|
6111
|
+
minter,
|
|
6112
|
+
newToken,
|
|
6113
|
+
setupActions: tokenSetupActions
|
|
6114
|
+
} = await prepareSetupActions({
|
|
6115
|
+
chainId,
|
|
6116
|
+
account,
|
|
6117
|
+
contractVersion,
|
|
6118
|
+
nextTokenId,
|
|
6119
|
+
token,
|
|
6120
|
+
getAdditionalSetupActions
|
|
6121
|
+
});
|
|
6122
|
+
const request = makeCreateTokenCall({
|
|
6123
|
+
contractAddress,
|
|
6124
|
+
account,
|
|
6125
|
+
tokenSetupActions
|
|
6126
|
+
});
|
|
6127
|
+
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
6128
|
+
contractAddress,
|
|
6129
|
+
contractVersion,
|
|
6130
|
+
minter,
|
|
6131
|
+
publicClient,
|
|
6132
|
+
result: newToken.salesConfig,
|
|
6133
|
+
tokenId: nextTokenId
|
|
6134
|
+
});
|
|
6135
|
+
return {
|
|
6136
|
+
parameters: request,
|
|
6137
|
+
tokenSetupActions,
|
|
6138
|
+
newTokenId: nextTokenId,
|
|
6139
|
+
newToken,
|
|
6140
|
+
contractVersion,
|
|
6141
|
+
minter,
|
|
6142
|
+
prepareMint
|
|
6143
|
+
};
|
|
5898
6144
|
}
|
|
5899
|
-
function
|
|
5900
|
-
|
|
6145
|
+
async function prepareSetupActions({
|
|
6146
|
+
chainId,
|
|
6147
|
+
account,
|
|
6148
|
+
contractVersion,
|
|
6149
|
+
nextTokenId,
|
|
6150
|
+
token,
|
|
6151
|
+
getAdditionalSetupActions
|
|
6152
|
+
}) {
|
|
6153
|
+
const {
|
|
6154
|
+
minter,
|
|
6155
|
+
newToken,
|
|
6156
|
+
setupActions: tokenSetupActions
|
|
6157
|
+
} = await constructCreate1155TokenCalls({
|
|
6158
|
+
chainId,
|
|
6159
|
+
ownerAddress: account,
|
|
6160
|
+
contractVersion,
|
|
6161
|
+
nextTokenId,
|
|
6162
|
+
...token
|
|
6163
|
+
});
|
|
6164
|
+
const setupActions = getAdditionalSetupActions ? [
|
|
6165
|
+
...getAdditionalSetupActions({
|
|
6166
|
+
tokenId: nextTokenId
|
|
6167
|
+
}),
|
|
6168
|
+
...tokenSetupActions
|
|
6169
|
+
] : tokenSetupActions;
|
|
6170
|
+
return { minter, newToken, setupActions };
|
|
5901
6171
|
}
|
|
5902
6172
|
|
|
5903
|
-
// src/
|
|
5904
|
-
var
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
}
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
6173
|
+
// src/sparks/mints-queries.ts
|
|
6174
|
+
var getMintsAccountBalanceWithPriceQuery = (account) => {
|
|
6175
|
+
const query = `
|
|
6176
|
+
query GetMintAccountBalances($account: String!) {
|
|
6177
|
+
mintAccountBalances(where: { account: $account }) {
|
|
6178
|
+
balance
|
|
6179
|
+
mintToken {
|
|
6180
|
+
id
|
|
6181
|
+
pricePerToken
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
`;
|
|
6186
|
+
return {
|
|
6187
|
+
query,
|
|
6188
|
+
variables: { account }
|
|
6189
|
+
};
|
|
6190
|
+
};
|
|
6191
|
+
var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
|
|
6192
|
+
const parsed = mintAccountBalances.map((r) => {
|
|
6193
|
+
return {
|
|
6194
|
+
tokenId: BigInt(r.mintToken.id),
|
|
6195
|
+
quantity: BigInt(r.balance),
|
|
6196
|
+
pricePerToken: BigInt(r.mintToken.pricePerToken)
|
|
6197
|
+
};
|
|
6198
|
+
});
|
|
6199
|
+
const sorted = parsed.sort((a, b) => {
|
|
6200
|
+
if (a.pricePerToken < b.pricePerToken) {
|
|
6201
|
+
return -1;
|
|
6202
|
+
}
|
|
6203
|
+
return 1;
|
|
6204
|
+
});
|
|
6205
|
+
let remainingQuantity = quantityToCollect;
|
|
6206
|
+
const tokenIds = [];
|
|
6207
|
+
const quantities = [];
|
|
6208
|
+
while (remainingQuantity > 0) {
|
|
6209
|
+
const next = sorted.shift();
|
|
6210
|
+
if (!next) {
|
|
6211
|
+
throw new Error("Not enough MINTs to collect with");
|
|
6212
|
+
}
|
|
6213
|
+
const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
|
|
6214
|
+
tokenIds.push(next.tokenId);
|
|
6215
|
+
quantities.push(quantityToUse);
|
|
6216
|
+
remainingQuantity -= quantityToUse;
|
|
5933
6217
|
}
|
|
5934
|
-
return
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
var HTML = "text/html";
|
|
5939
|
-
var MARKDOWN = "text/markdown";
|
|
5940
|
-
var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
|
|
5941
|
-
var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
|
|
5942
|
-
var TEXT_PLAIN = "text/plain";
|
|
5943
|
-
var CSV = "text/csv";
|
|
5944
|
-
var NUMBERS = ".numbers";
|
|
5945
|
-
var EXCEL = ".xlsx";
|
|
5946
|
-
var PDF = "application/pdf";
|
|
5947
|
-
var JPG = "image/jpg";
|
|
5948
|
-
var JPEG = "image/jpeg";
|
|
5949
|
-
var PNG = "image/png";
|
|
5950
|
-
var WEBP = "image/webp";
|
|
5951
|
-
var SVG = "image/svg+xml";
|
|
5952
|
-
var TIFF = "image/tiff";
|
|
5953
|
-
var GIF = "image/gif";
|
|
5954
|
-
var isImage = (mimeType) => {
|
|
5955
|
-
if (!mimeType)
|
|
5956
|
-
return false;
|
|
5957
|
-
return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
|
|
6218
|
+
return {
|
|
6219
|
+
tokenIds,
|
|
6220
|
+
quantities
|
|
6221
|
+
};
|
|
5958
6222
|
};
|
|
5959
|
-
var
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
|
|
5964
|
-
// assuming all zip files are html directories
|
|
5965
|
-
["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
|
|
5966
|
-
default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
|
|
6223
|
+
var sumBalances = (mintAccountBalances) => {
|
|
6224
|
+
return mintAccountBalances.reduce((acc, curr) => {
|
|
6225
|
+
return acc + BigInt(curr.balance);
|
|
6226
|
+
}, BigInt(0));
|
|
5967
6227
|
};
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
var
|
|
5971
|
-
var
|
|
5972
|
-
var
|
|
5973
|
-
var
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
[WEBP]: "IMAGE" /* IMAGE */,
|
|
5993
|
-
[SVG]: "IMAGE" /* IMAGE */,
|
|
5994
|
-
[TIFF]: "TIFF" /* TIFF */,
|
|
5995
|
-
[GIF]: "IMAGE" /* IMAGE */,
|
|
5996
|
-
[MP4]: "VIDEO" /* VIDEO */,
|
|
5997
|
-
[WEBM]: "VIDEO" /* VIDEO */,
|
|
5998
|
-
[QUICKTIME]: "VIDEO" /* VIDEO */,
|
|
5999
|
-
[M4V]: "VIDEO" /* VIDEO */,
|
|
6000
|
-
[MPEG]: "AUDIO" /* AUDIO */,
|
|
6001
|
-
[MP3]: "AUDIO" /* AUDIO */,
|
|
6002
|
-
[M4A]: "AUDIO" /* AUDIO */,
|
|
6003
|
-
[VND_WAV]: "AUDIO" /* AUDIO */,
|
|
6004
|
-
[VND_WAVE]: "AUDIO" /* AUDIO */,
|
|
6005
|
-
[WAV]: "AUDIO" /* AUDIO */,
|
|
6006
|
-
[WAVE]: "AUDIO" /* AUDIO */,
|
|
6007
|
-
[X_WAV]: "AUDIO" /* AUDIO */,
|
|
6008
|
-
[AIFF]: "AUDIO" /* AUDIO */,
|
|
6009
|
-
[TEXT_PLAIN]: "TEXT" /* TEXT */,
|
|
6010
|
-
[TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
|
|
6011
|
-
[MARKDOWN]: "TEXT" /* TEXT */,
|
|
6012
|
-
[MARKDOWN_UTF8]: "TEXT" /* TEXT */,
|
|
6013
|
-
[CSV]: "CSV" /* CSV */,
|
|
6014
|
-
[NUMBERS]: "NUMBERS" /* NUMBERS */,
|
|
6015
|
-
[EXCEL]: "EXCEL" /* EXCEL */,
|
|
6016
|
-
[PDF]: "PDF" /* PDF */,
|
|
6017
|
-
[ZIP]: "ZIP" /* ZIP */,
|
|
6018
|
-
[GLTF]: "MODEL" /* MODEL */,
|
|
6019
|
-
[GLTF_EXT]: "MODEL" /* MODEL */,
|
|
6020
|
-
[GLB]: "MODEL" /* MODEL */,
|
|
6021
|
-
// GLTF returns 'application/json' as the mimetype,
|
|
6022
|
-
// and as the only JSON-encoded media we currently support,
|
|
6023
|
-
// we assume that if the mimetype is JSON, it's a GLTF
|
|
6024
|
-
[JSON_MIME_TYPE]: "MODEL" /* MODEL */,
|
|
6025
|
-
[GLB_EXT]: "MODEL" /* MODEL */
|
|
6228
|
+
|
|
6229
|
+
// src/sparks/sparks-contracts.ts
|
|
6230
|
+
var import_protocol_deployments12 = require("@zoralabs/protocol-deployments");
|
|
6231
|
+
var import_viem11 = require("viem");
|
|
6232
|
+
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
6233
|
+
var mintWithEthParams = ({
|
|
6234
|
+
tokenId,
|
|
6235
|
+
quantity,
|
|
6236
|
+
recipient,
|
|
6237
|
+
chainId,
|
|
6238
|
+
pricePerMint,
|
|
6239
|
+
account
|
|
6240
|
+
}) => makeContractParameters({
|
|
6241
|
+
abi: import_protocol_deployments12.zoraSparksManagerImplABI,
|
|
6242
|
+
address: import_protocol_deployments12.zoraSparksManagerImplAddress[chainId],
|
|
6243
|
+
functionName: "mintWithEth",
|
|
6244
|
+
args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
|
|
6245
|
+
value: pricePerMint * quantity,
|
|
6246
|
+
account
|
|
6247
|
+
});
|
|
6248
|
+
var getPaidMintValue = (quantities, pricePerMint) => {
|
|
6249
|
+
if (!pricePerMint || pricePerMint === 0n)
|
|
6250
|
+
return;
|
|
6251
|
+
return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
|
|
6026
6252
|
};
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6253
|
+
var mintsBalanceOfAccountParams = ({
|
|
6254
|
+
account,
|
|
6255
|
+
chainId
|
|
6256
|
+
}) => ({
|
|
6257
|
+
abi: import_protocol_deployments12.zoraMints1155Config.abi,
|
|
6258
|
+
address: import_protocol_deployments12.zoraMints1155Config.address[chainId],
|
|
6259
|
+
functionName: "balanceOfAccount",
|
|
6260
|
+
args: [account]
|
|
6261
|
+
});
|
|
6262
|
+
var encodeCollectOnManager = ({
|
|
6263
|
+
zoraCreator1155Contract,
|
|
6264
|
+
minter,
|
|
6265
|
+
zoraCreator1155TokenId,
|
|
6266
|
+
mintArguments
|
|
6267
|
+
}) => (0, import_viem11.encodeFunctionData)({
|
|
6268
|
+
abi: import_protocol_deployments12.zoraMintsManagerImplConfig.abi,
|
|
6269
|
+
functionName: "collect",
|
|
6270
|
+
args: [
|
|
6271
|
+
zoraCreator1155Contract,
|
|
6272
|
+
minter,
|
|
6273
|
+
zoraCreator1155TokenId,
|
|
6274
|
+
mintArguments
|
|
6275
|
+
]
|
|
6276
|
+
});
|
|
6277
|
+
function collectWithMintsParams({
|
|
6278
|
+
tokenIds,
|
|
6279
|
+
quantities,
|
|
6280
|
+
chainId,
|
|
6281
|
+
paidMintPricePerToken,
|
|
6282
|
+
account,
|
|
6283
|
+
mintArguments,
|
|
6284
|
+
minter,
|
|
6285
|
+
zoraCreator1155Contract,
|
|
6286
|
+
zoraCreator1155TokenId
|
|
6287
|
+
}) {
|
|
6288
|
+
const call = encodeCollectOnManager({
|
|
6289
|
+
tokenIds,
|
|
6290
|
+
quantities,
|
|
6291
|
+
zoraCreator1155Contract,
|
|
6292
|
+
zoraCreator1155TokenId,
|
|
6293
|
+
minter,
|
|
6294
|
+
mintArguments
|
|
6295
|
+
});
|
|
6296
|
+
return makeContractParameters({
|
|
6297
|
+
abi: import_protocol_deployments12.zoraMints1155Config.abi,
|
|
6298
|
+
address: import_protocol_deployments12.zoraMints1155Config.address[chainId],
|
|
6299
|
+
functionName: "transferBatchToManagerAndCall",
|
|
6300
|
+
args: [tokenIds, quantities, call],
|
|
6301
|
+
// if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
|
|
6302
|
+
// for the paid mint cost.
|
|
6303
|
+
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
6304
|
+
account
|
|
6305
|
+
});
|
|
6031
6306
|
}
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
const
|
|
6036
|
-
|
|
6037
|
-
|
|
6307
|
+
function getMintsEthPrice({
|
|
6308
|
+
publicClient
|
|
6309
|
+
}) {
|
|
6310
|
+
const chainId = publicClient.chain?.id;
|
|
6311
|
+
if (!chainId || !import_protocol_deployments12.zoraMintsManagerImplAddress[chainId]) {
|
|
6312
|
+
throw new Error(`Chain id ${chainId} not supported`);
|
|
6313
|
+
}
|
|
6314
|
+
return publicClient.readContract({
|
|
6315
|
+
abi: import_protocol_deployments12.zoraMintsManagerImplABI,
|
|
6316
|
+
address: import_protocol_deployments12.zoraMintsManagerImplAddress[chainId],
|
|
6317
|
+
functionName: "getEthPrice"
|
|
6318
|
+
});
|
|
6038
6319
|
}
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6320
|
+
function makePermitTransferBatchAndTypeData({
|
|
6321
|
+
tokenIds,
|
|
6322
|
+
quantities,
|
|
6323
|
+
chainId,
|
|
6324
|
+
mintsOwner,
|
|
6325
|
+
to,
|
|
6326
|
+
nonce,
|
|
6327
|
+
deadline,
|
|
6328
|
+
safeTransferData
|
|
6329
|
+
}) {
|
|
6330
|
+
const permit = {
|
|
6331
|
+
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
6332
|
+
to,
|
|
6333
|
+
tokenIds,
|
|
6334
|
+
quantities,
|
|
6335
|
+
deadline,
|
|
6336
|
+
nonce,
|
|
6337
|
+
safeTransferData
|
|
6338
|
+
};
|
|
6339
|
+
const typedData = {
|
|
6340
|
+
...(0, import_protocol_deployments12.mintsSafeTransferBatchTypedDataDefinition)({
|
|
6341
|
+
chainId,
|
|
6342
|
+
message: permit
|
|
6343
|
+
}),
|
|
6344
|
+
account: mintsOwner
|
|
6345
|
+
};
|
|
6049
6346
|
return {
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
animation_url,
|
|
6053
|
-
content,
|
|
6054
|
-
attributes
|
|
6347
|
+
permit,
|
|
6348
|
+
typedData
|
|
6055
6349
|
};
|
|
6056
|
-
}
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6350
|
+
}
|
|
6351
|
+
function makePermitTransferTypeData({
|
|
6352
|
+
tokenId,
|
|
6353
|
+
quantity,
|
|
6354
|
+
chainId,
|
|
6355
|
+
mintsOwner,
|
|
6356
|
+
to,
|
|
6357
|
+
nonce,
|
|
6358
|
+
deadline,
|
|
6359
|
+
safeTransferData
|
|
6360
|
+
}) {
|
|
6361
|
+
const permit = {
|
|
6362
|
+
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
6363
|
+
to,
|
|
6364
|
+
tokenId,
|
|
6365
|
+
quantity,
|
|
6366
|
+
deadline,
|
|
6367
|
+
nonce,
|
|
6368
|
+
safeTransferData
|
|
6369
|
+
};
|
|
6370
|
+
const typedData = {
|
|
6371
|
+
...(0, import_protocol_deployments12.mintsSafeTransferTypedDataDefinition)({
|
|
6372
|
+
chainId,
|
|
6373
|
+
message: permit
|
|
6374
|
+
}),
|
|
6375
|
+
account: mintsOwner
|
|
6376
|
+
};
|
|
6377
|
+
return {
|
|
6378
|
+
permit,
|
|
6379
|
+
typedData
|
|
6380
|
+
};
|
|
6381
|
+
}
|
|
6382
|
+
var encodePremintOnManager = ({
|
|
6383
|
+
contractCreationConfig,
|
|
6384
|
+
premintConfig,
|
|
6385
|
+
premintSignature,
|
|
6386
|
+
mintArguments,
|
|
6387
|
+
signerContract = import_viem11.zeroAddress
|
|
6388
|
+
}) => (0, import_viem11.encodeFunctionData)({
|
|
6389
|
+
abi: import_protocol_deployments12.zoraMintsManagerImplConfig.abi,
|
|
6390
|
+
functionName: "collectPremintV2",
|
|
6391
|
+
args: [
|
|
6392
|
+
contractCreationConfig,
|
|
6393
|
+
premintConfig,
|
|
6394
|
+
premintSignature,
|
|
6395
|
+
mintArguments,
|
|
6396
|
+
signerContract
|
|
6397
|
+
]
|
|
6398
|
+
});
|
|
6399
|
+
var makePermitToCollectPremintOrNonPremint = ({
|
|
6400
|
+
mintsOwner,
|
|
6401
|
+
chainId,
|
|
6402
|
+
deadline,
|
|
6403
|
+
tokenIds,
|
|
6404
|
+
// this quantity of MINTs will be used to collect premint
|
|
6405
|
+
// and will be burned. This same quantity is the quantity of
|
|
6406
|
+
// premint to collect.
|
|
6407
|
+
quantities,
|
|
6408
|
+
nonce,
|
|
6409
|
+
premint,
|
|
6410
|
+
collect
|
|
6063
6411
|
}) => {
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
const mediaType = mimeTypeToMedia(mimeType);
|
|
6070
|
-
let image = void 0;
|
|
6071
|
-
let animation_url = null;
|
|
6072
|
-
if (isImage(mimeType)) {
|
|
6073
|
-
image = contentUrl;
|
|
6412
|
+
let safeTransferData;
|
|
6413
|
+
if (premint) {
|
|
6414
|
+
safeTransferData = encodePremintOnManager(premint);
|
|
6415
|
+
} else if (collect) {
|
|
6416
|
+
safeTransferData = encodeCollectOnManager(collect);
|
|
6074
6417
|
} else {
|
|
6075
|
-
|
|
6076
|
-
animation_url = mediaUrl;
|
|
6418
|
+
throw new Error("Invalid operation");
|
|
6077
6419
|
}
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6420
|
+
return makePermitTransferBatchAndTypeData({
|
|
6421
|
+
tokenIds,
|
|
6422
|
+
quantities,
|
|
6423
|
+
chainId,
|
|
6424
|
+
mintsOwner,
|
|
6425
|
+
nonce,
|
|
6426
|
+
deadline,
|
|
6427
|
+
safeTransferData,
|
|
6428
|
+
to: import_protocol_deployments12.zoraMintsManagerImplConfig.address[chainId]
|
|
6429
|
+
});
|
|
6430
|
+
};
|
|
6431
|
+
function collectPremintV2WithMintsParams({
|
|
6432
|
+
tokenIds,
|
|
6433
|
+
quantities,
|
|
6434
|
+
paidMintPricePerToken,
|
|
6435
|
+
account,
|
|
6436
|
+
chainId,
|
|
6437
|
+
...rest
|
|
6438
|
+
}) {
|
|
6439
|
+
const call = encodePremintOnManager({
|
|
6440
|
+
...rest
|
|
6441
|
+
});
|
|
6442
|
+
return makeContractParameters({
|
|
6443
|
+
abi: import_protocol_deployments12.zoraMints1155Config.abi,
|
|
6444
|
+
address: import_protocol_deployments12.zoraMints1155Config.address[chainId],
|
|
6445
|
+
functionName: "transferBatchToManagerAndCall",
|
|
6446
|
+
args: [tokenIds, quantities, call],
|
|
6447
|
+
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
6448
|
+
account
|
|
6449
|
+
});
|
|
6450
|
+
}
|
|
6451
|
+
function decodeCallFailedError(error) {
|
|
6452
|
+
if (error.data?.errorName !== "CallFailed")
|
|
6453
|
+
throw new Error("Not a CallFailed error");
|
|
6454
|
+
const internalErrorData = error.data?.args?.[0];
|
|
6455
|
+
return (0, import_viem11.decodeErrorResult)({
|
|
6456
|
+
abi: import_protocol_deployments12.zoraMintsManagerImplABI,
|
|
6457
|
+
data: internalErrorData
|
|
6458
|
+
});
|
|
6459
|
+
}
|
|
6460
|
+
|
|
6461
|
+
// src/sdk.ts
|
|
6462
|
+
function createCreatorClient(clientConfig) {
|
|
6463
|
+
const premintClient = new PremintClient({
|
|
6464
|
+
chainId: clientConfig.chainId,
|
|
6465
|
+
publicClient: clientConfig.publicClient,
|
|
6466
|
+
premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
|
|
6467
|
+
});
|
|
6468
|
+
const create1155CreatorClient = new Create1155Client({
|
|
6469
|
+
chainId: clientConfig.chainId,
|
|
6470
|
+
publicClient: clientConfig.publicClient
|
|
6471
|
+
});
|
|
6084
6472
|
return {
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
attributes
|
|
6473
|
+
createPremint: (p) => premintClient.createPremint(p),
|
|
6474
|
+
updatePremint: (p) => premintClient.updatePremint(p),
|
|
6475
|
+
deletePremint: (p) => premintClient.deletePremint(p),
|
|
6476
|
+
create1155: (p) => create1155CreatorClient.createNew1155(p),
|
|
6477
|
+
create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
|
|
6091
6478
|
};
|
|
6092
|
-
}
|
|
6479
|
+
}
|
|
6480
|
+
function createCollectorClient(params) {
|
|
6481
|
+
const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
|
|
6482
|
+
const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
|
|
6483
|
+
const mintClient = new MintClient({
|
|
6484
|
+
publicClient: params.publicClient,
|
|
6485
|
+
premintGetter: premintGetterToUse,
|
|
6486
|
+
mintGetter: mintGetterToUse
|
|
6487
|
+
});
|
|
6488
|
+
return {
|
|
6489
|
+
getPremint: (p) => premintGetterToUse.get({
|
|
6490
|
+
collectionAddress: p.address,
|
|
6491
|
+
uid: p.uid
|
|
6492
|
+
}),
|
|
6493
|
+
getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
|
|
6494
|
+
getToken: (p) => mintClient.get(p),
|
|
6495
|
+
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
6496
|
+
mint: (p) => mintClient.mint(p),
|
|
6497
|
+
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
6498
|
+
};
|
|
6499
|
+
}
|
|
6093
6500
|
|
|
6094
6501
|
// src/ipfs/text-metadata.ts
|
|
6095
6502
|
var CHAR_LIMIT = 1111;
|
|
@@ -6184,6 +6591,26 @@ async function generateTextNftMetadataFiles(text) {
|
|
|
6184
6591
|
thumbnailFile
|
|
6185
6592
|
};
|
|
6186
6593
|
}
|
|
6594
|
+
|
|
6595
|
+
// src/allow-list/allow-list-client.ts
|
|
6596
|
+
var ALLOW_LIST_API_BASE = "http://allowlist.zora.co/";
|
|
6597
|
+
var createAllowList = async ({
|
|
6598
|
+
allowList,
|
|
6599
|
+
httpClient: httpClient2 = httpClient,
|
|
6600
|
+
baseUrl = ALLOW_LIST_API_BASE
|
|
6601
|
+
}) => {
|
|
6602
|
+
const { post: post2, retries: retries2 } = httpClient2;
|
|
6603
|
+
const data = {
|
|
6604
|
+
entries: allowList.entries.map((entry) => ({
|
|
6605
|
+
user: entry.user,
|
|
6606
|
+
maxCanMint: entry.maxCanMint,
|
|
6607
|
+
price: entry.price.toString()
|
|
6608
|
+
}))
|
|
6609
|
+
};
|
|
6610
|
+
return (await retries2(
|
|
6611
|
+
() => post2(`${baseUrl}allowlist`, data)
|
|
6612
|
+
)).root;
|
|
6613
|
+
};
|
|
6187
6614
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6188
6615
|
0 && (module.exports = {
|
|
6189
6616
|
Create1155Client,
|
|
@@ -6196,7 +6623,6 @@ async function generateTextNftMetadataFiles(text) {
|
|
|
6196
6623
|
ZORA_API_BASE,
|
|
6197
6624
|
applyUpdateToPremint,
|
|
6198
6625
|
buildPremintMintCall,
|
|
6199
|
-
collectOnchain,
|
|
6200
6626
|
collectPremint,
|
|
6201
6627
|
collectPremintV2WithMintsParams,
|
|
6202
6628
|
collectWithMintsParams,
|
|
@@ -6204,6 +6630,7 @@ async function generateTextNftMetadataFiles(text) {
|
|
|
6204
6630
|
convertGetPremintApiResponse,
|
|
6205
6631
|
convertGetPremintOfCollectionApiResponse,
|
|
6206
6632
|
convertPremintFromApi,
|
|
6633
|
+
createAllowList,
|
|
6207
6634
|
createCollectorClient,
|
|
6208
6635
|
createCreatorClient,
|
|
6209
6636
|
decodeCallFailedError,
|