@zoralabs/protocol-sdk 0.11.12 → 0.12.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/apis/network-config.d.ts +3 -0
- package/dist/apis/network-config.d.ts.map +1 -0
- package/dist/create/contract-setup.d.ts +3 -4
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/create-client.d.ts +53 -0
- package/dist/create/create-client.d.ts.map +1 -0
- package/dist/create/types.d.ts +11 -3
- package/dist/create/types.d.ts.map +1 -1
- package/dist/fixtures/contract-setup.d.ts +2 -2
- package/dist/fixtures/contract-setup.d.ts.map +1 -1
- package/dist/fixtures/rewards-query-results.d.ts +0 -1
- package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
- package/dist/fixtures/secondary.d.ts +3 -6
- package/dist/fixtures/secondary.d.ts.map +1 -1
- package/dist/index.cjs +1613 -1483
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1594 -1483
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +21 -9
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +24 -22
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/strategies-parsing.d.ts +28 -0
- package/dist/mint/strategies-parsing.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +2 -6
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/types.d.ts +25 -8
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/preminter.d.ts +5 -5
- package/dist/preminter.d.ts.map +1 -1
- package/dist/rewards/rewards-client.d.ts +7 -3
- package/dist/rewards/rewards-client.d.ts.map +1 -1
- package/dist/rewards/rewards-queries.d.ts +14 -11
- package/dist/rewards/rewards-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-queries.d.ts +0 -1
- package/dist/rewards/subgraph-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-rewards-getter.d.ts +2 -8
- package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
- package/dist/sdk.d.ts +9 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/secondary/secondary-client.d.ts +7 -8
- package/dist/secondary/secondary-client.d.ts.map +1 -1
- package/dist/secondary/uniswap/uniswapQuote.d.ts +0 -1
- package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -1
- package/dist/secondary/utils.d.ts +1 -2
- package/dist/secondary/utils.d.ts.map +1 -1
- package/dist/types.d.ts +6 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/apis/network-config.ts +8 -0
- package/src/apis/subgraph-getter.ts +1 -1
- package/src/comments/comments.test.ts +11 -22
- package/src/create/contract-setup.ts +3 -4
- package/src/create/{1155-create-helper.test.ts → create-client.test.ts} +52 -88
- package/src/create/{1155-create-helper.ts → create-client.ts} +129 -63
- package/src/create/types.ts +13 -3
- package/src/fixtures/contract-setup.ts +3 -3
- package/src/fixtures/rewards-query-results.ts +2 -9
- package/src/fixtures/secondary.ts +16 -10
- package/src/index.ts +34 -4
- package/src/mint/mint-client.test.ts +37 -64
- package/src/mint/mint-client.ts +36 -32
- package/src/mint/mint-queries.ts +73 -54
- package/src/mint/strategies-parsing.ts +311 -0
- package/src/mint/subgraph-mint-getter.ts +4 -304
- package/src/mint/types.ts +36 -7
- package/src/premint/premint-api-client.ts +1 -1
- package/src/premint/premint-client.ts +1 -1
- package/src/rewards/rewards-client.test.ts +318 -21
- package/src/rewards/rewards-client.ts +15 -16
- package/src/rewards/rewards-queries.ts +116 -36
- package/src/rewards/subgraph-queries.ts +0 -2
- package/src/rewards/subgraph-rewards-getter.ts +3 -13
- package/src/sdk.ts +9 -7
- package/src/secondary/secondary-client.test.ts +39 -40
- package/src/secondary/secondary-client.ts +14 -33
- package/src/secondary/uniswap/uniswapQuote.ts +3 -2
- package/src/secondary/utils.ts +2 -2
- package/src/types.ts +15 -4
- package/src/utils.ts +9 -3
- package/dist/create/1155-create-helper.d.ts +0 -29
- package/dist/create/1155-create-helper.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2503,1198 +2503,1212 @@ import {
|
|
|
2503
2503
|
premintTypedDataDefinition as premintTypedDataDefinition2
|
|
2504
2504
|
} from "@zoralabs/protocol-deployments";
|
|
2505
2505
|
|
|
2506
|
-
// src/
|
|
2507
|
-
var
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
address
|
|
2512
|
-
pricePerToken
|
|
2513
|
-
saleEnd
|
|
2514
|
-
saleStart
|
|
2515
|
-
maxTokensPerAddress
|
|
2516
|
-
}
|
|
2517
|
-
erc20Minter {
|
|
2518
|
-
address
|
|
2519
|
-
pricePerToken
|
|
2520
|
-
currency
|
|
2521
|
-
saleEnd
|
|
2522
|
-
saleStart
|
|
2523
|
-
maxTokensPerAddress
|
|
2524
|
-
}
|
|
2525
|
-
presale {
|
|
2526
|
-
address
|
|
2527
|
-
presaleStart
|
|
2528
|
-
presaleEnd
|
|
2529
|
-
merkleRoot
|
|
2530
|
-
}
|
|
2531
|
-
zoraTimedMinter {
|
|
2532
|
-
address
|
|
2533
|
-
mintFee
|
|
2534
|
-
saleStart
|
|
2535
|
-
saleEnd
|
|
2536
|
-
erc20Z {
|
|
2537
|
-
id
|
|
2538
|
-
pool
|
|
2539
|
-
}
|
|
2540
|
-
secondaryActivated
|
|
2541
|
-
marketCountdown
|
|
2542
|
-
minimumMarketEth
|
|
2543
|
-
}
|
|
2544
|
-
}`;
|
|
2545
|
-
var TOKEN_FRAGMENT = `
|
|
2546
|
-
fragment Token on ZoraCreateToken {
|
|
2547
|
-
creator
|
|
2548
|
-
tokenId
|
|
2549
|
-
uri
|
|
2550
|
-
totalMinted
|
|
2551
|
-
maxSupply
|
|
2552
|
-
tokenStandard
|
|
2553
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
2554
|
-
...SaleStrategy
|
|
2555
|
-
}
|
|
2556
|
-
contract {
|
|
2557
|
-
address
|
|
2558
|
-
mintFeePerQuantity
|
|
2559
|
-
contractVersion
|
|
2560
|
-
contractURI
|
|
2561
|
-
name
|
|
2562
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
2563
|
-
...SaleStrategy
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
}`;
|
|
2567
|
-
var FRAGMENTS = `
|
|
2568
|
-
${NFT_SALE_STRATEGY_FRAGMENT}
|
|
2569
|
-
${TOKEN_FRAGMENT}
|
|
2570
|
-
`;
|
|
2571
|
-
function buildNftTokenSalesQuery({
|
|
2572
|
-
tokenId,
|
|
2573
|
-
tokenAddress
|
|
2574
|
-
}) {
|
|
2575
|
-
return {
|
|
2576
|
-
query: `
|
|
2577
|
-
${FRAGMENTS}
|
|
2578
|
-
query ($id: ID!) {
|
|
2579
|
-
zoraCreateToken(id: $id) {
|
|
2580
|
-
...Token
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
`,
|
|
2584
|
-
variables: {
|
|
2585
|
-
id: tokenId !== void 0 ? (
|
|
2586
|
-
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
2587
|
-
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
2588
|
-
) : `${tokenAddress.toLowerCase()}-0`
|
|
2589
|
-
},
|
|
2590
|
-
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
2591
|
-
};
|
|
2592
|
-
}
|
|
2593
|
-
function buildContractTokensQuery({
|
|
2594
|
-
tokenAddress
|
|
2595
|
-
}) {
|
|
2596
|
-
return {
|
|
2597
|
-
query: `
|
|
2598
|
-
${FRAGMENTS}
|
|
2599
|
-
query ($contract: Bytes!) {
|
|
2600
|
-
zoraCreateTokens(
|
|
2601
|
-
where: {address: $contract}
|
|
2602
|
-
) {
|
|
2603
|
-
...Token
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
`,
|
|
2607
|
-
variables: {
|
|
2608
|
-
contract: tokenAddress.toLowerCase()
|
|
2609
|
-
},
|
|
2610
|
-
parseResponseData: (responseData) => responseData?.zoraCreateTokens
|
|
2611
|
-
};
|
|
2612
|
-
}
|
|
2613
|
-
function buildPremintsOfContractQuery({
|
|
2614
|
-
tokenAddress
|
|
2506
|
+
// src/utils.ts
|
|
2507
|
+
var makeContractParameters = (args) => args;
|
|
2508
|
+
function mintRecipientOrAccount({
|
|
2509
|
+
mintRecipient,
|
|
2510
|
+
minterAccount
|
|
2615
2511
|
}) {
|
|
2616
|
-
return
|
|
2617
|
-
query: `
|
|
2618
|
-
query ($contractAddress: Bytes!) {
|
|
2619
|
-
premints(where:{contractAddress:$contractAddress}) {
|
|
2620
|
-
uid
|
|
2621
|
-
tokenId
|
|
2622
|
-
}
|
|
2623
|
-
}
|
|
2624
|
-
`,
|
|
2625
|
-
variables: {
|
|
2626
|
-
contractAddress: tokenAddress.toLowerCase()
|
|
2627
|
-
},
|
|
2628
|
-
parseResponseData: (responseData) => responseData?.premints
|
|
2629
|
-
};
|
|
2512
|
+
return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
2630
2513
|
}
|
|
2514
|
+
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
2631
2515
|
|
|
2632
|
-
// src/apis/
|
|
2633
|
-
var
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
}
|
|
2637
|
-
async query({
|
|
2638
|
-
subgraphUrl,
|
|
2639
|
-
query,
|
|
2640
|
-
variables
|
|
2641
|
-
}) {
|
|
2642
|
-
const { retries: retries2, post: post2 } = this.httpClient;
|
|
2643
|
-
const result = await retries2(async () => {
|
|
2644
|
-
return await post2(subgraphUrl, {
|
|
2645
|
-
query,
|
|
2646
|
-
variables
|
|
2647
|
-
});
|
|
2648
|
-
});
|
|
2649
|
-
return result?.data;
|
|
2516
|
+
// src/apis/network-config.ts
|
|
2517
|
+
var getApiNetworkConfigForChain = (chainId) => {
|
|
2518
|
+
if (!networkConfigByChain[chainId]) {
|
|
2519
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
2650
2520
|
}
|
|
2521
|
+
return networkConfigByChain[chainId];
|
|
2651
2522
|
};
|
|
2652
2523
|
|
|
2653
|
-
// src/
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2524
|
+
// src/premint/premint-client.ts
|
|
2525
|
+
var defaultTokenConfigV1MintArguments = () => ({
|
|
2526
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
2527
|
+
maxTokensPerAddress: 0n,
|
|
2528
|
+
pricePerToken: 0n,
|
|
2529
|
+
mintDuration: 0n,
|
|
2530
|
+
mintStart: 0n,
|
|
2531
|
+
royaltyMintSchedule: 0,
|
|
2532
|
+
royaltyBPS: 1e3
|
|
2533
|
+
// 10%,
|
|
2534
|
+
});
|
|
2535
|
+
var pickTokenConfigV1 = (tokenConfig) => ({
|
|
2536
|
+
maxSupply: tokenConfig.maxSupply,
|
|
2537
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
2538
|
+
pricePerToken: tokenConfig.pricePerToken,
|
|
2539
|
+
mintDuration: tokenConfig.mintDuration,
|
|
2540
|
+
mintStart: tokenConfig.mintStart,
|
|
2541
|
+
royaltyBPS: tokenConfig.royaltyBPS,
|
|
2542
|
+
tokenURI: tokenConfig.tokenURI,
|
|
2543
|
+
royaltyRecipient: tokenConfig.payoutRecipient
|
|
2544
|
+
});
|
|
2545
|
+
var pickTokenConfigV2 = (tokenConfig) => ({
|
|
2546
|
+
maxSupply: tokenConfig.maxSupply,
|
|
2547
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
2548
|
+
pricePerToken: tokenConfig.pricePerToken,
|
|
2549
|
+
mintDuration: tokenConfig.mintDuration,
|
|
2550
|
+
mintStart: tokenConfig.mintStart,
|
|
2551
|
+
royaltyBPS: tokenConfig.royaltyBPS,
|
|
2552
|
+
tokenURI: tokenConfig.tokenURI,
|
|
2553
|
+
payoutRecipient: tokenConfig.payoutRecipient,
|
|
2554
|
+
createReferral: tokenConfig.createReferral || zeroAddress2
|
|
2555
|
+
});
|
|
2556
|
+
var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
2557
|
+
...pickTokenConfigV1(tokenConfig),
|
|
2558
|
+
...defaultTokenConfigV1MintArguments(),
|
|
2559
|
+
fixedPriceMinter
|
|
2560
|
+
});
|
|
2561
|
+
var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
2562
|
+
...pickTokenConfigV2(tokenConfig),
|
|
2563
|
+
...defaultTokenConfigV2MintArguments(),
|
|
2564
|
+
fixedPriceMinter
|
|
2565
|
+
});
|
|
2566
|
+
var defaultTokenConfigV2MintArguments = () => ({
|
|
2567
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
2568
|
+
maxTokensPerAddress: 0n,
|
|
2569
|
+
pricePerToken: 0n,
|
|
2570
|
+
mintDuration: 0n,
|
|
2571
|
+
mintStart: 0n,
|
|
2572
|
+
royaltyBPS: 1e3
|
|
2573
|
+
// 10%,
|
|
2574
|
+
});
|
|
2575
|
+
var makeTokenConfigWithDefaults = ({
|
|
2576
|
+
chainId,
|
|
2577
|
+
tokenCreationConfig,
|
|
2578
|
+
supportedPremintVersions: supportedPremintVersions2
|
|
2665
2579
|
}) => {
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
if (atTry <= maxTries) {
|
|
2671
|
-
await wait(atTry * linearBackoffMS);
|
|
2672
|
-
return await retryInternal({
|
|
2673
|
-
tryFn,
|
|
2674
|
-
maxTries,
|
|
2675
|
-
atTry: atTry + 1,
|
|
2676
|
-
linearBackoffMS,
|
|
2677
|
-
shouldRetryOnError
|
|
2678
|
-
});
|
|
2679
|
-
}
|
|
2580
|
+
const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
|
|
2581
|
+
if (!supportedPremintVersions2.includes(PremintConfigVersion2.V2)) {
|
|
2582
|
+
if (tokenCreationConfig.createReferral) {
|
|
2583
|
+
throw new Error("Contract does not support create referral");
|
|
2680
2584
|
}
|
|
2681
|
-
|
|
2585
|
+
return {
|
|
2586
|
+
premintConfigVersion: PremintConfigVersion2.V1,
|
|
2587
|
+
tokenConfig: tokenConfigV1WithDefault(
|
|
2588
|
+
tokenCreationConfig,
|
|
2589
|
+
fixedPriceMinter
|
|
2590
|
+
)
|
|
2591
|
+
};
|
|
2682
2592
|
}
|
|
2593
|
+
return {
|
|
2594
|
+
premintConfigVersion: PremintConfigVersion2.V2,
|
|
2595
|
+
tokenConfig: tokenConfigV2WithDefault(
|
|
2596
|
+
tokenCreationConfig,
|
|
2597
|
+
fixedPriceMinter
|
|
2598
|
+
)
|
|
2599
|
+
};
|
|
2683
2600
|
};
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
...params,
|
|
2687
|
-
atTry: 1
|
|
2688
|
-
});
|
|
2689
|
-
};
|
|
2690
|
-
|
|
2691
|
-
// src/apis/http-api-base.ts
|
|
2692
|
-
var BadResponseError = class extends Error {
|
|
2693
|
-
constructor(message, status, json) {
|
|
2694
|
-
super(message);
|
|
2695
|
-
this.name = "BadResponseError";
|
|
2696
|
-
this.status = status;
|
|
2697
|
-
this.json = json;
|
|
2698
|
-
}
|
|
2699
|
-
};
|
|
2700
|
-
var get = async (url) => {
|
|
2701
|
-
const response = await fetch(url, { method: "GET" });
|
|
2702
|
-
if (response.status !== 200) {
|
|
2703
|
-
let json;
|
|
2601
|
+
function getPremintedLogFromReceipt(receipt) {
|
|
2602
|
+
for (const data of receipt.logs) {
|
|
2704
2603
|
try {
|
|
2705
|
-
|
|
2706
|
-
|
|
2604
|
+
const decodedLog = decodeEventLog({
|
|
2605
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
2606
|
+
eventName: "PremintedV2",
|
|
2607
|
+
...data
|
|
2608
|
+
});
|
|
2609
|
+
if (decodedLog.eventName === "PremintedV2") {
|
|
2610
|
+
return decodedLog.args;
|
|
2611
|
+
}
|
|
2612
|
+
} catch (err) {
|
|
2707
2613
|
}
|
|
2708
|
-
throw new BadResponseError(
|
|
2709
|
-
`Invalid response, status ${response.status}`,
|
|
2710
|
-
response.status,
|
|
2711
|
-
json
|
|
2712
|
-
);
|
|
2713
2614
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
"content-type": "application/json",
|
|
2725
|
-
accept: "application/json"
|
|
2726
|
-
},
|
|
2727
|
-
body: JSON.stringify(data),
|
|
2728
|
-
signal
|
|
2729
|
-
});
|
|
2730
|
-
clearTimeout(timeoutId);
|
|
2731
|
-
if (response.status !== 200) {
|
|
2732
|
-
let json;
|
|
2733
|
-
try {
|
|
2734
|
-
json = await response.json();
|
|
2735
|
-
} catch (e) {
|
|
2736
|
-
}
|
|
2737
|
-
throw new BadResponseError(
|
|
2738
|
-
`Bad response: ${response.status}`,
|
|
2739
|
-
response.status,
|
|
2740
|
-
json
|
|
2741
|
-
);
|
|
2615
|
+
}
|
|
2616
|
+
var PremintClient = class {
|
|
2617
|
+
constructor({
|
|
2618
|
+
chainId,
|
|
2619
|
+
publicClient,
|
|
2620
|
+
premintApi
|
|
2621
|
+
}) {
|
|
2622
|
+
this.chainId = chainId;
|
|
2623
|
+
this.apiClient = premintApi;
|
|
2624
|
+
this.publicClient = publicClient;
|
|
2742
2625
|
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
var defaultShouldRetry = (err) => {
|
|
2746
|
-
return err instanceof BadResponseError && err.status >= 500;
|
|
2747
|
-
};
|
|
2748
|
-
var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
|
|
2749
|
-
return retriesGeneric({
|
|
2750
|
-
tryFn,
|
|
2751
|
-
maxTries,
|
|
2752
|
-
linearBackoffMS,
|
|
2753
|
-
shouldRetryOnError: shouldRetry
|
|
2754
|
-
});
|
|
2755
|
-
};
|
|
2756
|
-
var httpClient = {
|
|
2757
|
-
get,
|
|
2758
|
-
post,
|
|
2759
|
-
retries
|
|
2760
|
-
};
|
|
2761
|
-
|
|
2762
|
-
// src/apis/subgraph-getter.ts
|
|
2763
|
-
var SubgraphGetter = class {
|
|
2764
|
-
constructor(chainId, subgraphQuerier) {
|
|
2765
|
-
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
2766
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
2626
|
+
getDataFromPremintReceipt(receipt, blockExplorerUrl) {
|
|
2627
|
+
return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
|
|
2767
2628
|
}
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2629
|
+
/**
|
|
2630
|
+
* Prepares data for updating a premint
|
|
2631
|
+
*
|
|
2632
|
+
* @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
|
|
2633
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
2634
|
+
*/
|
|
2635
|
+
async updatePremint(args) {
|
|
2636
|
+
return await updatePremint({
|
|
2637
|
+
...args,
|
|
2638
|
+
apiClient: this.apiClient,
|
|
2639
|
+
publicClient: this.publicClient,
|
|
2640
|
+
chainId: this.chainId
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
/**
|
|
2644
|
+
* Prepares data for deleting a premint
|
|
2645
|
+
*
|
|
2646
|
+
* @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
|
|
2647
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
2648
|
+
*/
|
|
2649
|
+
async deletePremint(params) {
|
|
2650
|
+
return deletePremint({
|
|
2651
|
+
...params,
|
|
2652
|
+
apiClient: this.apiClient,
|
|
2653
|
+
publicClient: this.publicClient,
|
|
2654
|
+
chainId: this.chainId
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Prepares data for creating a premint
|
|
2659
|
+
*
|
|
2660
|
+
* @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
|
|
2661
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
2662
|
+
*/
|
|
2663
|
+
async createPremint(parameters) {
|
|
2664
|
+
return createPremint({
|
|
2665
|
+
...parameters,
|
|
2666
|
+
publicClient: this.publicClient,
|
|
2667
|
+
apiClient: this.apiClient,
|
|
2668
|
+
chainId: this.chainId
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Fetches given premint data from the ZORA API.
|
|
2673
|
+
*
|
|
2674
|
+
* @param address Address for the premint contract
|
|
2675
|
+
* @param uid UID for the desired premint
|
|
2676
|
+
* @returns PremintSignatureGetResponse of premint data from the API
|
|
2677
|
+
*/
|
|
2678
|
+
async getPremint({ address, uid }) {
|
|
2679
|
+
return await this.apiClient.get({
|
|
2680
|
+
collectionAddress: address,
|
|
2681
|
+
uid
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Gets the deterministic contract address for a premint collection
|
|
2686
|
+
* @param collection Collection to get the address for
|
|
2687
|
+
* @returns deterministic contract address
|
|
2688
|
+
*/
|
|
2689
|
+
async getCollectionAddress(collection) {
|
|
2690
|
+
return await getPremintCollectionAddress({
|
|
2691
|
+
contract: collection,
|
|
2692
|
+
publicClient: this.publicClient
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
async getMintCosts({
|
|
2696
|
+
tokenContract,
|
|
2697
|
+
quantityToMint,
|
|
2698
|
+
pricePerToken
|
|
2772
2699
|
}) {
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2700
|
+
return await getPremintMintCosts({
|
|
2701
|
+
publicClient: this.publicClient,
|
|
2702
|
+
quantityToMint,
|
|
2703
|
+
tokenContract,
|
|
2704
|
+
tokenPrice: pricePerToken
|
|
2777
2705
|
});
|
|
2778
|
-
return parseResponseData(responseData);
|
|
2779
2706
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2707
|
+
/**
|
|
2708
|
+
* Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
|
|
2709
|
+
* tokens on that contract for the mint recipient.
|
|
2710
|
+
*
|
|
2711
|
+
* @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
|
|
2712
|
+
* @returns receipt, log, zoraURL
|
|
2713
|
+
*/
|
|
2714
|
+
async makeMintParameters({
|
|
2715
|
+
minterAccount,
|
|
2716
|
+
tokenContract,
|
|
2717
|
+
uid,
|
|
2718
|
+
mintArguments,
|
|
2719
|
+
firstMinter
|
|
2720
|
+
}) {
|
|
2721
|
+
return await collectPremint({
|
|
2722
|
+
uid,
|
|
2723
|
+
tokenContract,
|
|
2724
|
+
minterAccount,
|
|
2725
|
+
quantityToMint: mintArguments?.quantityToMint || 1n,
|
|
2726
|
+
mintComment: mintArguments?.mintComment,
|
|
2727
|
+
mintReferral: mintArguments?.mintReferral,
|
|
2728
|
+
mintRecipient: mintArguments?.mintRecipient,
|
|
2729
|
+
firstMinter,
|
|
2730
|
+
premintGetter: this.apiClient,
|
|
2731
|
+
publicClient: this.publicClient
|
|
2732
|
+
});
|
|
2786
2733
|
}
|
|
2787
|
-
return networkConfigByChain[chainId];
|
|
2788
2734
|
};
|
|
2789
|
-
function
|
|
2790
|
-
const
|
|
2791
|
-
return {
|
|
2792
|
-
salesStrategy: {
|
|
2793
|
-
saleType: "fixedPrice",
|
|
2794
|
-
...fixedPrice,
|
|
2795
|
-
maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
|
|
2796
|
-
pricePerToken: BigInt(fixedPrice.pricePerToken),
|
|
2797
|
-
mintFeePerQuantity: contractMintFee
|
|
2798
|
-
},
|
|
2799
|
-
saleEnd,
|
|
2800
|
-
saleActive: BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime
|
|
2801
|
-
};
|
|
2802
|
-
}
|
|
2803
|
-
function parseERC20SalesConfig(erc20Minter, blockTime) {
|
|
2804
|
-
const saleEnd = BigInt(erc20Minter.saleEnd);
|
|
2805
|
-
return {
|
|
2806
|
-
salesStrategy: {
|
|
2807
|
-
saleType: "erc20",
|
|
2808
|
-
...erc20Minter,
|
|
2809
|
-
maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
|
|
2810
|
-
pricePerToken: BigInt(erc20Minter.pricePerToken),
|
|
2811
|
-
mintFeePerQuantity: 0n
|
|
2812
|
-
},
|
|
2813
|
-
saleEnd,
|
|
2814
|
-
saleActive: BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime
|
|
2815
|
-
};
|
|
2816
|
-
}
|
|
2817
|
-
function parsePresaleSalesConfig(presale, contractMintFee, blockTime) {
|
|
2818
|
-
const saleEnd = BigInt(presale.presaleEnd);
|
|
2735
|
+
function getDataFromPremintReceipt(receipt, chainId, blockExplorerUrl) {
|
|
2736
|
+
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
2819
2737
|
return {
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
saleActive: BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime
|
|
2738
|
+
tokenId: premintedLog?.tokenId,
|
|
2739
|
+
collectionAddres: premintedLog?.contractAddress,
|
|
2740
|
+
premintedLog,
|
|
2741
|
+
urls: makeUrls({
|
|
2742
|
+
address: premintedLog?.contractAddress,
|
|
2743
|
+
tokenId: premintedLog?.tokenId,
|
|
2744
|
+
chainId,
|
|
2745
|
+
blockExplorerUrl
|
|
2746
|
+
})
|
|
2830
2747
|
};
|
|
2831
2748
|
}
|
|
2832
|
-
function
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
mintFee: BigInt(zoraTimedMinter.mintFee),
|
|
2840
|
-
saleStart: zoraTimedMinter.saleStart,
|
|
2841
|
-
saleEnd: zoraTimedMinter.saleEnd,
|
|
2842
|
-
erc20Z: zoraTimedMinter.erc20Z.id,
|
|
2843
|
-
pool: zoraTimedMinter.erc20Z.pool,
|
|
2844
|
-
secondaryActivated: zoraTimedMinter.secondaryActivated,
|
|
2845
|
-
mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
|
|
2846
|
-
marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
|
|
2847
|
-
minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
|
|
2848
|
-
},
|
|
2849
|
-
saleEnd: hasSaleEnd ? saleEnd : void 0,
|
|
2850
|
-
secondaryMarketActive: zoraTimedMinter.secondaryActivated,
|
|
2851
|
-
saleActive: BigInt(zoraTimedMinter.saleStart) <= blockTime && (hasSaleEnd ? saleEnd > blockTime : true)
|
|
2852
|
-
};
|
|
2853
|
-
}
|
|
2854
|
-
function parseSalesConfig(targetStrategy, contractMintFee, blockTime) {
|
|
2855
|
-
switch (targetStrategy.type) {
|
|
2856
|
-
case "FIXED_PRICE":
|
|
2857
|
-
return parseFixedPriceSalesConfig(
|
|
2858
|
-
targetStrategy.fixedPrice,
|
|
2859
|
-
contractMintFee,
|
|
2860
|
-
blockTime
|
|
2861
|
-
);
|
|
2862
|
-
case "ERC_20_MINTER":
|
|
2863
|
-
return parseERC20SalesConfig(targetStrategy.erc20Minter, blockTime);
|
|
2864
|
-
case "PRESALE":
|
|
2865
|
-
return parsePresaleSalesConfig(
|
|
2866
|
-
targetStrategy.presale,
|
|
2867
|
-
contractMintFee,
|
|
2868
|
-
blockTime
|
|
2869
|
-
);
|
|
2870
|
-
case "ZORA_TIMED":
|
|
2871
|
-
return parseZoraTimedSalesConfig(
|
|
2872
|
-
targetStrategy.zoraTimedMinter,
|
|
2873
|
-
blockTime
|
|
2874
|
-
);
|
|
2875
|
-
default:
|
|
2876
|
-
throw new Error("Unknown saleType");
|
|
2877
|
-
}
|
|
2878
|
-
}
|
|
2879
|
-
function getTargetStrategy({
|
|
2880
|
-
tokenId,
|
|
2881
|
-
preferredSaleType,
|
|
2882
|
-
token,
|
|
2883
|
-
blockTime,
|
|
2884
|
-
contractMintFee
|
|
2749
|
+
function makePremintReturn({
|
|
2750
|
+
premintConfig,
|
|
2751
|
+
premintConfigVersion,
|
|
2752
|
+
publicClient,
|
|
2753
|
+
apiClient,
|
|
2754
|
+
chainId,
|
|
2755
|
+
...collectionAndAddress
|
|
2885
2756
|
}) {
|
|
2886
|
-
const
|
|
2887
|
-
const
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
);
|
|
2893
|
-
const
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
);
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2757
|
+
const { collection, collectionAddress } = collectionAndAddress;
|
|
2758
|
+
const typedDataDefinition = premintTypedDataDefinition2({
|
|
2759
|
+
verifyingContract: collectionAddress,
|
|
2760
|
+
premintConfig,
|
|
2761
|
+
premintConfigVersion,
|
|
2762
|
+
chainId
|
|
2763
|
+
});
|
|
2764
|
+
const signAndSubmit = async ({
|
|
2765
|
+
walletClient,
|
|
2766
|
+
account,
|
|
2767
|
+
checkSignature
|
|
2768
|
+
}) => {
|
|
2769
|
+
const { signature, signerAccount } = await signPremint({
|
|
2770
|
+
account,
|
|
2771
|
+
walletClient,
|
|
2772
|
+
typedDataDefinition
|
|
2773
|
+
});
|
|
2774
|
+
await submit({
|
|
2775
|
+
signature,
|
|
2776
|
+
checkSignature,
|
|
2777
|
+
account: signerAccount
|
|
2778
|
+
});
|
|
2779
|
+
return {
|
|
2780
|
+
signature,
|
|
2781
|
+
signerAccount
|
|
2782
|
+
};
|
|
2783
|
+
};
|
|
2784
|
+
const submit = async ({
|
|
2785
|
+
signature,
|
|
2786
|
+
checkSignature,
|
|
2787
|
+
account
|
|
2788
|
+
}) => {
|
|
2789
|
+
if (checkSignature) {
|
|
2790
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
2791
|
+
collectionAddress,
|
|
2792
|
+
additionalAdmins: collection?.additionalAdmins,
|
|
2793
|
+
contractAdmin: collection?.contractAdmin,
|
|
2794
|
+
publicClient,
|
|
2795
|
+
signer: account
|
|
2796
|
+
});
|
|
2797
|
+
if (!isAuthorized) {
|
|
2798
|
+
throw new Error("Not authorized to create premint");
|
|
2799
|
+
}
|
|
2910
2800
|
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2801
|
+
await apiClient.postSignature({
|
|
2802
|
+
...toContractCreationConfigOrAddress(collectionAndAddress),
|
|
2803
|
+
signature,
|
|
2804
|
+
premintConfig,
|
|
2805
|
+
premintConfigVersion
|
|
2806
|
+
});
|
|
2807
|
+
};
|
|
2808
|
+
const urls = makeUrls({
|
|
2809
|
+
chainId,
|
|
2810
|
+
address: collectionAddress,
|
|
2811
|
+
uid: premintConfig.uid
|
|
2812
|
+
});
|
|
2813
|
+
return {
|
|
2814
|
+
premintConfig,
|
|
2815
|
+
premintConfigVersion,
|
|
2816
|
+
typedDataDefinition,
|
|
2817
|
+
collectionAddress,
|
|
2818
|
+
signAndSubmit,
|
|
2819
|
+
submit,
|
|
2820
|
+
urls
|
|
2821
|
+
};
|
|
2913
2822
|
}
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
blockTime
|
|
2922
|
-
}) => {
|
|
2923
|
-
const token = await this.querySubgraphWithRetries(
|
|
2924
|
-
buildNftTokenSalesQuery({
|
|
2925
|
-
tokenId,
|
|
2926
|
-
tokenAddress
|
|
2927
|
-
})
|
|
2928
|
-
);
|
|
2929
|
-
if (!token) {
|
|
2930
|
-
throw new Error("Cannot find token");
|
|
2931
|
-
}
|
|
2932
|
-
const defaultMintFee = await this.getContractMintFee(token.contract);
|
|
2933
|
-
return parseTokenQueryResult({
|
|
2934
|
-
token,
|
|
2935
|
-
defaultMintFee,
|
|
2936
|
-
tokenId,
|
|
2937
|
-
preferredSaleType: saleType,
|
|
2938
|
-
blockTime
|
|
2939
|
-
});
|
|
2940
|
-
};
|
|
2941
|
-
}
|
|
2942
|
-
async getContractMintFee(contract) {
|
|
2943
|
-
return BigInt(contract.mintFeePerQuantity);
|
|
2944
|
-
}
|
|
2945
|
-
async getContractMintable({
|
|
2946
|
-
tokenAddress,
|
|
2947
|
-
preferredSaleType,
|
|
2948
|
-
blockTime
|
|
2949
|
-
}) {
|
|
2950
|
-
const tokens = await this.querySubgraphWithRetries(
|
|
2951
|
-
buildContractTokensQuery({
|
|
2952
|
-
tokenAddress
|
|
2953
|
-
})
|
|
2954
|
-
);
|
|
2955
|
-
if (!tokens || tokens.length === 0)
|
|
2956
|
-
return [];
|
|
2957
|
-
const defaultMintFee = await this.getContractMintFee(tokens[0].contract);
|
|
2958
|
-
return tokens.filter((x) => x.tokenId !== "0").map(
|
|
2959
|
-
(token) => parseTokenQueryResult({
|
|
2960
|
-
token,
|
|
2961
|
-
tokenId: token.tokenId,
|
|
2962
|
-
preferredSaleType,
|
|
2963
|
-
defaultMintFee,
|
|
2964
|
-
blockTime
|
|
2965
|
-
})
|
|
2966
|
-
);
|
|
2823
|
+
async function signPremint({
|
|
2824
|
+
account,
|
|
2825
|
+
walletClient,
|
|
2826
|
+
typedDataDefinition
|
|
2827
|
+
}) {
|
|
2828
|
+
if (!account) {
|
|
2829
|
+
account = walletClient.account;
|
|
2967
2830
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
}) {
|
|
2971
|
-
const premints = await this.querySubgraphWithRetries(
|
|
2972
|
-
buildPremintsOfContractQuery({
|
|
2973
|
-
tokenAddress
|
|
2974
|
-
})
|
|
2975
|
-
);
|
|
2976
|
-
return premints?.map((premint) => ({
|
|
2977
|
-
tokenId: BigInt(premint.tokenId),
|
|
2978
|
-
uid: +premint.uid
|
|
2979
|
-
})) || [];
|
|
2831
|
+
if (!account) {
|
|
2832
|
+
throw new Error("No account provided");
|
|
2980
2833
|
}
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
tokenId,
|
|
2985
|
-
preferredSaleType,
|
|
2986
|
-
defaultMintFee,
|
|
2987
|
-
blockTime
|
|
2988
|
-
}) {
|
|
2989
|
-
const targetStrategy = getTargetStrategy({
|
|
2990
|
-
tokenId,
|
|
2991
|
-
preferredSaleType,
|
|
2992
|
-
token,
|
|
2993
|
-
blockTime,
|
|
2994
|
-
contractMintFee: defaultMintFee
|
|
2834
|
+
const signature = await walletClient.signTypedData({
|
|
2835
|
+
account,
|
|
2836
|
+
...typedDataDefinition
|
|
2995
2837
|
});
|
|
2996
|
-
return
|
|
2838
|
+
return {
|
|
2839
|
+
signature,
|
|
2840
|
+
signerAccount: account
|
|
2841
|
+
};
|
|
2997
2842
|
}
|
|
2998
|
-
function
|
|
2999
|
-
token,
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
2843
|
+
async function createPremint({
|
|
2844
|
+
token: tokenCreationConfig,
|
|
2845
|
+
uid,
|
|
2846
|
+
publicClient,
|
|
2847
|
+
apiClient,
|
|
2848
|
+
chainId,
|
|
2849
|
+
...collectionOrAddress
|
|
3004
2850
|
}) {
|
|
3005
|
-
const
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
2851
|
+
const {
|
|
2852
|
+
premintConfig,
|
|
2853
|
+
premintConfigVersion,
|
|
2854
|
+
collectionAddress: collectionAddressToUse
|
|
2855
|
+
} = await prepareCreatePremintConfig({
|
|
2856
|
+
...collectionOrAddress,
|
|
2857
|
+
tokenCreationConfig,
|
|
2858
|
+
uid,
|
|
2859
|
+
publicClient,
|
|
2860
|
+
apiClient,
|
|
2861
|
+
chainId
|
|
3011
2862
|
});
|
|
3012
|
-
|
|
3013
|
-
|
|
2863
|
+
return makePremintReturn({
|
|
2864
|
+
premintConfig,
|
|
2865
|
+
premintConfigVersion,
|
|
2866
|
+
collectionAddress: collectionAddressToUse,
|
|
2867
|
+
collection: collectionOrAddress.contract,
|
|
2868
|
+
publicClient,
|
|
2869
|
+
apiClient,
|
|
2870
|
+
chainId
|
|
3014
2871
|
});
|
|
3015
|
-
return {
|
|
3016
|
-
salesConfigAndTokenInfo: {
|
|
3017
|
-
...tokenInfo,
|
|
3018
|
-
salesConfig: salesStrategyAndMintInfo?.salesStrategy
|
|
3019
|
-
},
|
|
3020
|
-
primaryMintActive: salesStrategyAndMintInfo?.saleActive ?? false,
|
|
3021
|
-
primaryMintEnd: salesStrategyAndMintInfo?.saleEnd,
|
|
3022
|
-
secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
|
|
3023
|
-
};
|
|
3024
2872
|
}
|
|
3025
|
-
function
|
|
3026
|
-
|
|
2873
|
+
async function prepareCreatePremintConfig({
|
|
2874
|
+
tokenCreationConfig,
|
|
2875
|
+
uid,
|
|
2876
|
+
publicClient,
|
|
2877
|
+
apiClient,
|
|
2878
|
+
chainId,
|
|
2879
|
+
...collectionOrAddress
|
|
3027
2880
|
}) {
|
|
2881
|
+
const newContractAddress = await getPremintCollectionAddress({
|
|
2882
|
+
publicClient,
|
|
2883
|
+
...collectionOrAddress
|
|
2884
|
+
});
|
|
2885
|
+
let uidToUse = uid;
|
|
2886
|
+
if (typeof uidToUse !== "number") {
|
|
2887
|
+
uidToUse = await apiClient.getNextUID(newContractAddress);
|
|
2888
|
+
}
|
|
2889
|
+
const supportedVersions = await supportedPremintVersions({
|
|
2890
|
+
tokenContract: newContractAddress,
|
|
2891
|
+
publicClient
|
|
2892
|
+
});
|
|
2893
|
+
const tokenConfigAndVersion = makeTokenConfigWithDefaults({
|
|
2894
|
+
tokenCreationConfig,
|
|
2895
|
+
chainId,
|
|
2896
|
+
supportedPremintVersions: supportedVersions
|
|
2897
|
+
});
|
|
2898
|
+
const premintConfig = makeNewPremint({
|
|
2899
|
+
...tokenConfigAndVersion,
|
|
2900
|
+
uid: uidToUse
|
|
2901
|
+
});
|
|
2902
|
+
const premintConfigAndVersion = {
|
|
2903
|
+
premintConfig,
|
|
2904
|
+
premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
|
|
2905
|
+
};
|
|
3028
2906
|
return {
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
name: token.contract.name,
|
|
3032
|
-
URI: token.contract.contractURI
|
|
3033
|
-
},
|
|
3034
|
-
tokenURI: token.uri,
|
|
3035
|
-
tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
|
|
3036
|
-
mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
|
|
3037
|
-
creator: token.creator,
|
|
3038
|
-
totalMinted: BigInt(token.totalMinted),
|
|
3039
|
-
maxSupply: BigInt(token.maxSupply),
|
|
3040
|
-
contractVersion: token.contract.contractVersion
|
|
2907
|
+
...premintConfigAndVersion,
|
|
2908
|
+
collectionAddress: newContractAddress
|
|
3041
2909
|
};
|
|
3042
2910
|
}
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
2911
|
+
async function updatePremint({
|
|
2912
|
+
uid,
|
|
2913
|
+
collection,
|
|
2914
|
+
tokenConfigUpdates,
|
|
2915
|
+
apiClient,
|
|
2916
|
+
publicClient,
|
|
2917
|
+
chainId
|
|
2918
|
+
}) {
|
|
2919
|
+
const {
|
|
2920
|
+
premint: { premintConfig, premintConfigVersion },
|
|
2921
|
+
collection: collectionCreationConfig
|
|
2922
|
+
} = await apiClient.get({
|
|
2923
|
+
collectionAddress: collection,
|
|
2924
|
+
uid
|
|
2925
|
+
});
|
|
2926
|
+
const updatedPremint = applyUpdateToPremint({
|
|
2927
|
+
uid: premintConfig.uid,
|
|
2928
|
+
version: premintConfig.version,
|
|
2929
|
+
tokenConfig: premintConfig.tokenConfig,
|
|
2930
|
+
tokenConfigUpdates
|
|
2931
|
+
});
|
|
2932
|
+
return makePremintReturn({
|
|
2933
|
+
premintConfig: updatedPremint,
|
|
2934
|
+
premintConfigVersion,
|
|
2935
|
+
collectionAddress: collection,
|
|
2936
|
+
collection: collectionCreationConfig,
|
|
2937
|
+
publicClient,
|
|
2938
|
+
apiClient,
|
|
2939
|
+
chainId
|
|
2940
|
+
});
|
|
2941
|
+
}
|
|
2942
|
+
async function deletePremint({
|
|
2943
|
+
uid,
|
|
2944
|
+
collection,
|
|
2945
|
+
publicClient,
|
|
2946
|
+
apiClient,
|
|
2947
|
+
chainId
|
|
2948
|
+
}) {
|
|
2949
|
+
const {
|
|
2950
|
+
premint: { premintConfig, premintConfigVersion },
|
|
2951
|
+
collection: collectionCreationConfig,
|
|
2952
|
+
collectionAddress
|
|
2953
|
+
} = await apiClient.get({
|
|
2954
|
+
collectionAddress: collection,
|
|
2955
|
+
uid
|
|
2956
|
+
});
|
|
2957
|
+
const deletedPremint = {
|
|
2958
|
+
...premintConfig,
|
|
2959
|
+
version: premintConfig.version + 1,
|
|
2960
|
+
deleted: true
|
|
2961
|
+
};
|
|
2962
|
+
return makePremintReturn({
|
|
2963
|
+
premintConfig: deletedPremint,
|
|
2964
|
+
premintConfigVersion,
|
|
2965
|
+
collectionAddress,
|
|
2966
|
+
collection: collectionCreationConfig,
|
|
2967
|
+
publicClient,
|
|
2968
|
+
apiClient,
|
|
2969
|
+
chainId
|
|
2970
|
+
});
|
|
2971
|
+
}
|
|
2972
|
+
async function collectPremint({
|
|
2973
|
+
uid,
|
|
2974
|
+
tokenContract,
|
|
2975
|
+
minterAccount,
|
|
2976
|
+
quantityToMint,
|
|
2977
|
+
mintComment = "",
|
|
2978
|
+
mintReferral,
|
|
3047
2979
|
mintRecipient,
|
|
3048
|
-
|
|
2980
|
+
firstMinter,
|
|
2981
|
+
premintGetter,
|
|
2982
|
+
publicClient
|
|
3049
2983
|
}) {
|
|
3050
|
-
|
|
2984
|
+
if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
|
|
2985
|
+
throw new Error("Quantity to mint cannot be below 1");
|
|
2986
|
+
}
|
|
2987
|
+
const premint = await premintGetter.get({
|
|
2988
|
+
collectionAddress: tokenContract,
|
|
2989
|
+
uid
|
|
2990
|
+
});
|
|
2991
|
+
const mintFee = await getPremintMintFee({
|
|
2992
|
+
tokenContract,
|
|
2993
|
+
publicClient
|
|
2994
|
+
});
|
|
2995
|
+
return buildPremintMintCall({
|
|
2996
|
+
mintArguments: {
|
|
2997
|
+
minterAccount,
|
|
2998
|
+
quantityToMint,
|
|
2999
|
+
firstMinter,
|
|
3000
|
+
mintComment,
|
|
3001
|
+
mintRecipient,
|
|
3002
|
+
mintReferral
|
|
3003
|
+
},
|
|
3004
|
+
mintFee,
|
|
3005
|
+
premint
|
|
3006
|
+
});
|
|
3051
3007
|
}
|
|
3052
|
-
var
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
// 10%,
|
|
3064
|
-
});
|
|
3065
|
-
var pickTokenConfigV1 = (tokenConfig) => ({
|
|
3066
|
-
maxSupply: tokenConfig.maxSupply,
|
|
3067
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
3068
|
-
pricePerToken: tokenConfig.pricePerToken,
|
|
3069
|
-
mintDuration: tokenConfig.mintDuration,
|
|
3070
|
-
mintStart: tokenConfig.mintStart,
|
|
3071
|
-
royaltyBPS: tokenConfig.royaltyBPS,
|
|
3072
|
-
tokenURI: tokenConfig.tokenURI,
|
|
3073
|
-
royaltyRecipient: tokenConfig.payoutRecipient
|
|
3074
|
-
});
|
|
3075
|
-
var pickTokenConfigV2 = (tokenConfig) => ({
|
|
3076
|
-
maxSupply: tokenConfig.maxSupply,
|
|
3077
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
3078
|
-
pricePerToken: tokenConfig.pricePerToken,
|
|
3079
|
-
mintDuration: tokenConfig.mintDuration,
|
|
3080
|
-
mintStart: tokenConfig.mintStart,
|
|
3081
|
-
royaltyBPS: tokenConfig.royaltyBPS,
|
|
3082
|
-
tokenURI: tokenConfig.tokenURI,
|
|
3083
|
-
payoutRecipient: tokenConfig.payoutRecipient,
|
|
3084
|
-
createReferral: tokenConfig.createReferral || zeroAddress2
|
|
3085
|
-
});
|
|
3086
|
-
var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
3087
|
-
...pickTokenConfigV1(tokenConfig),
|
|
3088
|
-
...defaultTokenConfigV1MintArguments(),
|
|
3089
|
-
fixedPriceMinter
|
|
3090
|
-
});
|
|
3091
|
-
var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
3092
|
-
...pickTokenConfigV2(tokenConfig),
|
|
3093
|
-
...defaultTokenConfigV2MintArguments(),
|
|
3094
|
-
fixedPriceMinter
|
|
3095
|
-
});
|
|
3096
|
-
var defaultTokenConfigV2MintArguments = () => ({
|
|
3097
|
-
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
3098
|
-
maxTokensPerAddress: 0n,
|
|
3099
|
-
pricePerToken: 0n,
|
|
3100
|
-
mintDuration: 0n,
|
|
3101
|
-
mintStart: 0n,
|
|
3102
|
-
royaltyBPS: 1e3
|
|
3103
|
-
// 10%,
|
|
3104
|
-
});
|
|
3105
|
-
var makeTokenConfigWithDefaults = ({
|
|
3106
|
-
chainId,
|
|
3107
|
-
tokenCreationConfig,
|
|
3108
|
-
supportedPremintVersions: supportedPremintVersions2
|
|
3008
|
+
var buildPremintMintCall = ({
|
|
3009
|
+
mintArguments: {
|
|
3010
|
+
minterAccount,
|
|
3011
|
+
mintComment = "",
|
|
3012
|
+
mintRecipient,
|
|
3013
|
+
mintReferral,
|
|
3014
|
+
firstMinter,
|
|
3015
|
+
quantityToMint
|
|
3016
|
+
},
|
|
3017
|
+
premint: { collection, collectionAddress, premint, signature },
|
|
3018
|
+
mintFee
|
|
3109
3019
|
}) => {
|
|
3110
|
-
const
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
fixedPriceMinter
|
|
3120
|
-
)
|
|
3121
|
-
};
|
|
3122
|
-
}
|
|
3123
|
-
return {
|
|
3124
|
-
premintConfigVersion: PremintConfigVersion2.V2,
|
|
3125
|
-
tokenConfig: tokenConfigV2WithDefault(
|
|
3126
|
-
tokenCreationConfig,
|
|
3127
|
-
fixedPriceMinter
|
|
3128
|
-
)
|
|
3020
|
+
const mintArgumentsContract = {
|
|
3021
|
+
mintComment,
|
|
3022
|
+
mintRecipient: mintRecipientOrAccount({
|
|
3023
|
+
mintRecipient,
|
|
3024
|
+
minterAccount
|
|
3025
|
+
}),
|
|
3026
|
+
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
3027
|
+
mintReferral
|
|
3028
|
+
})
|
|
3129
3029
|
};
|
|
3030
|
+
const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
|
|
3031
|
+
const collectionAddressToSubmit = collection ? zeroAddress2 : collectionAddress;
|
|
3032
|
+
const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
3033
|
+
if (premint.premintConfigVersion === PremintConfigVersion2.V3) {
|
|
3034
|
+
throw new Error("PremintV3 not supported in premint SDK");
|
|
3035
|
+
}
|
|
3036
|
+
const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
|
|
3037
|
+
return makeContractParameters({
|
|
3038
|
+
account: minterAccount,
|
|
3039
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
3040
|
+
functionName: "premint",
|
|
3041
|
+
value,
|
|
3042
|
+
address: getPremintExecutorAddress(),
|
|
3043
|
+
args: [
|
|
3044
|
+
collectionOrEmpty,
|
|
3045
|
+
collectionAddressToSubmit,
|
|
3046
|
+
encodePremintConfig(premint),
|
|
3047
|
+
signature,
|
|
3048
|
+
BigInt(quantityToMint),
|
|
3049
|
+
mintArgumentsContract,
|
|
3050
|
+
firstMinterToSubmit,
|
|
3051
|
+
zeroAddress2
|
|
3052
|
+
]
|
|
3053
|
+
});
|
|
3130
3054
|
};
|
|
3131
|
-
function
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
return decodedLog.args;
|
|
3141
|
-
}
|
|
3142
|
-
} catch (err) {
|
|
3143
|
-
}
|
|
3055
|
+
function makeUrls({
|
|
3056
|
+
uid,
|
|
3057
|
+
address,
|
|
3058
|
+
tokenId,
|
|
3059
|
+
chainId,
|
|
3060
|
+
blockExplorerUrl
|
|
3061
|
+
}) {
|
|
3062
|
+
if ((!uid || !tokenId) && !address) {
|
|
3063
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
3144
3064
|
}
|
|
3065
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
3066
|
+
const network = getApiNetworkConfigForChain(chainId);
|
|
3067
|
+
return {
|
|
3068
|
+
explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
|
|
3069
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
|
|
3070
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
|
|
3071
|
+
};
|
|
3145
3072
|
}
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
}
|
|
3186
|
-
|
|
3187
|
-
/**
|
|
3188
|
-
* Prepares data for creating a premint
|
|
3189
|
-
*
|
|
3190
|
-
* @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
|
|
3191
|
-
* @returns A PremintReturn. {@link PremintReturn}
|
|
3192
|
-
*/
|
|
3193
|
-
async createPremint(parameters) {
|
|
3194
|
-
return createPremint({
|
|
3195
|
-
...parameters,
|
|
3196
|
-
publicClient: this.publicClient,
|
|
3197
|
-
apiClient: this.apiClient,
|
|
3198
|
-
chainId: this.chainId
|
|
3199
|
-
});
|
|
3200
|
-
}
|
|
3201
|
-
/**
|
|
3202
|
-
* Fetches given premint data from the ZORA API.
|
|
3203
|
-
*
|
|
3204
|
-
* @param address Address for the premint contract
|
|
3205
|
-
* @param uid UID for the desired premint
|
|
3206
|
-
* @returns PremintSignatureGetResponse of premint data from the API
|
|
3207
|
-
*/
|
|
3208
|
-
async getPremint({ address, uid }) {
|
|
3209
|
-
return await this.apiClient.get({
|
|
3210
|
-
collectionAddress: address,
|
|
3211
|
-
uid
|
|
3212
|
-
});
|
|
3213
|
-
}
|
|
3214
|
-
/**
|
|
3215
|
-
* Gets the deterministic contract address for a premint collection
|
|
3216
|
-
* @param collection Collection to get the address for
|
|
3217
|
-
* @returns deterministic contract address
|
|
3218
|
-
*/
|
|
3219
|
-
async getCollectionAddress(collection) {
|
|
3220
|
-
return await getPremintCollectionAddress({
|
|
3221
|
-
contract: collection,
|
|
3222
|
-
publicClient: this.publicClient
|
|
3223
|
-
});
|
|
3073
|
+
|
|
3074
|
+
// src/premint/contract-types.ts
|
|
3075
|
+
import {
|
|
3076
|
+
PremintConfigVersion as PremintConfigVersionOrig
|
|
3077
|
+
} from "@zoralabs/protocol-deployments";
|
|
3078
|
+
var PremintConfigVersion3 = ((PremintConfigVersion4) => {
|
|
3079
|
+
PremintConfigVersion4[PremintConfigVersion4["V1"] = PremintConfigVersionOrig.V1] = "V1";
|
|
3080
|
+
PremintConfigVersion4[PremintConfigVersion4["V2"] = PremintConfigVersionOrig.V2] = "V2";
|
|
3081
|
+
PremintConfigVersion4[PremintConfigVersion4["V3"] = PremintConfigVersionOrig.V3] = "V3";
|
|
3082
|
+
return PremintConfigVersion4;
|
|
3083
|
+
})(PremintConfigVersion3 || {});
|
|
3084
|
+
|
|
3085
|
+
// src/retries.ts
|
|
3086
|
+
async function wait(delayMs) {
|
|
3087
|
+
return new Promise((resolve) => {
|
|
3088
|
+
setTimeout(resolve, delayMs);
|
|
3089
|
+
});
|
|
3090
|
+
}
|
|
3091
|
+
var retryInternal = async ({
|
|
3092
|
+
tryFn,
|
|
3093
|
+
maxTries = 3,
|
|
3094
|
+
atTry,
|
|
3095
|
+
linearBackoffMS = 200,
|
|
3096
|
+
shouldRetryOnError = () => true
|
|
3097
|
+
}) => {
|
|
3098
|
+
try {
|
|
3099
|
+
return await tryFn();
|
|
3100
|
+
} catch (err) {
|
|
3101
|
+
if (shouldRetryOnError(err)) {
|
|
3102
|
+
if (atTry <= maxTries) {
|
|
3103
|
+
await wait(atTry * linearBackoffMS);
|
|
3104
|
+
return await retryInternal({
|
|
3105
|
+
tryFn,
|
|
3106
|
+
maxTries,
|
|
3107
|
+
atTry: atTry + 1,
|
|
3108
|
+
linearBackoffMS,
|
|
3109
|
+
shouldRetryOnError
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
throw err;
|
|
3224
3114
|
}
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3115
|
+
};
|
|
3116
|
+
var retriesGeneric = async (params) => {
|
|
3117
|
+
return retryInternal({
|
|
3118
|
+
...params,
|
|
3119
|
+
atTry: 1
|
|
3120
|
+
});
|
|
3121
|
+
};
|
|
3122
|
+
|
|
3123
|
+
// src/apis/http-api-base.ts
|
|
3124
|
+
var BadResponseError = class extends Error {
|
|
3125
|
+
constructor(message, status, json) {
|
|
3126
|
+
super(message);
|
|
3127
|
+
this.name = "BadResponseError";
|
|
3128
|
+
this.status = status;
|
|
3129
|
+
this.json = json;
|
|
3236
3130
|
}
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
return await collectPremint({
|
|
3252
|
-
uid,
|
|
3253
|
-
tokenContract,
|
|
3254
|
-
minterAccount,
|
|
3255
|
-
quantityToMint: mintArguments?.quantityToMint || 1n,
|
|
3256
|
-
mintComment: mintArguments?.mintComment,
|
|
3257
|
-
mintReferral: mintArguments?.mintReferral,
|
|
3258
|
-
mintRecipient: mintArguments?.mintRecipient,
|
|
3259
|
-
firstMinter,
|
|
3260
|
-
premintGetter: this.apiClient,
|
|
3261
|
-
publicClient: this.publicClient
|
|
3262
|
-
});
|
|
3131
|
+
};
|
|
3132
|
+
var get = async (url) => {
|
|
3133
|
+
const response = await fetch(url, { method: "GET" });
|
|
3134
|
+
if (response.status !== 200) {
|
|
3135
|
+
let json;
|
|
3136
|
+
try {
|
|
3137
|
+
json = await response.json();
|
|
3138
|
+
} catch (e) {
|
|
3139
|
+
}
|
|
3140
|
+
throw new BadResponseError(
|
|
3141
|
+
`Invalid response, status ${response.status}`,
|
|
3142
|
+
response.status,
|
|
3143
|
+
json
|
|
3144
|
+
);
|
|
3263
3145
|
}
|
|
3146
|
+
return await response.json();
|
|
3264
3147
|
};
|
|
3265
|
-
|
|
3266
|
-
const
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
}
|
|
3279
|
-
function makePremintReturn({
|
|
3280
|
-
premintConfig,
|
|
3281
|
-
premintConfigVersion,
|
|
3282
|
-
publicClient,
|
|
3283
|
-
apiClient,
|
|
3284
|
-
chainId,
|
|
3285
|
-
...collectionAndAddress
|
|
3286
|
-
}) {
|
|
3287
|
-
const { collection, collectionAddress } = collectionAndAddress;
|
|
3288
|
-
const typedDataDefinition = premintTypedDataDefinition2({
|
|
3289
|
-
verifyingContract: collectionAddress,
|
|
3290
|
-
premintConfig,
|
|
3291
|
-
premintConfigVersion,
|
|
3292
|
-
chainId
|
|
3148
|
+
var post = async (url, data) => {
|
|
3149
|
+
const controller = new AbortController();
|
|
3150
|
+
const { signal } = controller;
|
|
3151
|
+
const timeout = 30 * 60 * 1e3;
|
|
3152
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
3153
|
+
const response = await fetch(url, {
|
|
3154
|
+
method: "POST",
|
|
3155
|
+
headers: {
|
|
3156
|
+
"content-type": "application/json",
|
|
3157
|
+
accept: "application/json"
|
|
3158
|
+
},
|
|
3159
|
+
body: JSON.stringify(data),
|
|
3160
|
+
signal
|
|
3293
3161
|
});
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3162
|
+
clearTimeout(timeoutId);
|
|
3163
|
+
if (response.status !== 200) {
|
|
3164
|
+
let json;
|
|
3165
|
+
try {
|
|
3166
|
+
json = await response.json();
|
|
3167
|
+
} catch (e) {
|
|
3168
|
+
}
|
|
3169
|
+
throw new BadResponseError(
|
|
3170
|
+
`Bad response: ${response.status}`,
|
|
3171
|
+
response.status,
|
|
3172
|
+
json
|
|
3173
|
+
);
|
|
3174
|
+
}
|
|
3175
|
+
return await response.json();
|
|
3176
|
+
};
|
|
3177
|
+
var defaultShouldRetry = (err) => {
|
|
3178
|
+
return err instanceof BadResponseError && err.status >= 500;
|
|
3179
|
+
};
|
|
3180
|
+
var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
|
|
3181
|
+
return retriesGeneric({
|
|
3182
|
+
tryFn,
|
|
3183
|
+
maxTries,
|
|
3184
|
+
linearBackoffMS,
|
|
3185
|
+
shouldRetryOnError: shouldRetry
|
|
3186
|
+
});
|
|
3187
|
+
};
|
|
3188
|
+
var httpClient = {
|
|
3189
|
+
get,
|
|
3190
|
+
post,
|
|
3191
|
+
retries
|
|
3192
|
+
};
|
|
3193
|
+
|
|
3194
|
+
// src/premint/premint-api-client.ts
|
|
3195
|
+
var postSignature = async ({
|
|
3196
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
3197
|
+
...data
|
|
3198
|
+
}) => retries2(
|
|
3199
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
3200
|
+
);
|
|
3201
|
+
var getNextUID = async ({
|
|
3202
|
+
chainId,
|
|
3203
|
+
collection_address,
|
|
3204
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3205
|
+
}) => retries2(
|
|
3206
|
+
() => get2(
|
|
3207
|
+
`${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
|
|
3208
|
+
)
|
|
3209
|
+
);
|
|
3210
|
+
var getSignature = async ({
|
|
3211
|
+
collectionAddress,
|
|
3212
|
+
uid,
|
|
3213
|
+
chainId,
|
|
3214
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3215
|
+
}) => {
|
|
3216
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3217
|
+
const result = await retries2(
|
|
3218
|
+
() => get2(
|
|
3219
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
|
|
3220
|
+
)
|
|
3221
|
+
);
|
|
3222
|
+
return convertGetPremintApiResponse(result);
|
|
3223
|
+
};
|
|
3224
|
+
var getOfCollection = async ({
|
|
3225
|
+
collectionAddress,
|
|
3226
|
+
chainId,
|
|
3227
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3228
|
+
}) => {
|
|
3229
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3230
|
+
const result = await retries2(
|
|
3231
|
+
() => get2(
|
|
3232
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
|
|
3233
|
+
)
|
|
3234
|
+
);
|
|
3235
|
+
return convertGetPremintOfCollectionApiResponse(result);
|
|
3236
|
+
};
|
|
3237
|
+
var PremintAPIClient = class {
|
|
3238
|
+
constructor(chainId, httpClient2) {
|
|
3239
|
+
this.postSignature = ({
|
|
3310
3240
|
signature,
|
|
3311
|
-
|
|
3241
|
+
...rest
|
|
3242
|
+
}) => {
|
|
3243
|
+
const data = encodePostSignatureInput({
|
|
3244
|
+
...rest,
|
|
3245
|
+
chainId: this.chainId,
|
|
3246
|
+
signature
|
|
3247
|
+
});
|
|
3248
|
+
return postSignature({
|
|
3249
|
+
...data,
|
|
3250
|
+
httpClient: this.httpClient
|
|
3251
|
+
});
|
|
3312
3252
|
};
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
3253
|
+
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
3254
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
3255
|
+
chainId: this.chainId,
|
|
3256
|
+
httpClient: this.httpClient
|
|
3257
|
+
})).next_uid;
|
|
3258
|
+
this.get = async ({ collectionAddress, uid }) => {
|
|
3259
|
+
return getSignature({
|
|
3321
3260
|
collectionAddress,
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
signer: account
|
|
3261
|
+
uid,
|
|
3262
|
+
chainId: this.chainId,
|
|
3263
|
+
httpClient: this.httpClient
|
|
3326
3264
|
});
|
|
3327
|
-
|
|
3328
|
-
|
|
3265
|
+
};
|
|
3266
|
+
this.getOfCollection = async ({
|
|
3267
|
+
collectionAddress
|
|
3268
|
+
}) => {
|
|
3269
|
+
return getOfCollection({
|
|
3270
|
+
collectionAddress,
|
|
3271
|
+
chainId: this.chainId,
|
|
3272
|
+
httpClient: this.httpClient
|
|
3273
|
+
});
|
|
3274
|
+
};
|
|
3275
|
+
this.chainId = chainId;
|
|
3276
|
+
this.httpClient = httpClient2 || httpClient;
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
|
|
3280
|
+
// src/mint/subgraph-queries.ts
|
|
3281
|
+
var NFT_SALE_STRATEGY_FRAGMENT = `
|
|
3282
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
3283
|
+
type
|
|
3284
|
+
fixedPrice {
|
|
3285
|
+
address
|
|
3286
|
+
pricePerToken
|
|
3287
|
+
saleEnd
|
|
3288
|
+
saleStart
|
|
3289
|
+
maxTokensPerAddress
|
|
3290
|
+
}
|
|
3291
|
+
erc20Minter {
|
|
3292
|
+
address
|
|
3293
|
+
pricePerToken
|
|
3294
|
+
currency
|
|
3295
|
+
saleEnd
|
|
3296
|
+
saleStart
|
|
3297
|
+
maxTokensPerAddress
|
|
3298
|
+
}
|
|
3299
|
+
presale {
|
|
3300
|
+
address
|
|
3301
|
+
presaleStart
|
|
3302
|
+
presaleEnd
|
|
3303
|
+
merkleRoot
|
|
3304
|
+
}
|
|
3305
|
+
zoraTimedMinter {
|
|
3306
|
+
address
|
|
3307
|
+
mintFee
|
|
3308
|
+
saleStart
|
|
3309
|
+
saleEnd
|
|
3310
|
+
erc20Z {
|
|
3311
|
+
id
|
|
3312
|
+
pool
|
|
3313
|
+
}
|
|
3314
|
+
secondaryActivated
|
|
3315
|
+
marketCountdown
|
|
3316
|
+
minimumMarketEth
|
|
3317
|
+
}
|
|
3318
|
+
}`;
|
|
3319
|
+
var TOKEN_FRAGMENT = `
|
|
3320
|
+
fragment Token on ZoraCreateToken {
|
|
3321
|
+
creator
|
|
3322
|
+
tokenId
|
|
3323
|
+
uri
|
|
3324
|
+
totalMinted
|
|
3325
|
+
maxSupply
|
|
3326
|
+
tokenStandard
|
|
3327
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
3328
|
+
...SaleStrategy
|
|
3329
|
+
}
|
|
3330
|
+
contract {
|
|
3331
|
+
address
|
|
3332
|
+
mintFeePerQuantity
|
|
3333
|
+
contractVersion
|
|
3334
|
+
contractURI
|
|
3335
|
+
name
|
|
3336
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
3337
|
+
...SaleStrategy
|
|
3329
3338
|
}
|
|
3330
3339
|
}
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
address: collectionAddress,
|
|
3341
|
-
uid: premintConfig.uid
|
|
3342
|
-
});
|
|
3340
|
+
}`;
|
|
3341
|
+
var FRAGMENTS = `
|
|
3342
|
+
${NFT_SALE_STRATEGY_FRAGMENT}
|
|
3343
|
+
${TOKEN_FRAGMENT}
|
|
3344
|
+
`;
|
|
3345
|
+
function buildNftTokenSalesQuery({
|
|
3346
|
+
tokenId,
|
|
3347
|
+
tokenAddress
|
|
3348
|
+
}) {
|
|
3343
3349
|
return {
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3350
|
+
query: `
|
|
3351
|
+
${FRAGMENTS}
|
|
3352
|
+
query ($id: ID!) {
|
|
3353
|
+
zoraCreateToken(id: $id) {
|
|
3354
|
+
...Token
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
`,
|
|
3358
|
+
variables: {
|
|
3359
|
+
id: tokenId !== void 0 ? (
|
|
3360
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
3361
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
3362
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
3363
|
+
},
|
|
3364
|
+
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
3351
3365
|
};
|
|
3352
3366
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
walletClient,
|
|
3356
|
-
typedDataDefinition
|
|
3367
|
+
function buildContractTokensQuery({
|
|
3368
|
+
tokenAddress
|
|
3357
3369
|
}) {
|
|
3358
|
-
if (!account) {
|
|
3359
|
-
account = walletClient.account;
|
|
3360
|
-
}
|
|
3361
|
-
if (!account) {
|
|
3362
|
-
throw new Error("No account provided");
|
|
3363
|
-
}
|
|
3364
|
-
const signature = await walletClient.signTypedData({
|
|
3365
|
-
account,
|
|
3366
|
-
...typedDataDefinition
|
|
3367
|
-
});
|
|
3368
3370
|
return {
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
+
query: `
|
|
3372
|
+
${FRAGMENTS}
|
|
3373
|
+
query ($contract: Bytes!) {
|
|
3374
|
+
zoraCreateTokens(
|
|
3375
|
+
where: {address: $contract}
|
|
3376
|
+
) {
|
|
3377
|
+
...Token
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
`,
|
|
3381
|
+
variables: {
|
|
3382
|
+
contract: tokenAddress.toLowerCase()
|
|
3383
|
+
},
|
|
3384
|
+
parseResponseData: (responseData) => responseData?.zoraCreateTokens
|
|
3371
3385
|
};
|
|
3372
3386
|
}
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
uid,
|
|
3376
|
-
publicClient,
|
|
3377
|
-
apiClient,
|
|
3378
|
-
chainId,
|
|
3379
|
-
...collectionOrAddress
|
|
3387
|
+
function buildPremintsOfContractQuery({
|
|
3388
|
+
tokenAddress
|
|
3380
3389
|
}) {
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
premintConfigVersion,
|
|
3396
|
-
collectionAddress: collectionAddressToUse,
|
|
3397
|
-
collection: collectionOrAddress.contract,
|
|
3398
|
-
publicClient,
|
|
3399
|
-
apiClient,
|
|
3400
|
-
chainId
|
|
3401
|
-
});
|
|
3390
|
+
return {
|
|
3391
|
+
query: `
|
|
3392
|
+
query ($contractAddress: Bytes!) {
|
|
3393
|
+
premints(where:{contractAddress:$contractAddress}) {
|
|
3394
|
+
uid
|
|
3395
|
+
tokenId
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
`,
|
|
3399
|
+
variables: {
|
|
3400
|
+
contractAddress: tokenAddress.toLowerCase()
|
|
3401
|
+
},
|
|
3402
|
+
parseResponseData: (responseData) => responseData?.premints
|
|
3403
|
+
};
|
|
3402
3404
|
}
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
chainId,
|
|
3409
|
-
...collectionOrAddress
|
|
3410
|
-
}) {
|
|
3411
|
-
const newContractAddress = await getPremintCollectionAddress({
|
|
3412
|
-
publicClient,
|
|
3413
|
-
...collectionOrAddress
|
|
3414
|
-
});
|
|
3415
|
-
let uidToUse = uid;
|
|
3416
|
-
if (typeof uidToUse !== "number") {
|
|
3417
|
-
uidToUse = await apiClient.getNextUID(newContractAddress);
|
|
3405
|
+
|
|
3406
|
+
// src/apis/subgraph-querier.ts
|
|
3407
|
+
var SubgraphQuerier = class {
|
|
3408
|
+
constructor(httpClient2) {
|
|
3409
|
+
this.httpClient = httpClient2;
|
|
3418
3410
|
}
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3411
|
+
async query({
|
|
3412
|
+
subgraphUrl,
|
|
3413
|
+
query,
|
|
3414
|
+
variables
|
|
3415
|
+
}) {
|
|
3416
|
+
const { retries: retries2, post: post2 } = this.httpClient;
|
|
3417
|
+
const result = await retries2(async () => {
|
|
3418
|
+
return await post2(subgraphUrl, {
|
|
3419
|
+
query,
|
|
3420
|
+
variables
|
|
3421
|
+
});
|
|
3422
|
+
});
|
|
3423
|
+
return result?.data;
|
|
3424
|
+
}
|
|
3425
|
+
};
|
|
3426
|
+
|
|
3427
|
+
// src/apis/subgraph-getter.ts
|
|
3428
|
+
var SubgraphGetter = class {
|
|
3429
|
+
constructor(chainId, subgraphQuerier) {
|
|
3430
|
+
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
3431
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
3432
|
+
}
|
|
3433
|
+
async querySubgraphWithRetries({
|
|
3434
|
+
query,
|
|
3435
|
+
variables,
|
|
3436
|
+
parseResponseData
|
|
3437
|
+
}) {
|
|
3438
|
+
const responseData = await this.subgraphQuerier.query({
|
|
3439
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
3440
|
+
query,
|
|
3441
|
+
variables
|
|
3442
|
+
});
|
|
3443
|
+
return parseResponseData(responseData);
|
|
3444
|
+
}
|
|
3445
|
+
};
|
|
3446
|
+
|
|
3447
|
+
// src/mint/strategies-parsing.ts
|
|
3448
|
+
function parseFixedPriceSalesConfig(fixedPrice, contractMintFee) {
|
|
3449
|
+
return {
|
|
3450
|
+
salesStrategy: {
|
|
3451
|
+
saleType: "fixedPrice",
|
|
3452
|
+
...fixedPrice,
|
|
3453
|
+
maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
|
|
3454
|
+
pricePerToken: BigInt(fixedPrice.pricePerToken),
|
|
3455
|
+
mintFeePerQuantity: contractMintFee
|
|
3456
|
+
},
|
|
3457
|
+
saleEnd: BigInt(fixedPrice.saleEnd),
|
|
3458
|
+
saleStart: BigInt(fixedPrice.saleStart)
|
|
3459
|
+
// saleActive:
|
|
3460
|
+
// BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime,
|
|
3435
3461
|
};
|
|
3462
|
+
}
|
|
3463
|
+
function parseERC20SalesConfig(erc20Minter) {
|
|
3436
3464
|
return {
|
|
3437
|
-
|
|
3438
|
-
|
|
3465
|
+
salesStrategy: {
|
|
3466
|
+
saleType: "erc20",
|
|
3467
|
+
...erc20Minter,
|
|
3468
|
+
maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
|
|
3469
|
+
pricePerToken: BigInt(erc20Minter.pricePerToken),
|
|
3470
|
+
mintFeePerQuantity: 0n
|
|
3471
|
+
},
|
|
3472
|
+
saleEnd: BigInt(erc20Minter.saleEnd),
|
|
3473
|
+
saleStart: BigInt(erc20Minter.saleStart)
|
|
3474
|
+
// saleActive:
|
|
3475
|
+
// BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime,
|
|
3439
3476
|
};
|
|
3440
3477
|
}
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3478
|
+
function parsePresaleSalesConfig(presale, contractMintFee) {
|
|
3479
|
+
return {
|
|
3480
|
+
salesStrategy: {
|
|
3481
|
+
saleType: "allowlist",
|
|
3482
|
+
address: presale.address,
|
|
3483
|
+
merkleRoot: presale.merkleRoot,
|
|
3484
|
+
saleStart: presale.presaleStart,
|
|
3485
|
+
saleEnd: presale.presaleEnd,
|
|
3486
|
+
mintFeePerQuantity: contractMintFee
|
|
3487
|
+
},
|
|
3488
|
+
saleEnd: BigInt(presale.presaleEnd),
|
|
3489
|
+
saleStart: BigInt(presale.presaleStart)
|
|
3490
|
+
// saleActive:
|
|
3491
|
+
// BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime,
|
|
3492
|
+
};
|
|
3493
|
+
}
|
|
3494
|
+
function parseZoraTimedSalesConfig(zoraTimedMinter) {
|
|
3495
|
+
const saleEnd = BigInt(zoraTimedMinter.saleEnd);
|
|
3496
|
+
return {
|
|
3497
|
+
salesStrategy: {
|
|
3498
|
+
saleType: "timed",
|
|
3499
|
+
address: zoraTimedMinter.address,
|
|
3500
|
+
mintFee: BigInt(zoraTimedMinter.mintFee),
|
|
3501
|
+
saleStart: zoraTimedMinter.saleStart,
|
|
3502
|
+
saleEnd: zoraTimedMinter.saleEnd,
|
|
3503
|
+
erc20Z: zoraTimedMinter.erc20Z.id,
|
|
3504
|
+
pool: zoraTimedMinter.erc20Z.pool,
|
|
3505
|
+
secondaryActivated: zoraTimedMinter.secondaryActivated,
|
|
3506
|
+
mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
|
|
3507
|
+
marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
|
|
3508
|
+
minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
|
|
3509
|
+
},
|
|
3510
|
+
saleEnd: saleEnd > 0n ? saleEnd : void 0,
|
|
3511
|
+
saleStart: BigInt(zoraTimedMinter.saleStart)
|
|
3512
|
+
// saleActive:
|
|
3513
|
+
// BigInt(zoraTimedMinter.saleStart) <= blockTime &&
|
|
3514
|
+
// (hasSaleEnd ? saleEnd > blockTime : true),
|
|
3515
|
+
};
|
|
3516
|
+
}
|
|
3517
|
+
function parseSalesConfig(targetStrategy, contractMintFee) {
|
|
3518
|
+
switch (targetStrategy.type) {
|
|
3519
|
+
case "FIXED_PRICE":
|
|
3520
|
+
return parseFixedPriceSalesConfig(
|
|
3521
|
+
targetStrategy.fixedPrice,
|
|
3522
|
+
contractMintFee
|
|
3523
|
+
// blockTime,
|
|
3524
|
+
);
|
|
3525
|
+
case "ERC_20_MINTER":
|
|
3526
|
+
return parseERC20SalesConfig(targetStrategy.erc20Minter);
|
|
3527
|
+
case "PRESALE":
|
|
3528
|
+
return parsePresaleSalesConfig(
|
|
3529
|
+
targetStrategy.presale,
|
|
3530
|
+
contractMintFee
|
|
3531
|
+
// blockTime,
|
|
3532
|
+
);
|
|
3533
|
+
case "ZORA_TIMED":
|
|
3534
|
+
return parseZoraTimedSalesConfig(
|
|
3535
|
+
targetStrategy.zoraTimedMinter
|
|
3536
|
+
// blockTime,
|
|
3537
|
+
);
|
|
3538
|
+
default:
|
|
3539
|
+
throw new Error("Unknown saleType");
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
function isPrimaryMintActive(sale, blockTime) {
|
|
3543
|
+
if (sale.saleStart > blockTime)
|
|
3544
|
+
return false;
|
|
3545
|
+
if (!sale.saleEnd)
|
|
3546
|
+
return true;
|
|
3547
|
+
return sale.saleEnd > blockTime;
|
|
3548
|
+
}
|
|
3549
|
+
function isSecondaryMinter(result) {
|
|
3550
|
+
return result.saleType === "timed";
|
|
3551
|
+
}
|
|
3552
|
+
function isSecondaryMarketActive(sale) {
|
|
3553
|
+
const salesStrategy = sale.salesStrategy;
|
|
3554
|
+
if (isSecondaryMinter(salesStrategy)) {
|
|
3555
|
+
return salesStrategy.secondaryActivated;
|
|
3556
|
+
}
|
|
3557
|
+
return false;
|
|
3558
|
+
}
|
|
3559
|
+
function getTargetStrategy({
|
|
3560
|
+
preferredSaleType,
|
|
3561
|
+
blockTime,
|
|
3562
|
+
parsedStrategies
|
|
3448
3563
|
}) {
|
|
3449
|
-
const
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
const
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3564
|
+
const withPrimaryAndSecondaryMintActive = parsedStrategies.map(
|
|
3565
|
+
(strategy) => ({
|
|
3566
|
+
strategy,
|
|
3567
|
+
primaryMintActive: isPrimaryMintActive(strategy, blockTime),
|
|
3568
|
+
secondaryMarketActive: isSecondaryMarketActive(strategy)
|
|
3569
|
+
})
|
|
3570
|
+
);
|
|
3571
|
+
const stillValidSalesStrategies = withPrimaryAndSecondaryMintActive.filter(
|
|
3572
|
+
({ primaryMintActive, secondaryMarketActive }) => primaryMintActive || secondaryMarketActive
|
|
3573
|
+
);
|
|
3574
|
+
const saleStrategies = stillValidSalesStrategies.sort(
|
|
3575
|
+
(a, b) => (a.strategy.saleEnd ?? 0n) > (b.strategy.saleEnd ?? 0n) ? 1 : -1
|
|
3576
|
+
);
|
|
3577
|
+
let targetStrategy;
|
|
3578
|
+
if (!preferredSaleType) {
|
|
3579
|
+
return saleStrategies[0];
|
|
3580
|
+
} else {
|
|
3581
|
+
targetStrategy = saleStrategies.find(
|
|
3582
|
+
({ strategy: { salesStrategy } }) => salesStrategy.saleType === preferredSaleType
|
|
3583
|
+
);
|
|
3584
|
+
if (!targetStrategy) {
|
|
3585
|
+
targetStrategy = saleStrategies.find(
|
|
3586
|
+
({ strategy: { salesStrategy } }) => salesStrategy.saleType === "timed" || salesStrategy.saleType === "fixedPrice" || salesStrategy.saleType === "erc20"
|
|
3587
|
+
);
|
|
3588
|
+
if (!targetStrategy)
|
|
3589
|
+
throw new Error("Cannot find valid sale strategy");
|
|
3590
|
+
return targetStrategy;
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
return targetStrategy;
|
|
3471
3594
|
}
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3595
|
+
function findTargetStrategyWithPrimaryOrSecondarySaleActive({
|
|
3596
|
+
token,
|
|
3597
|
+
tokenId,
|
|
3598
|
+
preferredSaleType,
|
|
3599
|
+
defaultMintFee,
|
|
3600
|
+
blockTime
|
|
3478
3601
|
}) {
|
|
3479
|
-
const
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
const deletedPremint = {
|
|
3488
|
-
...premintConfig,
|
|
3489
|
-
version: premintConfig.version + 1,
|
|
3490
|
-
deleted: true
|
|
3491
|
-
};
|
|
3492
|
-
return makePremintReturn({
|
|
3493
|
-
premintConfig: deletedPremint,
|
|
3494
|
-
premintConfigVersion,
|
|
3495
|
-
collectionAddress,
|
|
3496
|
-
collection: collectionCreationConfig,
|
|
3497
|
-
publicClient,
|
|
3498
|
-
apiClient,
|
|
3499
|
-
chainId
|
|
3602
|
+
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
3603
|
+
const parsedStrategies = allStrategies.map(
|
|
3604
|
+
(strategy) => parseSalesConfig(strategy, defaultMintFee)
|
|
3605
|
+
);
|
|
3606
|
+
const targetStrategy = getTargetStrategy({
|
|
3607
|
+
preferredSaleType,
|
|
3608
|
+
blockTime,
|
|
3609
|
+
parsedStrategies
|
|
3500
3610
|
});
|
|
3611
|
+
return targetStrategy;
|
|
3501
3612
|
}
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
mintComment = "",
|
|
3508
|
-
mintReferral,
|
|
3509
|
-
mintRecipient,
|
|
3510
|
-
firstMinter,
|
|
3511
|
-
premintGetter,
|
|
3512
|
-
publicClient
|
|
3613
|
+
function parseAndFilterTokenQueryResult({
|
|
3614
|
+
token,
|
|
3615
|
+
tokenId,
|
|
3616
|
+
preferredSaleType,
|
|
3617
|
+
blockTime
|
|
3513
3618
|
}) {
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3619
|
+
const defaultMintFee = BigInt(token.contract.mintFeePerQuantity);
|
|
3620
|
+
const salesStrategyAndMintInfo = findTargetStrategyWithPrimaryOrSecondarySaleActive({
|
|
3621
|
+
token,
|
|
3622
|
+
tokenId,
|
|
3623
|
+
preferredSaleType,
|
|
3624
|
+
defaultMintFee,
|
|
3625
|
+
blockTime
|
|
3520
3626
|
});
|
|
3521
|
-
const
|
|
3522
|
-
|
|
3523
|
-
publicClient
|
|
3627
|
+
const tokenInfo = parseTokenInfo({
|
|
3628
|
+
token
|
|
3524
3629
|
});
|
|
3525
|
-
return
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
firstMinter,
|
|
3530
|
-
mintComment,
|
|
3531
|
-
mintRecipient,
|
|
3532
|
-
mintReferral
|
|
3630
|
+
return {
|
|
3631
|
+
salesConfigAndTokenInfo: {
|
|
3632
|
+
...tokenInfo,
|
|
3633
|
+
salesConfig: salesStrategyAndMintInfo?.strategy.salesStrategy
|
|
3533
3634
|
},
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
}
|
|
3538
|
-
var buildPremintMintCall = ({
|
|
3539
|
-
mintArguments: {
|
|
3540
|
-
minterAccount,
|
|
3541
|
-
mintComment = "",
|
|
3542
|
-
mintRecipient,
|
|
3543
|
-
mintReferral,
|
|
3544
|
-
firstMinter,
|
|
3545
|
-
quantityToMint
|
|
3546
|
-
},
|
|
3547
|
-
premint: { collection, collectionAddress, premint, signature },
|
|
3548
|
-
mintFee
|
|
3549
|
-
}) => {
|
|
3550
|
-
const mintArgumentsContract = {
|
|
3551
|
-
mintComment,
|
|
3552
|
-
mintRecipient: mintRecipientOrAccount({
|
|
3553
|
-
mintRecipient,
|
|
3554
|
-
minterAccount
|
|
3555
|
-
}),
|
|
3556
|
-
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
3557
|
-
mintReferral
|
|
3558
|
-
})
|
|
3635
|
+
primaryMintActive: salesStrategyAndMintInfo?.primaryMintActive ?? false,
|
|
3636
|
+
primaryMintEnd: salesStrategyAndMintInfo?.strategy.saleEnd,
|
|
3637
|
+
secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
|
|
3559
3638
|
};
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
if (premint.premintConfigVersion === PremintConfigVersion2.V3) {
|
|
3564
|
-
throw new Error("PremintV3 not supported in premint SDK");
|
|
3565
|
-
}
|
|
3566
|
-
const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
|
|
3567
|
-
return makeContractParameters({
|
|
3568
|
-
account: minterAccount,
|
|
3569
|
-
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
3570
|
-
functionName: "premint",
|
|
3571
|
-
value,
|
|
3572
|
-
address: getPremintExecutorAddress(),
|
|
3573
|
-
args: [
|
|
3574
|
-
collectionOrEmpty,
|
|
3575
|
-
collectionAddressToSubmit,
|
|
3576
|
-
encodePremintConfig(premint),
|
|
3577
|
-
signature,
|
|
3578
|
-
BigInt(quantityToMint),
|
|
3579
|
-
mintArgumentsContract,
|
|
3580
|
-
firstMinterToSubmit,
|
|
3581
|
-
zeroAddress2
|
|
3582
|
-
]
|
|
3583
|
-
});
|
|
3584
|
-
};
|
|
3585
|
-
function makeUrls({
|
|
3586
|
-
uid,
|
|
3587
|
-
address,
|
|
3588
|
-
tokenId,
|
|
3589
|
-
chainId,
|
|
3590
|
-
blockExplorerUrl
|
|
3639
|
+
}
|
|
3640
|
+
function parseTokenInfo({
|
|
3641
|
+
token
|
|
3591
3642
|
}) {
|
|
3592
|
-
if ((!uid || !tokenId) && !address) {
|
|
3593
|
-
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
3594
|
-
}
|
|
3595
|
-
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
3596
|
-
const network = getApiNetworkConfigForChain(chainId);
|
|
3597
3643
|
return {
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3644
|
+
contract: {
|
|
3645
|
+
address: token.contract.address,
|
|
3646
|
+
name: token.contract.name,
|
|
3647
|
+
URI: token.contract.contractURI
|
|
3648
|
+
},
|
|
3649
|
+
tokenURI: token.uri,
|
|
3650
|
+
tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
|
|
3651
|
+
mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
|
|
3652
|
+
creator: token.creator,
|
|
3653
|
+
totalMinted: BigInt(token.totalMinted),
|
|
3654
|
+
maxSupply: BigInt(token.maxSupply),
|
|
3655
|
+
contractVersion: token.contract.contractVersion
|
|
3601
3656
|
};
|
|
3602
3657
|
}
|
|
3603
3658
|
|
|
3604
|
-
// src/
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
PremintConfigVersion4[PremintConfigVersion4["V3"] = PremintConfigVersionOrig.V3] = "V3";
|
|
3612
|
-
return PremintConfigVersion4;
|
|
3613
|
-
})(PremintConfigVersion3 || {});
|
|
3614
|
-
|
|
3615
|
-
// src/premint/premint-api-client.ts
|
|
3616
|
-
var postSignature = async ({
|
|
3617
|
-
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
3618
|
-
...data
|
|
3619
|
-
}) => retries2(
|
|
3620
|
-
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
3621
|
-
);
|
|
3622
|
-
var getNextUID = async ({
|
|
3623
|
-
chainId,
|
|
3624
|
-
collection_address,
|
|
3625
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3626
|
-
}) => retries2(
|
|
3627
|
-
() => get2(
|
|
3628
|
-
`${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
|
|
3629
|
-
)
|
|
3630
|
-
);
|
|
3631
|
-
var getSignature = async ({
|
|
3632
|
-
collectionAddress,
|
|
3633
|
-
uid,
|
|
3634
|
-
chainId,
|
|
3635
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3636
|
-
}) => {
|
|
3637
|
-
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3638
|
-
const result = await retries2(
|
|
3639
|
-
() => get2(
|
|
3640
|
-
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
|
|
3641
|
-
)
|
|
3642
|
-
);
|
|
3643
|
-
return convertGetPremintApiResponse(result);
|
|
3644
|
-
};
|
|
3645
|
-
var getOfCollection = async ({
|
|
3646
|
-
collectionAddress,
|
|
3647
|
-
chainId,
|
|
3648
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3649
|
-
}) => {
|
|
3650
|
-
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3651
|
-
const result = await retries2(
|
|
3652
|
-
() => get2(
|
|
3653
|
-
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
|
|
3654
|
-
)
|
|
3655
|
-
);
|
|
3656
|
-
return convertGetPremintOfCollectionApiResponse(result);
|
|
3657
|
-
};
|
|
3658
|
-
var PremintAPIClient = class {
|
|
3659
|
-
constructor(chainId, httpClient2) {
|
|
3660
|
-
this.postSignature = ({
|
|
3661
|
-
signature,
|
|
3662
|
-
...rest
|
|
3663
|
-
}) => {
|
|
3664
|
-
const data = encodePostSignatureInput({
|
|
3665
|
-
...rest,
|
|
3666
|
-
chainId: this.chainId,
|
|
3667
|
-
signature
|
|
3668
|
-
});
|
|
3669
|
-
return postSignature({
|
|
3670
|
-
...data,
|
|
3671
|
-
httpClient: this.httpClient
|
|
3672
|
-
});
|
|
3673
|
-
};
|
|
3674
|
-
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
3675
|
-
collection_address: collectionAddress.toLowerCase(),
|
|
3676
|
-
chainId: this.chainId,
|
|
3677
|
-
httpClient: this.httpClient
|
|
3678
|
-
})).next_uid;
|
|
3679
|
-
this.get = async ({ collectionAddress, uid }) => {
|
|
3680
|
-
return getSignature({
|
|
3681
|
-
collectionAddress,
|
|
3682
|
-
uid,
|
|
3683
|
-
chainId: this.chainId,
|
|
3684
|
-
httpClient: this.httpClient
|
|
3685
|
-
});
|
|
3686
|
-
};
|
|
3687
|
-
this.getOfCollection = async ({
|
|
3688
|
-
collectionAddress
|
|
3659
|
+
// src/mint/subgraph-mint-getter.ts
|
|
3660
|
+
var SubgraphMintGetter = class extends SubgraphGetter {
|
|
3661
|
+
constructor(chainId, subgraphQuerier) {
|
|
3662
|
+
super(chainId, subgraphQuerier);
|
|
3663
|
+
this.getMintable = async ({
|
|
3664
|
+
tokenAddress,
|
|
3665
|
+
tokenId
|
|
3689
3666
|
}) => {
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3667
|
+
const token = await this.querySubgraphWithRetries(
|
|
3668
|
+
buildNftTokenSalesQuery({
|
|
3669
|
+
tokenId,
|
|
3670
|
+
tokenAddress
|
|
3671
|
+
})
|
|
3672
|
+
);
|
|
3673
|
+
if (!token) {
|
|
3674
|
+
throw new Error("Cannot find token");
|
|
3675
|
+
}
|
|
3676
|
+
return token;
|
|
3695
3677
|
};
|
|
3696
|
-
|
|
3697
|
-
|
|
3678
|
+
}
|
|
3679
|
+
async getContractMintable({
|
|
3680
|
+
tokenAddress,
|
|
3681
|
+
preferredSaleType,
|
|
3682
|
+
blockTime
|
|
3683
|
+
}) {
|
|
3684
|
+
const tokens = await this.querySubgraphWithRetries(
|
|
3685
|
+
buildContractTokensQuery({
|
|
3686
|
+
tokenAddress
|
|
3687
|
+
})
|
|
3688
|
+
);
|
|
3689
|
+
if (!tokens || tokens.length === 0)
|
|
3690
|
+
return [];
|
|
3691
|
+
return tokens.filter((x) => x.tokenId !== "0").map(
|
|
3692
|
+
(token) => parseAndFilterTokenQueryResult({
|
|
3693
|
+
token,
|
|
3694
|
+
tokenId: token.tokenId,
|
|
3695
|
+
preferredSaleType,
|
|
3696
|
+
blockTime
|
|
3697
|
+
})
|
|
3698
|
+
);
|
|
3699
|
+
}
|
|
3700
|
+
async getContractPremintTokenIds({
|
|
3701
|
+
tokenAddress
|
|
3702
|
+
}) {
|
|
3703
|
+
const premints = await this.querySubgraphWithRetries(
|
|
3704
|
+
buildPremintsOfContractQuery({
|
|
3705
|
+
tokenAddress
|
|
3706
|
+
})
|
|
3707
|
+
);
|
|
3708
|
+
return premints?.map((premint) => ({
|
|
3709
|
+
tokenId: BigInt(premint.tokenId),
|
|
3710
|
+
uid: +premint.uid
|
|
3711
|
+
})) || [];
|
|
3698
3712
|
}
|
|
3699
3713
|
};
|
|
3700
3714
|
|
|
@@ -3999,32 +4013,33 @@ function parseMintCosts({
|
|
|
3999
4013
|
}
|
|
4000
4014
|
|
|
4001
4015
|
// src/mint/mint-queries.ts
|
|
4002
|
-
async function
|
|
4003
|
-
params
|
|
4004
|
-
|
|
4005
|
-
premintGetter,
|
|
4006
|
-
publicClient,
|
|
4007
|
-
chainId
|
|
4008
|
-
}) {
|
|
4009
|
-
const { tokenContract } = params;
|
|
4016
|
+
async function getToken(params) {
|
|
4017
|
+
const { premintGetter, publicClient } = params;
|
|
4018
|
+
const chainId = publicClient.chain.id;
|
|
4010
4019
|
if (isOnChainMint(params)) {
|
|
4011
4020
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
4012
4021
|
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
4013
|
-
const
|
|
4022
|
+
const mintGetterOrDefault = params.mintGetter ?? new SubgraphMintGetter(chainId);
|
|
4023
|
+
const result = await mintGetterOrDefault.getMintable({
|
|
4024
|
+
tokenId,
|
|
4025
|
+
tokenAddress: params.tokenContract
|
|
4026
|
+
});
|
|
4027
|
+
const token = parseAndFilterTokenQueryResult({
|
|
4028
|
+
token: result,
|
|
4014
4029
|
tokenId,
|
|
4015
|
-
tokenAddress: tokenContract,
|
|
4016
4030
|
preferredSaleType: params.preferredSaleType,
|
|
4017
4031
|
blockTime
|
|
4018
4032
|
});
|
|
4019
|
-
return toMintableReturn(
|
|
4033
|
+
return toMintableReturn(token, chainId);
|
|
4020
4034
|
}
|
|
4021
|
-
const
|
|
4022
|
-
|
|
4035
|
+
const premintGetterOrDefault = premintGetter ?? new PremintAPIClient(chainId);
|
|
4036
|
+
const premint = await premintGetterOrDefault.get({
|
|
4037
|
+
collectionAddress: params.tokenContract,
|
|
4023
4038
|
uid: params.uid
|
|
4024
4039
|
});
|
|
4025
4040
|
const mintFee = await getPremintMintFee({
|
|
4026
4041
|
publicClient,
|
|
4027
|
-
tokenContract
|
|
4042
|
+
tokenContract: params.tokenContract
|
|
4028
4043
|
});
|
|
4029
4044
|
return toPremintMintReturn({ premint, mintFee });
|
|
4030
4045
|
}
|
|
@@ -4050,19 +4065,20 @@ async function getPremintsOfCollectionWithTokenIds({
|
|
|
4050
4065
|
premints: premintsWithTokenId
|
|
4051
4066
|
};
|
|
4052
4067
|
}
|
|
4053
|
-
async function
|
|
4054
|
-
params,
|
|
4068
|
+
async function getTokensOfContract({
|
|
4055
4069
|
mintGetter,
|
|
4056
4070
|
premintGetter,
|
|
4057
4071
|
publicClient,
|
|
4058
|
-
|
|
4072
|
+
...params
|
|
4059
4073
|
}) {
|
|
4060
|
-
const
|
|
4074
|
+
const chainId = publicClient.chain.id;
|
|
4075
|
+
const mintGetterOrDefault = mintGetter ?? new SubgraphMintGetter(chainId);
|
|
4076
|
+
const onchainMints = (await mintGetterOrDefault.getContractMintable({
|
|
4061
4077
|
tokenAddress: params.tokenContract
|
|
4062
4078
|
})).map((result) => toMintableReturn(result, chainId));
|
|
4063
4079
|
const offchainMints = await getPremintsOfContractMintable({
|
|
4064
|
-
mintGetter,
|
|
4065
|
-
premintGetter,
|
|
4080
|
+
mintGetter: mintGetterOrDefault,
|
|
4081
|
+
premintGetter: premintGetter ?? new PremintAPIClient(chainId),
|
|
4066
4082
|
publicClient,
|
|
4067
4083
|
params: {
|
|
4068
4084
|
tokenContract: params.tokenContract
|
|
@@ -4085,16 +4101,20 @@ async function getMintCosts({
|
|
|
4085
4101
|
if (isOnChainMint(params)) {
|
|
4086
4102
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
4087
4103
|
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
4088
|
-
const
|
|
4104
|
+
const result = await mintGetter.getMintable({
|
|
4105
|
+
tokenId,
|
|
4106
|
+
tokenAddress: collection
|
|
4107
|
+
});
|
|
4108
|
+
const token = parseAndFilterTokenQueryResult({
|
|
4109
|
+
token: result,
|
|
4089
4110
|
tokenId,
|
|
4090
|
-
tokenAddress: collection,
|
|
4091
4111
|
blockTime
|
|
4092
4112
|
});
|
|
4093
|
-
if (!salesConfigAndTokenInfo.salesConfig) {
|
|
4113
|
+
if (!token.salesConfigAndTokenInfo.salesConfig) {
|
|
4094
4114
|
throw new Error("No valid sales config found for token");
|
|
4095
4115
|
}
|
|
4096
4116
|
return parseMintCosts({
|
|
4097
|
-
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
4117
|
+
salesConfig: token.salesConfigAndTokenInfo.salesConfig,
|
|
4098
4118
|
quantityToMint: BigInt(quantityToMint),
|
|
4099
4119
|
allowListEntry
|
|
4100
4120
|
});
|
|
@@ -4144,7 +4164,7 @@ async function getPremintsOfContractMintable({
|
|
|
4144
4164
|
});
|
|
4145
4165
|
});
|
|
4146
4166
|
}
|
|
4147
|
-
function
|
|
4167
|
+
function isPrimaryMintActive2(premint) {
|
|
4148
4168
|
const currentTime = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
4149
4169
|
return premint.premintConfig.tokenConfig.mintStart < currentTime;
|
|
4150
4170
|
}
|
|
@@ -4237,7 +4257,7 @@ function toPremintMintReturn({
|
|
|
4237
4257
|
mintFee
|
|
4238
4258
|
}) {
|
|
4239
4259
|
const mintable = parsePremint({ premint, mintFee });
|
|
4240
|
-
const primaryMintActive =
|
|
4260
|
+
const primaryMintActive = isPrimaryMintActive2(premint.premint);
|
|
4241
4261
|
if (!primaryMintActive) {
|
|
4242
4262
|
return {
|
|
4243
4263
|
token: mintable,
|
|
@@ -4276,13 +4296,11 @@ var MintClient = class {
|
|
|
4276
4296
|
constructor({
|
|
4277
4297
|
publicClient,
|
|
4278
4298
|
premintGetter,
|
|
4279
|
-
mintGetter
|
|
4280
|
-
chainId
|
|
4299
|
+
mintGetter
|
|
4281
4300
|
}) {
|
|
4282
4301
|
this.publicClient = publicClient;
|
|
4283
4302
|
this.mintGetter = mintGetter;
|
|
4284
4303
|
this.premintGetter = premintGetter;
|
|
4285
|
-
this.chainId = chainId;
|
|
4286
4304
|
}
|
|
4287
4305
|
/**
|
|
4288
4306
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
@@ -4293,26 +4311,24 @@ var MintClient = class {
|
|
|
4293
4311
|
*/
|
|
4294
4312
|
async mint(parameters) {
|
|
4295
4313
|
return mint({
|
|
4296
|
-
parameters,
|
|
4314
|
+
...parameters,
|
|
4297
4315
|
publicClient: this.publicClient,
|
|
4298
4316
|
mintGetter: this.mintGetter,
|
|
4299
|
-
premintGetter: this.premintGetter
|
|
4300
|
-
chainId: this.chainId
|
|
4317
|
+
premintGetter: this.premintGetter
|
|
4301
4318
|
});
|
|
4302
4319
|
}
|
|
4303
4320
|
/**
|
|
4304
4321
|
* Gets an 1155, 721, or premint, and returns both information about it, and a function
|
|
4305
4322
|
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
4306
|
-
* @param parameters - Token to get {@link
|
|
4323
|
+
* @param parameters - Token to get {@link GetMintParametersArguments}
|
|
4307
4324
|
* @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
|
|
4308
4325
|
*/
|
|
4309
4326
|
async get(parameters) {
|
|
4310
|
-
return
|
|
4311
|
-
|
|
4327
|
+
return getToken({
|
|
4328
|
+
...parameters,
|
|
4312
4329
|
mintGetter: this.mintGetter,
|
|
4313
4330
|
premintGetter: this.premintGetter,
|
|
4314
|
-
publicClient: this.publicClient
|
|
4315
|
-
chainId: this.chainId
|
|
4331
|
+
publicClient: this.publicClient
|
|
4316
4332
|
});
|
|
4317
4333
|
}
|
|
4318
4334
|
/**
|
|
@@ -4322,17 +4338,16 @@ var MintClient = class {
|
|
|
4322
4338
|
* @Returns Array of tokens, each containing information about the token and a function to build a mint transaction.
|
|
4323
4339
|
*/
|
|
4324
4340
|
async getOfContract(params) {
|
|
4325
|
-
return
|
|
4326
|
-
params,
|
|
4341
|
+
return getTokensOfContract({
|
|
4342
|
+
...params,
|
|
4327
4343
|
mintGetter: this.mintGetter,
|
|
4328
4344
|
premintGetter: this.premintGetter,
|
|
4329
|
-
publicClient: this.publicClient
|
|
4330
|
-
chainId: this.chainId
|
|
4345
|
+
publicClient: this.publicClient
|
|
4331
4346
|
});
|
|
4332
4347
|
}
|
|
4333
4348
|
/**
|
|
4334
4349
|
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
4335
|
-
* @param parameters - Parameters for the mint {@link
|
|
4350
|
+
* @param parameters - Parameters for the mint {@link GetMintCostsParameterArguments}
|
|
4336
4351
|
* @returns Costs to mint the quantity of tokens specified
|
|
4337
4352
|
*/
|
|
4338
4353
|
async getMintCosts(parameters) {
|
|
@@ -4345,18 +4360,16 @@ var MintClient = class {
|
|
|
4345
4360
|
}
|
|
4346
4361
|
};
|
|
4347
4362
|
async function mint({
|
|
4348
|
-
parameters,
|
|
4349
4363
|
publicClient,
|
|
4350
4364
|
mintGetter,
|
|
4351
4365
|
premintGetter,
|
|
4352
|
-
|
|
4366
|
+
...parameters
|
|
4353
4367
|
}) {
|
|
4354
|
-
const { prepareMint, primaryMintActive } = await
|
|
4355
|
-
|
|
4368
|
+
const { prepareMint, primaryMintActive } = await getToken({
|
|
4369
|
+
...parameters,
|
|
4356
4370
|
mintGetter,
|
|
4357
4371
|
premintGetter,
|
|
4358
|
-
publicClient
|
|
4359
|
-
chainId
|
|
4372
|
+
publicClient
|
|
4360
4373
|
});
|
|
4361
4374
|
if (!primaryMintActive) {
|
|
4362
4375
|
throw new Error("Primary mint is not active");
|
|
@@ -4371,7 +4384,7 @@ async function mint({
|
|
|
4371
4384
|
});
|
|
4372
4385
|
}
|
|
4373
4386
|
|
|
4374
|
-
// src/create/
|
|
4387
|
+
// src/create/create-client.ts
|
|
4375
4388
|
import {
|
|
4376
4389
|
zoraCreator1155FactoryImplABI as zoraCreator1155FactoryImplABI2,
|
|
4377
4390
|
zoraCreator1155FactoryImplAddress as zoraCreator1155FactoryImplAddress2,
|
|
@@ -4397,9 +4410,9 @@ async function getDeterministicContractAddress({
|
|
|
4397
4410
|
publicClient,
|
|
4398
4411
|
account,
|
|
4399
4412
|
setupActions,
|
|
4400
|
-
contract
|
|
4401
|
-
chainId
|
|
4413
|
+
contract
|
|
4402
4414
|
}) {
|
|
4415
|
+
const chainId = publicClient.chain.id;
|
|
4403
4416
|
const contractAddress = await publicClient.readContract({
|
|
4404
4417
|
abi: zoraCreator1155FactoryImplABI,
|
|
4405
4418
|
address: zoraCreator1155FactoryImplAddress[chainId],
|
|
@@ -4929,27 +4942,85 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4929
4942
|
salesConfig: result
|
|
4930
4943
|
});
|
|
4931
4944
|
return {
|
|
4932
|
-
parameters: makePrepareMint1155TokenParams({
|
|
4933
|
-
salesConfigAndTokenInfo: {
|
|
4934
|
-
salesConfig: subgraphSalesConfig,
|
|
4935
|
-
contractVersion
|
|
4936
|
-
},
|
|
4937
|
-
...params,
|
|
4938
|
-
tokenContract: contractAddress,
|
|
4939
|
-
tokenId,
|
|
4940
|
-
chainId
|
|
4941
|
-
}),
|
|
4942
|
-
costs: parseMintCosts({
|
|
4943
|
-
allowListEntry: params.allowListEntry,
|
|
4944
|
-
quantityToMint: BigInt(params.quantityToMint),
|
|
4945
|
-
salesConfig: subgraphSalesConfig
|
|
4946
|
-
}),
|
|
4947
|
-
erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
|
|
4945
|
+
parameters: makePrepareMint1155TokenParams({
|
|
4946
|
+
salesConfigAndTokenInfo: {
|
|
4947
|
+
salesConfig: subgraphSalesConfig,
|
|
4948
|
+
contractVersion
|
|
4949
|
+
},
|
|
4950
|
+
...params,
|
|
4951
|
+
tokenContract: contractAddress,
|
|
4952
|
+
tokenId,
|
|
4953
|
+
chainId
|
|
4954
|
+
}),
|
|
4955
|
+
costs: parseMintCosts({
|
|
4956
|
+
allowListEntry: params.allowListEntry,
|
|
4957
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
4958
|
+
salesConfig: subgraphSalesConfig
|
|
4959
|
+
}),
|
|
4960
|
+
erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
|
|
4961
|
+
};
|
|
4962
|
+
};
|
|
4963
|
+
}
|
|
4964
|
+
|
|
4965
|
+
// src/create/subgraph-queries.ts
|
|
4966
|
+
function buildContractInfoQuery({
|
|
4967
|
+
contractAddress
|
|
4968
|
+
}) {
|
|
4969
|
+
return {
|
|
4970
|
+
query: `
|
|
4971
|
+
query ($contractAddress: Bytes!) {
|
|
4972
|
+
zoraCreateContract(id: $contractAddress) {
|
|
4973
|
+
contractVersion
|
|
4974
|
+
name
|
|
4975
|
+
mintFeePerQuantity
|
|
4976
|
+
tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
|
|
4977
|
+
tokenId
|
|
4978
|
+
}
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
`,
|
|
4982
|
+
variables: {
|
|
4983
|
+
contractAddress: contractAddress.toLowerCase()
|
|
4984
|
+
},
|
|
4985
|
+
parseResponseData: (responseData) => responseData.zoraCreateContract
|
|
4986
|
+
};
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
// src/create/contract-getter.ts
|
|
4990
|
+
var SubgraphContractGetter = class extends SubgraphGetter {
|
|
4991
|
+
constructor(chainId, subgraphQuerier) {
|
|
4992
|
+
super(chainId, subgraphQuerier);
|
|
4993
|
+
}
|
|
4994
|
+
async getContractInfo({
|
|
4995
|
+
contractAddress,
|
|
4996
|
+
retries: retries2 = 1
|
|
4997
|
+
}) {
|
|
4998
|
+
const tryFn = async () => {
|
|
4999
|
+
const responseData2 = await this.querySubgraphWithRetries(
|
|
5000
|
+
buildContractInfoQuery({ contractAddress })
|
|
5001
|
+
);
|
|
5002
|
+
if (!responseData2) {
|
|
5003
|
+
console.log("could not find contract");
|
|
5004
|
+
throw new Error("Cannot find contract");
|
|
5005
|
+
}
|
|
5006
|
+
return responseData2;
|
|
5007
|
+
};
|
|
5008
|
+
const responseData = await retriesGeneric({
|
|
5009
|
+
tryFn,
|
|
5010
|
+
maxTries: retries2,
|
|
5011
|
+
linearBackoffMS: 1e3
|
|
5012
|
+
});
|
|
5013
|
+
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
5014
|
+
return {
|
|
5015
|
+
name: responseData.name,
|
|
5016
|
+
contractVersion: responseData.contractVersion,
|
|
5017
|
+
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
5018
|
+
nextTokenId
|
|
4948
5019
|
};
|
|
4949
|
-
}
|
|
4950
|
-
}
|
|
5020
|
+
}
|
|
5021
|
+
};
|
|
4951
5022
|
|
|
4952
|
-
// src/create/
|
|
5023
|
+
// src/create/create-client.ts
|
|
4953
5024
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
4954
5025
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
4955
5026
|
for (const data of receipt.logs) {
|
|
@@ -5030,19 +5101,16 @@ function makeCreateTokenCall({
|
|
|
5030
5101
|
}
|
|
5031
5102
|
var Create1155Client = class {
|
|
5032
5103
|
constructor({
|
|
5033
|
-
chainId,
|
|
5034
5104
|
publicClient,
|
|
5035
5105
|
contractGetter
|
|
5036
5106
|
}) {
|
|
5037
|
-
this.chainId = chainId;
|
|
5038
5107
|
this.publicClient = publicClient;
|
|
5039
5108
|
this.contractGetter = contractGetter;
|
|
5040
5109
|
}
|
|
5041
5110
|
async createNew1155(props) {
|
|
5042
|
-
return
|
|
5111
|
+
return create1155({
|
|
5043
5112
|
...props,
|
|
5044
|
-
publicClient: this.publicClient
|
|
5045
|
-
chainId: this.chainId
|
|
5113
|
+
publicClient: this.publicClient
|
|
5046
5114
|
});
|
|
5047
5115
|
}
|
|
5048
5116
|
async createNew1155OnExistingContract({
|
|
@@ -5056,83 +5124,100 @@ var Create1155Client = class {
|
|
|
5056
5124
|
account,
|
|
5057
5125
|
token,
|
|
5058
5126
|
getAdditionalSetupActions,
|
|
5059
|
-
|
|
5060
|
-
chainId: this.
|
|
5061
|
-
contractGetter: this.contractGetter
|
|
5127
|
+
contractGetter: this.contractGetter,
|
|
5128
|
+
chainId: this.publicClient.chain.id
|
|
5062
5129
|
});
|
|
5063
5130
|
}
|
|
5064
5131
|
};
|
|
5065
|
-
async function
|
|
5132
|
+
async function create1155({
|
|
5066
5133
|
contract,
|
|
5067
5134
|
account,
|
|
5068
|
-
chainId,
|
|
5069
5135
|
token,
|
|
5070
5136
|
publicClient,
|
|
5071
5137
|
getAdditionalSetupActions
|
|
5072
5138
|
}) {
|
|
5073
5139
|
const nextTokenId = 1n;
|
|
5140
|
+
const chainId = publicClient.chain.id;
|
|
5074
5141
|
const contractVersion = new1155ContractVersion(chainId);
|
|
5075
|
-
const {
|
|
5076
|
-
minter,
|
|
5077
|
-
newToken,
|
|
5078
|
-
setupActions: tokenSetupActions
|
|
5079
|
-
} = prepareSetupActions({
|
|
5080
|
-
chainId,
|
|
5081
|
-
account,
|
|
5082
|
-
contractVersion,
|
|
5083
|
-
nextTokenId,
|
|
5084
|
-
token,
|
|
5085
|
-
getAdditionalSetupActions,
|
|
5086
|
-
contractName: contract.name
|
|
5087
|
-
});
|
|
5088
|
-
const request = makeCreateContractAndTokenCall({
|
|
5142
|
+
const result = prepareNew1155ContractAndToken({
|
|
5089
5143
|
contract,
|
|
5090
5144
|
account,
|
|
5091
5145
|
chainId,
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5146
|
+
token,
|
|
5147
|
+
getAdditionalSetupActions,
|
|
5148
|
+
nextTokenId,
|
|
5149
|
+
contractVersion
|
|
5095
5150
|
});
|
|
5096
5151
|
const contractAddress = await getDeterministicContractAddress({
|
|
5097
5152
|
account: typeof account === "string" ? account : account.address,
|
|
5098
5153
|
publicClient,
|
|
5099
|
-
setupActions:
|
|
5100
|
-
chainId,
|
|
5154
|
+
setupActions: result.setupActions,
|
|
5101
5155
|
contract
|
|
5102
5156
|
});
|
|
5103
5157
|
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
5104
5158
|
contractAddress,
|
|
5105
5159
|
contractVersion,
|
|
5106
|
-
minter,
|
|
5107
|
-
result: newToken.salesConfig,
|
|
5160
|
+
minter: result.minter,
|
|
5161
|
+
result: result.newToken.salesConfig,
|
|
5108
5162
|
tokenId: nextTokenId,
|
|
5163
|
+
chainId,
|
|
5109
5164
|
// to get the contract wide mint fee, we get what it would be for a new contract
|
|
5110
5165
|
getContractMintFee: async () => getNewContractMintFee({
|
|
5111
5166
|
publicClient,
|
|
5112
5167
|
chainId
|
|
5113
|
-
})
|
|
5114
|
-
chainId
|
|
5168
|
+
})
|
|
5115
5169
|
});
|
|
5116
5170
|
return {
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
newTokenId: nextTokenId,
|
|
5120
|
-
newToken,
|
|
5171
|
+
...result,
|
|
5172
|
+
prepareMint,
|
|
5121
5173
|
contractAddress,
|
|
5122
5174
|
contractVersion,
|
|
5123
|
-
|
|
5124
|
-
prepareMint
|
|
5175
|
+
newTokenId: nextTokenId
|
|
5125
5176
|
};
|
|
5126
5177
|
}
|
|
5127
|
-
|
|
5178
|
+
function prepareNew1155ContractAndToken({
|
|
5179
|
+
account,
|
|
5180
|
+
chainId,
|
|
5181
|
+
token,
|
|
5182
|
+
getAdditionalSetupActions,
|
|
5183
|
+
nextTokenId,
|
|
5184
|
+
contractVersion,
|
|
5185
|
+
contract
|
|
5186
|
+
}) {
|
|
5187
|
+
const { minter, newToken, setupActions } = prepareSetupActions({
|
|
5188
|
+
chainId,
|
|
5189
|
+
account,
|
|
5190
|
+
contractVersion,
|
|
5191
|
+
nextTokenId,
|
|
5192
|
+
token,
|
|
5193
|
+
getAdditionalSetupActions,
|
|
5194
|
+
contractName: contract.name
|
|
5195
|
+
});
|
|
5196
|
+
const request = makeCreateContractAndTokenCall({
|
|
5197
|
+
contract,
|
|
5198
|
+
account,
|
|
5199
|
+
chainId,
|
|
5200
|
+
tokenSetupActions: setupActions,
|
|
5201
|
+
fundsRecipient: token.payoutRecipient,
|
|
5202
|
+
royaltyBPS: token.royaltyBPS
|
|
5203
|
+
});
|
|
5204
|
+
return {
|
|
5205
|
+
parameters: request,
|
|
5206
|
+
setupActions,
|
|
5207
|
+
newToken,
|
|
5208
|
+
minter
|
|
5209
|
+
};
|
|
5210
|
+
}
|
|
5211
|
+
function prepareNew1155Token({
|
|
5128
5212
|
contractAddress,
|
|
5129
5213
|
account,
|
|
5130
5214
|
getAdditionalSetupActions,
|
|
5131
5215
|
token,
|
|
5132
5216
|
chainId,
|
|
5133
|
-
|
|
5217
|
+
nextTokenId,
|
|
5218
|
+
contractVersion,
|
|
5219
|
+
contractName
|
|
5134
5220
|
}) {
|
|
5135
|
-
const { nextTokenId, contractVersion, mintFee, name } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
|
|
5136
5221
|
const {
|
|
5137
5222
|
minter,
|
|
5138
5223
|
newToken,
|
|
@@ -5144,30 +5229,57 @@ async function createNew1155Token({
|
|
|
5144
5229
|
nextTokenId,
|
|
5145
5230
|
token,
|
|
5146
5231
|
getAdditionalSetupActions,
|
|
5147
|
-
contractName
|
|
5232
|
+
contractName
|
|
5148
5233
|
});
|
|
5149
5234
|
const request = makeCreateTokenCall({
|
|
5150
5235
|
contractAddress,
|
|
5151
5236
|
account,
|
|
5152
5237
|
tokenSetupActions
|
|
5153
5238
|
});
|
|
5239
|
+
return {
|
|
5240
|
+
parameters: request,
|
|
5241
|
+
setupActions: tokenSetupActions,
|
|
5242
|
+
newToken,
|
|
5243
|
+
minter
|
|
5244
|
+
};
|
|
5245
|
+
}
|
|
5246
|
+
async function createNew1155Token({
|
|
5247
|
+
contractAddress,
|
|
5248
|
+
account,
|
|
5249
|
+
getAdditionalSetupActions,
|
|
5250
|
+
token,
|
|
5251
|
+
chainId,
|
|
5252
|
+
contractGetter
|
|
5253
|
+
}) {
|
|
5254
|
+
const contractGetterOrDefault = contractGetter ?? new SubgraphContractGetter(chainId);
|
|
5255
|
+
const { nextTokenId, contractVersion, mintFee, name } = await contractGetterOrDefault.getContractInfo({
|
|
5256
|
+
contractAddress,
|
|
5257
|
+
retries: 5
|
|
5258
|
+
});
|
|
5259
|
+
const preparedToken = prepareNew1155Token({
|
|
5260
|
+
contractAddress,
|
|
5261
|
+
account,
|
|
5262
|
+
getAdditionalSetupActions,
|
|
5263
|
+
token,
|
|
5264
|
+
chainId,
|
|
5265
|
+
nextTokenId,
|
|
5266
|
+
contractVersion,
|
|
5267
|
+
contractName: name
|
|
5268
|
+
});
|
|
5154
5269
|
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
5155
5270
|
contractAddress,
|
|
5156
5271
|
contractVersion,
|
|
5157
|
-
minter,
|
|
5158
|
-
result: newToken.salesConfig,
|
|
5272
|
+
minter: preparedToken.minter,
|
|
5273
|
+
result: preparedToken.newToken.salesConfig,
|
|
5159
5274
|
tokenId: nextTokenId,
|
|
5160
5275
|
getContractMintFee: async () => mintFee,
|
|
5161
5276
|
chainId
|
|
5162
5277
|
});
|
|
5163
5278
|
return {
|
|
5164
|
-
|
|
5165
|
-
|
|
5279
|
+
...preparedToken,
|
|
5280
|
+
prepareMint,
|
|
5166
5281
|
newTokenId: nextTokenId,
|
|
5167
|
-
|
|
5168
|
-
contractVersion,
|
|
5169
|
-
minter,
|
|
5170
|
-
prepareMint
|
|
5282
|
+
contractVersion
|
|
5171
5283
|
};
|
|
5172
5284
|
}
|
|
5173
5285
|
function prepareSetupActions({
|
|
@@ -5444,119 +5556,61 @@ var makePermitToCollectPremintOrNonPremint = ({
|
|
|
5444
5556
|
deadline,
|
|
5445
5557
|
tokenIds,
|
|
5446
5558
|
// this quantity of MINTs will be used to collect premint
|
|
5447
|
-
// and will be burned. This same quantity is the quantity of
|
|
5448
|
-
// premint to collect.
|
|
5449
|
-
quantities,
|
|
5450
|
-
nonce,
|
|
5451
|
-
premint,
|
|
5452
|
-
collect
|
|
5453
|
-
}) => {
|
|
5454
|
-
let safeTransferData;
|
|
5455
|
-
if (premint) {
|
|
5456
|
-
safeTransferData = encodePremintOnManager(premint);
|
|
5457
|
-
} else if (collect) {
|
|
5458
|
-
safeTransferData = encodeCollectOnManager(collect);
|
|
5459
|
-
} else {
|
|
5460
|
-
throw new Error("Invalid operation");
|
|
5461
|
-
}
|
|
5462
|
-
return makePermitTransferBatchAndTypeData({
|
|
5463
|
-
tokenIds,
|
|
5464
|
-
quantities,
|
|
5465
|
-
chainId,
|
|
5466
|
-
mintsOwner,
|
|
5467
|
-
nonce,
|
|
5468
|
-
deadline,
|
|
5469
|
-
safeTransferData,
|
|
5470
|
-
to: zoraMintsManagerImplConfig.address[chainId]
|
|
5471
|
-
});
|
|
5472
|
-
};
|
|
5473
|
-
function collectPremintV2WithMintsParams({
|
|
5474
|
-
tokenIds,
|
|
5475
|
-
quantities,
|
|
5476
|
-
paidMintPricePerToken,
|
|
5477
|
-
account,
|
|
5478
|
-
chainId,
|
|
5479
|
-
...rest
|
|
5480
|
-
}) {
|
|
5481
|
-
const call = encodePremintOnManager({
|
|
5482
|
-
...rest
|
|
5483
|
-
});
|
|
5484
|
-
return makeContractParameters({
|
|
5485
|
-
abi: zoraMints1155Config.abi,
|
|
5486
|
-
address: zoraMints1155Config.address[chainId],
|
|
5487
|
-
functionName: "transferBatchToManagerAndCall",
|
|
5488
|
-
args: [tokenIds, quantities, call],
|
|
5489
|
-
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
5490
|
-
account
|
|
5491
|
-
});
|
|
5492
|
-
}
|
|
5493
|
-
function decodeCallFailedError(error) {
|
|
5494
|
-
if (error.data?.errorName !== "CallFailed")
|
|
5495
|
-
throw new Error("Not a CallFailed error");
|
|
5496
|
-
const internalErrorData = error.data?.args?.[0];
|
|
5497
|
-
return decodeErrorResult({
|
|
5498
|
-
abi: zoraMintsManagerImplABI,
|
|
5499
|
-
data: internalErrorData
|
|
5500
|
-
});
|
|
5501
|
-
}
|
|
5502
|
-
|
|
5503
|
-
// src/create/subgraph-queries.ts
|
|
5504
|
-
function buildContractInfoQuery({
|
|
5505
|
-
contractAddress
|
|
5506
|
-
}) {
|
|
5507
|
-
return {
|
|
5508
|
-
query: `
|
|
5509
|
-
query ($contractAddress: Bytes!) {
|
|
5510
|
-
zoraCreateContract(id: $contractAddress) {
|
|
5511
|
-
contractVersion
|
|
5512
|
-
name
|
|
5513
|
-
mintFeePerQuantity
|
|
5514
|
-
tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
|
|
5515
|
-
tokenId
|
|
5516
|
-
}
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
`,
|
|
5520
|
-
variables: {
|
|
5521
|
-
contractAddress: contractAddress.toLowerCase()
|
|
5522
|
-
},
|
|
5523
|
-
parseResponseData: (responseData) => responseData.zoraCreateContract
|
|
5524
|
-
};
|
|
5525
|
-
}
|
|
5526
|
-
|
|
5527
|
-
// src/create/contract-getter.ts
|
|
5528
|
-
var SubgraphContractGetter = class extends SubgraphGetter {
|
|
5529
|
-
constructor(chainId, subgraphQuerier) {
|
|
5530
|
-
super(chainId, subgraphQuerier);
|
|
5531
|
-
}
|
|
5532
|
-
async getContractInfo({
|
|
5533
|
-
contractAddress,
|
|
5534
|
-
retries: retries2 = 1
|
|
5535
|
-
}) {
|
|
5536
|
-
const tryFn = async () => {
|
|
5537
|
-
const responseData2 = await this.querySubgraphWithRetries(
|
|
5538
|
-
buildContractInfoQuery({ contractAddress })
|
|
5539
|
-
);
|
|
5540
|
-
if (!responseData2) {
|
|
5541
|
-
console.log("could not find contract");
|
|
5542
|
-
throw new Error("Cannot find contract");
|
|
5543
|
-
}
|
|
5544
|
-
return responseData2;
|
|
5545
|
-
};
|
|
5546
|
-
const responseData = await retriesGeneric({
|
|
5547
|
-
tryFn,
|
|
5548
|
-
maxTries: retries2,
|
|
5549
|
-
linearBackoffMS: 1e3
|
|
5550
|
-
});
|
|
5551
|
-
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
5552
|
-
return {
|
|
5553
|
-
name: responseData.name,
|
|
5554
|
-
contractVersion: responseData.contractVersion,
|
|
5555
|
-
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
5556
|
-
nextTokenId
|
|
5557
|
-
};
|
|
5559
|
+
// and will be burned. This same quantity is the quantity of
|
|
5560
|
+
// premint to collect.
|
|
5561
|
+
quantities,
|
|
5562
|
+
nonce,
|
|
5563
|
+
premint,
|
|
5564
|
+
collect
|
|
5565
|
+
}) => {
|
|
5566
|
+
let safeTransferData;
|
|
5567
|
+
if (premint) {
|
|
5568
|
+
safeTransferData = encodePremintOnManager(premint);
|
|
5569
|
+
} else if (collect) {
|
|
5570
|
+
safeTransferData = encodeCollectOnManager(collect);
|
|
5571
|
+
} else {
|
|
5572
|
+
throw new Error("Invalid operation");
|
|
5558
5573
|
}
|
|
5574
|
+
return makePermitTransferBatchAndTypeData({
|
|
5575
|
+
tokenIds,
|
|
5576
|
+
quantities,
|
|
5577
|
+
chainId,
|
|
5578
|
+
mintsOwner,
|
|
5579
|
+
nonce,
|
|
5580
|
+
deadline,
|
|
5581
|
+
safeTransferData,
|
|
5582
|
+
to: zoraMintsManagerImplConfig.address[chainId]
|
|
5583
|
+
});
|
|
5559
5584
|
};
|
|
5585
|
+
function collectPremintV2WithMintsParams({
|
|
5586
|
+
tokenIds,
|
|
5587
|
+
quantities,
|
|
5588
|
+
paidMintPricePerToken,
|
|
5589
|
+
account,
|
|
5590
|
+
chainId,
|
|
5591
|
+
...rest
|
|
5592
|
+
}) {
|
|
5593
|
+
const call = encodePremintOnManager({
|
|
5594
|
+
...rest
|
|
5595
|
+
});
|
|
5596
|
+
return makeContractParameters({
|
|
5597
|
+
abi: zoraMints1155Config.abi,
|
|
5598
|
+
address: zoraMints1155Config.address[chainId],
|
|
5599
|
+
functionName: "transferBatchToManagerAndCall",
|
|
5600
|
+
args: [tokenIds, quantities, call],
|
|
5601
|
+
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
5602
|
+
account
|
|
5603
|
+
});
|
|
5604
|
+
}
|
|
5605
|
+
function decodeCallFailedError(error) {
|
|
5606
|
+
if (error.data?.errorName !== "CallFailed")
|
|
5607
|
+
throw new Error("Not a CallFailed error");
|
|
5608
|
+
const internalErrorData = error.data?.args?.[0];
|
|
5609
|
+
return decodeErrorResult({
|
|
5610
|
+
abi: zoraMintsManagerImplABI,
|
|
5611
|
+
data: internalErrorData
|
|
5612
|
+
});
|
|
5613
|
+
}
|
|
5560
5614
|
|
|
5561
5615
|
// src/rewards/rewards-queries.ts
|
|
5562
5616
|
import {
|
|
@@ -5580,6 +5634,56 @@ var multicall3Abi = [
|
|
|
5580
5634
|
];
|
|
5581
5635
|
var multicall3Address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
5582
5636
|
|
|
5637
|
+
// src/rewards/subgraph-queries.ts
|
|
5638
|
+
function buildCreatorERC20zs({
|
|
5639
|
+
address
|
|
5640
|
+
}) {
|
|
5641
|
+
return {
|
|
5642
|
+
query: `
|
|
5643
|
+
query ($address: Bytes!) {
|
|
5644
|
+
zoraCreateTokens(
|
|
5645
|
+
where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
|
|
5646
|
+
) {
|
|
5647
|
+
royalties {
|
|
5648
|
+
user
|
|
5649
|
+
}
|
|
5650
|
+
salesStrategies {
|
|
5651
|
+
zoraTimedMinter {
|
|
5652
|
+
erc20Z {
|
|
5653
|
+
id
|
|
5654
|
+
}
|
|
5655
|
+
}
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
}
|
|
5659
|
+
`,
|
|
5660
|
+
variables: { address },
|
|
5661
|
+
parseResponseData: (responseData) => {
|
|
5662
|
+
return responseData?.zoraCreateTokens;
|
|
5663
|
+
}
|
|
5664
|
+
};
|
|
5665
|
+
}
|
|
5666
|
+
|
|
5667
|
+
// src/rewards/subgraph-rewards-getter.ts
|
|
5668
|
+
var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
5669
|
+
constructor(chainId, subgraphQuerier) {
|
|
5670
|
+
super(chainId, subgraphQuerier);
|
|
5671
|
+
}
|
|
5672
|
+
async getErc20ZzForCreator({ address }) {
|
|
5673
|
+
const queryResults = await this.querySubgraphWithRetries(
|
|
5674
|
+
buildCreatorERC20zs({ address })
|
|
5675
|
+
);
|
|
5676
|
+
const results = (queryResults?.map((result) => {
|
|
5677
|
+
const timedMinter = result.salesStrategies[0].zoraTimedMinter;
|
|
5678
|
+
if (!timedMinter) {
|
|
5679
|
+
return null;
|
|
5680
|
+
}
|
|
5681
|
+
return timedMinter.erc20Z.id;
|
|
5682
|
+
}) || []).filter((id) => !!id);
|
|
5683
|
+
return results;
|
|
5684
|
+
}
|
|
5685
|
+
};
|
|
5686
|
+
|
|
5583
5687
|
// src/rewards/rewards-queries.ts
|
|
5584
5688
|
function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
|
|
5585
5689
|
let ethBalance = 0n;
|
|
@@ -5606,21 +5710,47 @@ function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
|
|
|
5606
5710
|
erc20: unclaimedFeesAggregate
|
|
5607
5711
|
};
|
|
5608
5712
|
}
|
|
5609
|
-
var
|
|
5713
|
+
var getErc20zsWithPositions = async ({
|
|
5714
|
+
address,
|
|
5715
|
+
publicClient,
|
|
5716
|
+
rewardsGetter
|
|
5717
|
+
}) => {
|
|
5718
|
+
const chainId = publicClient.chain.id;
|
|
5719
|
+
const rewardsGetterOrDefault = rewardsGetter ?? new SubgraphRewardsGetter(chainId);
|
|
5720
|
+
const erc20zsForCreator = await rewardsGetterOrDefault.getErc20ZzForCreator({
|
|
5721
|
+
address
|
|
5722
|
+
});
|
|
5723
|
+
const royaltiesAddress = erc20ZRoyaltiesAddress[chainId];
|
|
5724
|
+
const positionsByErc20z = await publicClient.multicall({
|
|
5725
|
+
contracts: erc20zsForCreator.map((erc20z) => ({
|
|
5726
|
+
address: royaltiesAddress,
|
|
5727
|
+
abi: erc20ZRoyaltiesABI,
|
|
5728
|
+
functionName: "positionsByErc20z",
|
|
5729
|
+
args: [erc20z]
|
|
5730
|
+
})),
|
|
5731
|
+
multicallAddress: multicall3Address,
|
|
5732
|
+
allowFailure: false
|
|
5733
|
+
});
|
|
5734
|
+
const erc20zsWithPositions = erc20zsForCreator.filter(
|
|
5735
|
+
(_, i) => positionsByErc20z[i] !== 0n
|
|
5736
|
+
);
|
|
5737
|
+
return erc20zsWithPositions;
|
|
5738
|
+
};
|
|
5739
|
+
var getRewardsBalances = async ({
|
|
5610
5740
|
account,
|
|
5611
5741
|
// The account to check rewards for (Address or Account object)
|
|
5612
5742
|
publicClient,
|
|
5613
5743
|
// The public client for making blockchain queries
|
|
5614
|
-
chainId,
|
|
5615
|
-
// The ID of the blockchain network
|
|
5616
5744
|
rewardsGetter
|
|
5617
5745
|
// Interface for getting ERC20Z tokens for a creator
|
|
5618
5746
|
}) => {
|
|
5747
|
+
const chainId = publicClient.chain.id;
|
|
5619
5748
|
const address = typeof account === "string" ? account : account.address;
|
|
5620
|
-
const
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5749
|
+
const erc20zsWithPositions = await getErc20zsWithPositions({
|
|
5750
|
+
address,
|
|
5751
|
+
publicClient,
|
|
5752
|
+
rewardsGetter
|
|
5753
|
+
});
|
|
5624
5754
|
const result = await publicClient.multicall({
|
|
5625
5755
|
contracts: [
|
|
5626
5756
|
{
|
|
@@ -5633,7 +5763,7 @@ var getRewardsBalance = async ({
|
|
|
5633
5763
|
address: erc20ZRoyaltiesAddress[chainId],
|
|
5634
5764
|
abi: erc20ZRoyaltiesABI,
|
|
5635
5765
|
functionName: "getUnclaimedFeesBatch",
|
|
5636
|
-
args: [
|
|
5766
|
+
args: [erc20zsWithPositions]
|
|
5637
5767
|
}
|
|
5638
5768
|
],
|
|
5639
5769
|
multicallAddress: multicall3Address,
|
|
@@ -5664,12 +5794,14 @@ var withdrawProtocolRewards = ({
|
|
|
5664
5794
|
var makeClaimSecondaryRoyaltiesCalls = async ({
|
|
5665
5795
|
claimFor,
|
|
5666
5796
|
chainId,
|
|
5667
|
-
rewardsGetter
|
|
5797
|
+
rewardsGetter,
|
|
5798
|
+
publicClient
|
|
5668
5799
|
}) => {
|
|
5669
|
-
const
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5800
|
+
const erc20z = await getErc20zsWithPositions({
|
|
5801
|
+
address: claimFor,
|
|
5802
|
+
publicClient,
|
|
5803
|
+
rewardsGetter
|
|
5804
|
+
});
|
|
5673
5805
|
const royaltiesAddress = erc20ZRoyaltiesAddress[chainId];
|
|
5674
5806
|
if (erc20z.length === 0) {
|
|
5675
5807
|
return [];
|
|
@@ -5700,37 +5832,57 @@ var createMulticallParameters = (calls, account) => makeContractParameters({
|
|
|
5700
5832
|
args: [calls],
|
|
5701
5833
|
account
|
|
5702
5834
|
});
|
|
5703
|
-
var
|
|
5704
|
-
account,
|
|
5705
|
-
withdrawFor,
|
|
5706
|
-
claimSecondaryRoyalties = true,
|
|
5835
|
+
var handleProtocolRewardsOnly = ({
|
|
5707
5836
|
chainId,
|
|
5708
|
-
|
|
5837
|
+
withdrawFor,
|
|
5838
|
+
account
|
|
5839
|
+
}) => ({
|
|
5840
|
+
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
5841
|
+
account
|
|
5842
|
+
});
|
|
5843
|
+
var handleAllRewards = async ({
|
|
5844
|
+
withdrawFor,
|
|
5845
|
+
account,
|
|
5846
|
+
rewardsGetter,
|
|
5847
|
+
publicClient
|
|
5709
5848
|
}) => {
|
|
5710
|
-
|
|
5711
|
-
return {
|
|
5712
|
-
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
5713
|
-
account
|
|
5714
|
-
};
|
|
5715
|
-
}
|
|
5849
|
+
const chainId = publicClient.chain.id;
|
|
5716
5850
|
const protocolRewardsCall = createProtocolRewardsCall(chainId, withdrawFor);
|
|
5717
5851
|
const secondaryRoyaltiesCalls = await makeClaimSecondaryRoyaltiesCalls({
|
|
5718
5852
|
chainId,
|
|
5719
5853
|
claimFor: withdrawFor,
|
|
5720
|
-
rewardsGetter
|
|
5854
|
+
rewardsGetter,
|
|
5855
|
+
publicClient
|
|
5721
5856
|
});
|
|
5722
5857
|
const allCalls = [protocolRewardsCall, ...secondaryRoyaltiesCalls];
|
|
5723
5858
|
return createMulticallParameters(allCalls, account);
|
|
5724
5859
|
};
|
|
5860
|
+
var withdrawRewards = async ({
|
|
5861
|
+
account,
|
|
5862
|
+
withdrawFor,
|
|
5863
|
+
claimSecondaryRoyalties = true,
|
|
5864
|
+
rewardsGetter,
|
|
5865
|
+
publicClient
|
|
5866
|
+
}) => {
|
|
5867
|
+
const parameters = claimSecondaryRoyalties ? await handleAllRewards({
|
|
5868
|
+
withdrawFor,
|
|
5869
|
+
account,
|
|
5870
|
+
rewardsGetter,
|
|
5871
|
+
publicClient
|
|
5872
|
+
}) : await handleProtocolRewardsOnly({
|
|
5873
|
+
chainId: publicClient.chain.id,
|
|
5874
|
+
withdrawFor,
|
|
5875
|
+
account
|
|
5876
|
+
});
|
|
5877
|
+
return { parameters };
|
|
5878
|
+
};
|
|
5725
5879
|
|
|
5726
5880
|
// src/rewards/rewards-client.ts
|
|
5727
5881
|
var RewardsClient = class {
|
|
5728
5882
|
constructor({
|
|
5729
|
-
chainId,
|
|
5730
5883
|
publicClient,
|
|
5731
5884
|
rewardsGetter
|
|
5732
5885
|
}) {
|
|
5733
|
-
this.chainId = chainId;
|
|
5734
5886
|
this.publicClient = publicClient;
|
|
5735
5887
|
this.rewardsGetter = rewardsGetter;
|
|
5736
5888
|
}
|
|
@@ -5740,83 +5892,24 @@ var RewardsClient = class {
|
|
|
5740
5892
|
withdrawFor,
|
|
5741
5893
|
claimSecondaryRoyalties
|
|
5742
5894
|
}) {
|
|
5743
|
-
return {
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
})
|
|
5751
|
-
};
|
|
5895
|
+
return await withdrawRewards({
|
|
5896
|
+
rewardsGetter: this.rewardsGetter,
|
|
5897
|
+
withdrawFor,
|
|
5898
|
+
claimSecondaryRoyalties,
|
|
5899
|
+
account,
|
|
5900
|
+
publicClient: this.publicClient
|
|
5901
|
+
});
|
|
5752
5902
|
}
|
|
5753
5903
|
/** Retrieves the rewards balances for a given account */
|
|
5754
5904
|
async getRewardsBalances(params) {
|
|
5755
|
-
return
|
|
5905
|
+
return getRewardsBalances({
|
|
5756
5906
|
account: params.account,
|
|
5757
|
-
chainId: this.chainId,
|
|
5758
5907
|
publicClient: this.publicClient,
|
|
5759
5908
|
rewardsGetter: this.rewardsGetter
|
|
5760
5909
|
});
|
|
5761
5910
|
}
|
|
5762
5911
|
};
|
|
5763
5912
|
|
|
5764
|
-
// src/rewards/subgraph-queries.ts
|
|
5765
|
-
function buildCreatorERC20zs({
|
|
5766
|
-
address
|
|
5767
|
-
}) {
|
|
5768
|
-
return {
|
|
5769
|
-
query: `
|
|
5770
|
-
query ($address: Bytes!) {
|
|
5771
|
-
zoraCreateTokens(
|
|
5772
|
-
where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
|
|
5773
|
-
) {
|
|
5774
|
-
royalties {
|
|
5775
|
-
user
|
|
5776
|
-
}
|
|
5777
|
-
salesStrategies {
|
|
5778
|
-
zoraTimedMinter {
|
|
5779
|
-
secondaryActivated
|
|
5780
|
-
erc20Z {
|
|
5781
|
-
id
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
}
|
|
5785
|
-
}
|
|
5786
|
-
}
|
|
5787
|
-
`,
|
|
5788
|
-
variables: { address },
|
|
5789
|
-
parseResponseData: (responseData) => {
|
|
5790
|
-
return responseData?.zoraCreateTokens;
|
|
5791
|
-
}
|
|
5792
|
-
};
|
|
5793
|
-
}
|
|
5794
|
-
|
|
5795
|
-
// src/rewards/subgraph-rewards-getter.ts
|
|
5796
|
-
var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
5797
|
-
constructor(chainId, subgraphQuerier) {
|
|
5798
|
-
super(chainId, subgraphQuerier);
|
|
5799
|
-
}
|
|
5800
|
-
async getErc20ZzForCreator({ address }) {
|
|
5801
|
-
const queryResults = await this.querySubgraphWithRetries(
|
|
5802
|
-
buildCreatorERC20zs({ address })
|
|
5803
|
-
);
|
|
5804
|
-
const results = (queryResults?.map((result) => {
|
|
5805
|
-
const timedMinter = result.salesStrategies[0].zoraTimedMinter;
|
|
5806
|
-
if (!timedMinter) {
|
|
5807
|
-
return null;
|
|
5808
|
-
}
|
|
5809
|
-
return {
|
|
5810
|
-
secondaryActivated: timedMinter.secondaryActivated,
|
|
5811
|
-
erc20z: timedMinter.erc20Z.id
|
|
5812
|
-
};
|
|
5813
|
-
}) || []).filter(
|
|
5814
|
-
(idAndActivated) => !!idAndActivated
|
|
5815
|
-
);
|
|
5816
|
-
return results;
|
|
5817
|
-
}
|
|
5818
|
-
};
|
|
5819
|
-
|
|
5820
5913
|
// src/secondary/secondary-client.ts
|
|
5821
5914
|
import { encodeAbiParameters as encodeAbiParameters2 } from "viem";
|
|
5822
5915
|
import {
|
|
@@ -6005,7 +6098,8 @@ async function getPoolInfo({
|
|
|
6005
6098
|
};
|
|
6006
6099
|
}
|
|
6007
6100
|
async function getUniswapQuote(input, client) {
|
|
6008
|
-
const { type, quantity, poolAddress,
|
|
6101
|
+
const { type, quantity, poolAddress, erc20z } = input;
|
|
6102
|
+
const chainId = client.chain.id;
|
|
6009
6103
|
const WETH = wethAddresses[chainId];
|
|
6010
6104
|
const pool = await getPoolInfo({ poolAddress, WETH, erc20z, client });
|
|
6011
6105
|
const { fee, wethBalance, erc20zBalance } = pool;
|
|
@@ -6076,10 +6170,10 @@ var MARKET_REWARD = parseEther5("0.0000222");
|
|
|
6076
6170
|
async function getSecondaryInfo({
|
|
6077
6171
|
contract,
|
|
6078
6172
|
tokenId,
|
|
6079
|
-
publicClient
|
|
6080
|
-
chainId
|
|
6173
|
+
publicClient
|
|
6081
6174
|
}) {
|
|
6082
6175
|
let result;
|
|
6176
|
+
const chainId = publicClient.chain.id;
|
|
6083
6177
|
try {
|
|
6084
6178
|
result = await publicClient.readContract({
|
|
6085
6179
|
abi: zoraTimedSaleStrategyABI3,
|
|
@@ -6131,7 +6225,6 @@ async function makeBuy({
|
|
|
6131
6225
|
quantity,
|
|
6132
6226
|
account,
|
|
6133
6227
|
recipient,
|
|
6134
|
-
chainId,
|
|
6135
6228
|
slippage,
|
|
6136
6229
|
publicClient,
|
|
6137
6230
|
comment
|
|
@@ -6152,7 +6245,7 @@ async function makeBuy({
|
|
|
6152
6245
|
return handleBuyWithComment({
|
|
6153
6246
|
accountAddress,
|
|
6154
6247
|
recipient,
|
|
6155
|
-
chainId,
|
|
6248
|
+
chainId: publicClient.chain.id,
|
|
6156
6249
|
quantity,
|
|
6157
6250
|
contract,
|
|
6158
6251
|
tokenId,
|
|
@@ -6167,7 +6260,7 @@ async function makeBuy({
|
|
|
6167
6260
|
recipient,
|
|
6168
6261
|
accountAddress,
|
|
6169
6262
|
costWithSlippage,
|
|
6170
|
-
chainId,
|
|
6263
|
+
chainId: publicClient.chain.id,
|
|
6171
6264
|
account
|
|
6172
6265
|
});
|
|
6173
6266
|
}
|
|
@@ -6251,12 +6344,11 @@ function handleBuyWithoutComment({
|
|
|
6251
6344
|
})
|
|
6252
6345
|
};
|
|
6253
6346
|
}
|
|
6254
|
-
async function
|
|
6347
|
+
async function buy1155OnSecondary({
|
|
6255
6348
|
contract,
|
|
6256
6349
|
tokenId,
|
|
6257
6350
|
publicClient,
|
|
6258
6351
|
quantity,
|
|
6259
|
-
chainId,
|
|
6260
6352
|
account,
|
|
6261
6353
|
slippage = UNISWAP_SLIPPAGE,
|
|
6262
6354
|
recipient,
|
|
@@ -6265,8 +6357,7 @@ async function buyWithSlippage({
|
|
|
6265
6357
|
const secondaryInfo = await getSecondaryInfo({
|
|
6266
6358
|
contract,
|
|
6267
6359
|
tokenId,
|
|
6268
|
-
publicClient
|
|
6269
|
-
chainId
|
|
6360
|
+
publicClient
|
|
6270
6361
|
});
|
|
6271
6362
|
if (!secondaryInfo) {
|
|
6272
6363
|
return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
|
|
@@ -6280,8 +6371,7 @@ async function buyWithSlippage({
|
|
|
6280
6371
|
type: "buy",
|
|
6281
6372
|
quantity,
|
|
6282
6373
|
poolAddress: pool,
|
|
6283
|
-
erc20z
|
|
6284
|
-
chainId
|
|
6374
|
+
erc20z
|
|
6285
6375
|
},
|
|
6286
6376
|
publicClient
|
|
6287
6377
|
);
|
|
@@ -6294,7 +6384,6 @@ async function buyWithSlippage({
|
|
|
6294
6384
|
quantity,
|
|
6295
6385
|
account,
|
|
6296
6386
|
recipient,
|
|
6297
|
-
chainId,
|
|
6298
6387
|
slippage,
|
|
6299
6388
|
comment,
|
|
6300
6389
|
publicClient
|
|
@@ -6312,7 +6401,6 @@ async function makeSell({
|
|
|
6312
6401
|
quantity,
|
|
6313
6402
|
account,
|
|
6314
6403
|
recipient,
|
|
6315
|
-
chainId,
|
|
6316
6404
|
slippage,
|
|
6317
6405
|
publicClient
|
|
6318
6406
|
}) {
|
|
@@ -6337,6 +6425,7 @@ async function makeSell({
|
|
|
6337
6425
|
receivedWithSlippage,
|
|
6338
6426
|
0n
|
|
6339
6427
|
]);
|
|
6428
|
+
const chainId = publicClient.chain.id;
|
|
6340
6429
|
return {
|
|
6341
6430
|
parameters: makeContractParameters({
|
|
6342
6431
|
abi: zoraCreator1155ImplABI7,
|
|
@@ -6353,12 +6442,11 @@ async function makeSell({
|
|
|
6353
6442
|
})
|
|
6354
6443
|
};
|
|
6355
6444
|
}
|
|
6356
|
-
async function
|
|
6445
|
+
async function sell1155OnSecondary({
|
|
6357
6446
|
contract,
|
|
6358
6447
|
tokenId,
|
|
6359
6448
|
publicClient,
|
|
6360
6449
|
quantity,
|
|
6361
|
-
chainId,
|
|
6362
6450
|
account,
|
|
6363
6451
|
slippage = UNISWAP_SLIPPAGE,
|
|
6364
6452
|
recipient
|
|
@@ -6366,8 +6454,7 @@ async function sellWithSlippage({
|
|
|
6366
6454
|
const secondaryInfo = await getSecondaryInfo({
|
|
6367
6455
|
contract,
|
|
6368
6456
|
tokenId,
|
|
6369
|
-
publicClient
|
|
6370
|
-
chainId
|
|
6457
|
+
publicClient
|
|
6371
6458
|
});
|
|
6372
6459
|
if (!secondaryInfo) {
|
|
6373
6460
|
return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
|
|
@@ -6377,7 +6464,7 @@ async function sellWithSlippage({
|
|
|
6377
6464
|
return makeError(ERROR_SECONDARY_NOT_STARTED);
|
|
6378
6465
|
}
|
|
6379
6466
|
const { poolBalance, amount, price } = await getUniswapQuote(
|
|
6380
|
-
{ type: "sell", quantity, poolAddress: pool,
|
|
6467
|
+
{ type: "sell", quantity, poolAddress: pool, erc20z },
|
|
6381
6468
|
publicClient
|
|
6382
6469
|
);
|
|
6383
6470
|
const call = await makeSell({
|
|
@@ -6388,7 +6475,6 @@ async function sellWithSlippage({
|
|
|
6388
6475
|
quantity,
|
|
6389
6476
|
account,
|
|
6390
6477
|
recipient,
|
|
6391
|
-
chainId,
|
|
6392
6478
|
slippage,
|
|
6393
6479
|
publicClient
|
|
6394
6480
|
});
|
|
@@ -6403,12 +6489,8 @@ var SecondaryClient = class {
|
|
|
6403
6489
|
* @param publicClient - The public client for interacting with the blockchain.
|
|
6404
6490
|
* @param chainId - The ID of the blockchain network.
|
|
6405
6491
|
*/
|
|
6406
|
-
constructor({
|
|
6407
|
-
publicClient,
|
|
6408
|
-
chainId
|
|
6409
|
-
}) {
|
|
6492
|
+
constructor({ publicClient }) {
|
|
6410
6493
|
this.publicClient = publicClient;
|
|
6411
|
-
this.chainId = chainId;
|
|
6412
6494
|
}
|
|
6413
6495
|
/**
|
|
6414
6496
|
* Get the secondary info for a given contract and token ID.
|
|
@@ -6423,8 +6505,7 @@ var SecondaryClient = class {
|
|
|
6423
6505
|
return getSecondaryInfo({
|
|
6424
6506
|
contract,
|
|
6425
6507
|
tokenId,
|
|
6426
|
-
publicClient: this.publicClient
|
|
6427
|
-
chainId: this.chainId
|
|
6508
|
+
publicClient: this.publicClient
|
|
6428
6509
|
});
|
|
6429
6510
|
}
|
|
6430
6511
|
/**
|
|
@@ -6433,10 +6514,9 @@ var SecondaryClient = class {
|
|
|
6433
6514
|
* @returns A promise that resolves to the result of the buy operation, including price breakdown and transaction parameters.
|
|
6434
6515
|
*/
|
|
6435
6516
|
async buy1155OnSecondary(input) {
|
|
6436
|
-
return
|
|
6517
|
+
return buy1155OnSecondary({
|
|
6437
6518
|
...input,
|
|
6438
|
-
publicClient: this.publicClient
|
|
6439
|
-
chainId: this.chainId
|
|
6519
|
+
publicClient: this.publicClient
|
|
6440
6520
|
});
|
|
6441
6521
|
}
|
|
6442
6522
|
/**
|
|
@@ -6445,10 +6525,9 @@ var SecondaryClient = class {
|
|
|
6445
6525
|
* @returns A promise that resolves to the result of the sell operation, including price breakdown and transaction parameters.
|
|
6446
6526
|
*/
|
|
6447
6527
|
async sell1155OnSecondary(input) {
|
|
6448
|
-
return
|
|
6528
|
+
return sell1155OnSecondary({
|
|
6449
6529
|
...input,
|
|
6450
|
-
publicClient: this.publicClient
|
|
6451
|
-
chainId: this.chainId
|
|
6530
|
+
publicClient: this.publicClient
|
|
6452
6531
|
});
|
|
6453
6532
|
}
|
|
6454
6533
|
};
|
|
@@ -6461,12 +6540,10 @@ function createCreatorClient(clientConfig) {
|
|
|
6461
6540
|
premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
|
|
6462
6541
|
});
|
|
6463
6542
|
const create1155CreatorClient = new Create1155Client({
|
|
6464
|
-
chainId: clientConfig.chainId,
|
|
6465
6543
|
publicClient: clientConfig.publicClient,
|
|
6466
6544
|
contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
|
|
6467
6545
|
});
|
|
6468
6546
|
const rewardsClient = new RewardsClient({
|
|
6469
|
-
chainId: clientConfig.chainId,
|
|
6470
6547
|
publicClient: clientConfig.publicClient,
|
|
6471
6548
|
rewardsGetter: clientConfig.rewardsGetter || new SubgraphRewardsGetter(clientConfig.chainId)
|
|
6472
6549
|
});
|
|
@@ -6486,12 +6563,10 @@ function createCollectorClient(params) {
|
|
|
6486
6563
|
const mintClient = new MintClient({
|
|
6487
6564
|
publicClient: params.publicClient,
|
|
6488
6565
|
premintGetter: premintGetterToUse,
|
|
6489
|
-
mintGetter: mintGetterToUse
|
|
6490
|
-
chainId: params.chainId
|
|
6566
|
+
mintGetter: mintGetterToUse
|
|
6491
6567
|
});
|
|
6492
6568
|
const secondaryClient = new SecondaryClient({
|
|
6493
|
-
publicClient: params.publicClient
|
|
6494
|
-
chainId: params.chainId
|
|
6569
|
+
publicClient: params.publicClient
|
|
6495
6570
|
});
|
|
6496
6571
|
return {
|
|
6497
6572
|
getPremint: (p) => premintGetterToUse.get({
|
|
@@ -6514,7 +6589,7 @@ function isArweaveURL(url) {
|
|
|
6514
6589
|
return url && typeof url === "string" ? url.startsWith("ar://") : false;
|
|
6515
6590
|
}
|
|
6516
6591
|
|
|
6517
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
6592
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bytes.js
|
|
6518
6593
|
var empty = new Uint8Array(0);
|
|
6519
6594
|
function equals(aa, bb) {
|
|
6520
6595
|
if (aa === bb)
|
|
@@ -6540,7 +6615,7 @@ function coerce3(o) {
|
|
|
6540
6615
|
throw new Error("Unknown type, must be binary type");
|
|
6541
6616
|
}
|
|
6542
6617
|
|
|
6543
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
6618
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
6544
6619
|
function base3(ALPHABET, name) {
|
|
6545
6620
|
if (ALPHABET.length >= 255) {
|
|
6546
6621
|
throw new TypeError("Alphabet too long");
|
|
@@ -6676,7 +6751,7 @@ var src = base3;
|
|
|
6676
6751
|
var _brrp__multiformats_scope_baseX = src;
|
|
6677
6752
|
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
6678
6753
|
|
|
6679
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
6754
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base.js
|
|
6680
6755
|
var Encoder = class {
|
|
6681
6756
|
constructor(name, prefix, baseEncode) {
|
|
6682
6757
|
__publicField(this, "name");
|
|
@@ -6702,10 +6777,11 @@ var Decoder = class {
|
|
|
6702
6777
|
__publicField(this, "prefixCodePoint");
|
|
6703
6778
|
this.name = name;
|
|
6704
6779
|
this.prefix = prefix;
|
|
6705
|
-
|
|
6780
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
6781
|
+
if (prefixCodePoint === void 0) {
|
|
6706
6782
|
throw new Error("Invalid prefix character");
|
|
6707
6783
|
}
|
|
6708
|
-
this.prefixCodePoint =
|
|
6784
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
6709
6785
|
this.baseDecode = baseDecode;
|
|
6710
6786
|
}
|
|
6711
6787
|
decode(text) {
|
|
@@ -6847,7 +6923,7 @@ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
|
6847
6923
|
});
|
|
6848
6924
|
}
|
|
6849
6925
|
|
|
6850
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
6926
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base32.js
|
|
6851
6927
|
var base32 = rfc4648({
|
|
6852
6928
|
prefix: "b",
|
|
6853
6929
|
name: "base32",
|
|
@@ -6903,7 +6979,19 @@ var base32z = rfc4648({
|
|
|
6903
6979
|
bitsPerChar: 5
|
|
6904
6980
|
});
|
|
6905
6981
|
|
|
6906
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
6982
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base36.js
|
|
6983
|
+
var base36 = baseX({
|
|
6984
|
+
prefix: "k",
|
|
6985
|
+
name: "base36",
|
|
6986
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
6987
|
+
});
|
|
6988
|
+
var base36upper = baseX({
|
|
6989
|
+
prefix: "K",
|
|
6990
|
+
name: "base36upper",
|
|
6991
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
6992
|
+
});
|
|
6993
|
+
|
|
6994
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
6907
6995
|
var base58btc = baseX({
|
|
6908
6996
|
name: "base58btc",
|
|
6909
6997
|
prefix: "z",
|
|
@@ -6915,7 +7003,7 @@ var base58flickr = baseX({
|
|
|
6915
7003
|
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
6916
7004
|
});
|
|
6917
7005
|
|
|
6918
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
7006
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/vendor/varint.js
|
|
6919
7007
|
var encode_1 = encode2;
|
|
6920
7008
|
var MSB = 128;
|
|
6921
7009
|
var REST = 127;
|
|
@@ -6974,7 +7062,7 @@ var varint = {
|
|
|
6974
7062
|
var _brrp_varint = varint;
|
|
6975
7063
|
var varint_default = _brrp_varint;
|
|
6976
7064
|
|
|
6977
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
7065
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/varint.js
|
|
6978
7066
|
function decode3(data, offset = 0) {
|
|
6979
7067
|
const code = varint_default.decode(data, offset);
|
|
6980
7068
|
return [code, varint_default.decode.bytes];
|
|
@@ -6987,7 +7075,7 @@ function encodingLength(int) {
|
|
|
6987
7075
|
return varint_default.encodingLength(int);
|
|
6988
7076
|
}
|
|
6989
7077
|
|
|
6990
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
7078
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/hashes/digest.js
|
|
6991
7079
|
function create(code, digest) {
|
|
6992
7080
|
const size = digest.byteLength;
|
|
6993
7081
|
const sizeOffset = encodingLength(code);
|
|
@@ -7032,7 +7120,7 @@ var Digest = class {
|
|
|
7032
7120
|
}
|
|
7033
7121
|
};
|
|
7034
7122
|
|
|
7035
|
-
// ../../node_modules/.pnpm/multiformats@13.
|
|
7123
|
+
// ../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/cid.js
|
|
7036
7124
|
function format(link, base4) {
|
|
7037
7125
|
const { bytes, version } = link;
|
|
7038
7126
|
switch (version) {
|
|
@@ -7318,9 +7406,13 @@ function parseCIDtoBytes(source, base4) {
|
|
|
7318
7406
|
const decoder = base4 ?? base32;
|
|
7319
7407
|
return [base32.prefix, decoder.decode(source)];
|
|
7320
7408
|
}
|
|
7409
|
+
case base36.prefix: {
|
|
7410
|
+
const decoder = base4 ?? base36;
|
|
7411
|
+
return [base36.prefix, decoder.decode(source)];
|
|
7412
|
+
}
|
|
7321
7413
|
default: {
|
|
7322
7414
|
if (base4 == null) {
|
|
7323
|
-
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
7415
|
+
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
7324
7416
|
}
|
|
7325
7417
|
return [source[0], base4.decode(source)];
|
|
7326
7418
|
}
|
|
@@ -7735,10 +7827,12 @@ export {
|
|
|
7735
7827
|
PremintAPIClient,
|
|
7736
7828
|
PremintClient,
|
|
7737
7829
|
PremintConfigVersion3 as PremintConfigVersion,
|
|
7830
|
+
SubgraphContractGetter,
|
|
7738
7831
|
SubgraphMintGetter,
|
|
7739
7832
|
ZORA_API_BASE,
|
|
7740
7833
|
applyUpdateToPremint,
|
|
7741
7834
|
buildPremintMintCall,
|
|
7835
|
+
buy1155OnSecondary,
|
|
7742
7836
|
collectPremint,
|
|
7743
7837
|
collectPremintV2WithMintsParams,
|
|
7744
7838
|
collectWithMintsParams,
|
|
@@ -7746,9 +7840,11 @@ export {
|
|
|
7746
7840
|
convertGetPremintApiResponse,
|
|
7747
7841
|
convertGetPremintOfCollectionApiResponse,
|
|
7748
7842
|
convertPremintFromApi,
|
|
7843
|
+
create1155,
|
|
7749
7844
|
createAllowList,
|
|
7750
7845
|
createCollectorClient,
|
|
7751
7846
|
createCreatorClient,
|
|
7847
|
+
createNew1155Token,
|
|
7752
7848
|
decodeCallFailedError,
|
|
7753
7849
|
defaultAdditionalAdmins,
|
|
7754
7850
|
defaultTokenConfigV1MintArguments,
|
|
@@ -7757,8 +7853,8 @@ export {
|
|
|
7757
7853
|
encodeCollectOnManager,
|
|
7758
7854
|
encodePostSignatureInput,
|
|
7759
7855
|
encodePremintForAPI,
|
|
7856
|
+
findTargetStrategyWithPrimaryOrSecondarySaleActive,
|
|
7760
7857
|
generateTextNftMetadataFiles,
|
|
7761
|
-
getApiNetworkConfigForChain,
|
|
7762
7858
|
getContractAddressFromReceipt,
|
|
7763
7859
|
getDataFromPremintReceipt,
|
|
7764
7860
|
getDefaultFixedPriceMinterAddress,
|
|
@@ -7771,31 +7867,46 @@ export {
|
|
|
7771
7867
|
getPremintMintFee,
|
|
7772
7868
|
getPremintPricePerToken,
|
|
7773
7869
|
getPremintedLogFromReceipt,
|
|
7870
|
+
getRewardsBalances,
|
|
7871
|
+
getSecondaryInfo,
|
|
7774
7872
|
getSignature,
|
|
7873
|
+
getToken,
|
|
7775
7874
|
getTokenIdFromCreateReceipt,
|
|
7875
|
+
getTokensOfContract,
|
|
7876
|
+
is1155Mint,
|
|
7776
7877
|
isAuthorizedToCreatePremint,
|
|
7878
|
+
isOnChainMint,
|
|
7777
7879
|
isPremintConfigV1,
|
|
7778
7880
|
isPremintConfigV2,
|
|
7779
7881
|
isValidSignature,
|
|
7780
7882
|
makeCreateContractAndTokenCall,
|
|
7883
|
+
makeCreateTokenCall,
|
|
7781
7884
|
makeMediaTokenMetadata,
|
|
7782
7885
|
makeMintRewardsRecipient,
|
|
7783
7886
|
makeNewPremint,
|
|
7887
|
+
makeOnchainPrepareMintFromCreate,
|
|
7784
7888
|
makePermitToCollectPremintOrNonPremint,
|
|
7785
7889
|
makePermitTransferBatchAndTypeData,
|
|
7786
7890
|
makePermitTransferTypeData,
|
|
7787
7891
|
makeTextTokenMetadata,
|
|
7788
7892
|
makeUrls,
|
|
7789
7893
|
migratePremintConfigToV2,
|
|
7894
|
+
mint,
|
|
7790
7895
|
mintWithEthParams,
|
|
7791
7896
|
mintsBalanceOfAccountParams,
|
|
7897
|
+
new1155ContractVersion,
|
|
7898
|
+
parseAndFilterTokenQueryResult,
|
|
7899
|
+
prepareSetupActions,
|
|
7792
7900
|
recoverCreatorFromCreatorAttribution,
|
|
7793
7901
|
recoverPremintSigner,
|
|
7794
7902
|
selectMintsToCollectWithFromQueryResult,
|
|
7903
|
+
sell1155OnSecondary,
|
|
7795
7904
|
sumBalances,
|
|
7796
7905
|
supportedPremintVersions,
|
|
7797
7906
|
supportsPremintVersion,
|
|
7798
7907
|
toContractCreationConfigOrAddress,
|
|
7799
|
-
|
|
7908
|
+
toMintableReturn,
|
|
7909
|
+
tryRecoverPremintSigner,
|
|
7910
|
+
withdrawRewards
|
|
7800
7911
|
};
|
|
7801
7912
|
//# sourceMappingURL=index.js.map
|