@zoralabs/protocol-sdk 0.9.6 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +17 -0
- package/dist/anvil.d.ts +11 -1
- package/dist/anvil.d.ts.map +1 -1
- package/dist/apis/multicall3.d.ts +9 -0
- package/dist/apis/multicall3.d.ts.map +1 -0
- package/dist/apis/subgraph-getter.d.ts +9 -0
- package/dist/apis/subgraph-getter.d.ts.map +1 -0
- package/dist/create/1155-create-helper.test.d.ts +3 -0
- package/dist/create/1155-create-helper.test.d.ts.map +1 -0
- package/dist/create/contract-getter.d.ts +3 -6
- package/dist/create/contract-getter.d.ts.map +1 -1
- package/dist/fixtures/contract-setup.d.ts +16 -0
- package/dist/fixtures/contract-setup.d.ts.map +1 -0
- package/dist/fixtures/mint-query-results.d.ts +10 -0
- package/dist/fixtures/mint-query-results.d.ts.map +1 -0
- package/dist/fixtures/rewards-query-results.d.ts +6 -0
- package/dist/fixtures/rewards-query-results.d.ts.map +1 -0
- package/dist/index.cjs +989 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1013 -238
- package/dist/index.js.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +3 -5
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/rewards/rewards-client.d.ts +34 -0
- package/dist/rewards/rewards-client.d.ts.map +1 -0
- package/dist/rewards/rewards-queries.d.ts +34 -0
- package/dist/rewards/rewards-queries.d.ts.map +1 -0
- package/dist/rewards/subgraph-queries.d.ts +20 -0
- package/dist/rewards/subgraph-queries.d.ts.map +1 -0
- package/dist/rewards/subgraph-rewards-getter.d.ts +15 -0
- package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -0
- package/dist/sdk.d.ts +9 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/secondary/conversions.d.ts +7 -0
- package/dist/secondary/conversions.d.ts.map +1 -0
- package/dist/secondary/secondary-client.d.ts +67 -0
- package/dist/secondary/secondary-client.d.ts.map +1 -0
- package/dist/secondary/slippage.d.ts +25 -0
- package/dist/secondary/slippage.d.ts.map +1 -0
- package/dist/secondary/types.d.ts +37 -0
- package/dist/secondary/types.d.ts.map +1 -0
- package/dist/secondary/uniswap/abis.d.ts +152 -0
- package/dist/secondary/uniswap/abis.d.ts.map +1 -0
- package/dist/secondary/uniswap/uniswapQuote.d.ts +13 -0
- package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -0
- package/dist/secondary/uniswap/uniswapQuoteExact.d.ts +37 -0
- package/dist/secondary/uniswap/uniswapQuoteExact.d.ts.map +1 -0
- package/dist/secondary/uniswap/uniswapReserves.d.ts +3 -0
- package/dist/secondary/uniswap/uniswapReserves.d.ts.map +1 -0
- package/dist/secondary/utils.d.ts +10 -0
- package/dist/secondary/utils.d.ts.map +1 -0
- package/dist/sparks/sparks-contracts.d.ts.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/multicall3.ts +19 -0
- package/src/apis/subgraph-getter.ts +33 -0
- package/src/create/1155-create-helper.test.ts +18 -18
- package/src/create/contract-getter.ts +7 -29
- package/src/fixtures/contract-setup.ts +57 -0
- package/src/fixtures/mint-query-results.ts +55 -0
- package/src/fixtures/rewards-query-results.ts +25 -0
- package/src/mint/mint-client.test.ts +18 -46
- package/src/mint/subgraph-mint-getter.ts +7 -27
- package/src/rewards/rewards-client.test.ts +310 -0
- package/src/rewards/rewards-client.ts +67 -0
- package/src/rewards/rewards-queries.ts +253 -0
- package/src/rewards/subgraph-queries.ts +49 -0
- package/src/rewards/subgraph-rewards-getter.ts +33 -0
- package/src/sdk.ts +29 -0
- package/src/secondary/conversions.ts +20 -0
- package/src/secondary/secondary-client.test.ts +276 -0
- package/src/secondary/secondary-client.ts +374 -0
- package/src/secondary/slippage.ts +42 -0
- package/src/secondary/types.ts +64 -0
- package/src/secondary/uniswap/abis.ts +20 -0
- package/src/secondary/uniswap/uniswapQuote.ts +134 -0
- package/src/secondary/uniswap/uniswapQuoteExact.ts +114 -0
- package/src/secondary/uniswap/uniswapReserves.ts +34 -0
- package/src/secondary/utils.ts +40 -0
- package/src/sparks/sparks-contracts.ts +1 -3
- package/src/types.ts +6 -7
- package/src/utils.ts +7 -1
package/dist/index.js
CHANGED
|
@@ -391,12 +391,12 @@ var require_semver = __commonJS({
|
|
|
391
391
|
this.prerelease = [];
|
|
392
392
|
break;
|
|
393
393
|
case "pre": {
|
|
394
|
-
const
|
|
394
|
+
const base4 = Number(identifierBase) ? 1 : 0;
|
|
395
395
|
if (!identifier && identifierBase === false) {
|
|
396
396
|
throw new Error("invalid increment argument: identifier is empty");
|
|
397
397
|
}
|
|
398
398
|
if (this.prerelease.length === 0) {
|
|
399
|
-
this.prerelease = [
|
|
399
|
+
this.prerelease = [base4];
|
|
400
400
|
} else {
|
|
401
401
|
let i = this.prerelease.length;
|
|
402
402
|
while (--i >= 0) {
|
|
@@ -409,11 +409,11 @@ var require_semver = __commonJS({
|
|
|
409
409
|
if (identifier === this.prerelease.join(".") && identifierBase === false) {
|
|
410
410
|
throw new Error("invalid increment argument: identifier already exists");
|
|
411
411
|
}
|
|
412
|
-
this.prerelease.push(
|
|
412
|
+
this.prerelease.push(base4);
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
if (identifier) {
|
|
416
|
-
let prerelease = [identifier,
|
|
416
|
+
let prerelease = [identifier, base4];
|
|
417
417
|
if (identifierBase === false) {
|
|
418
418
|
prerelease = [identifier];
|
|
419
419
|
}
|
|
@@ -2503,136 +2503,6 @@ import {
|
|
|
2503
2503
|
premintTypedDataDefinition as premintTypedDataDefinition2
|
|
2504
2504
|
} from "@zoralabs/protocol-deployments";
|
|
2505
2505
|
|
|
2506
|
-
// src/retries.ts
|
|
2507
|
-
async function wait(delayMs) {
|
|
2508
|
-
return new Promise((resolve) => {
|
|
2509
|
-
setTimeout(resolve, delayMs);
|
|
2510
|
-
});
|
|
2511
|
-
}
|
|
2512
|
-
var retryInternal = async ({
|
|
2513
|
-
tryFn,
|
|
2514
|
-
maxTries = 3,
|
|
2515
|
-
atTry,
|
|
2516
|
-
linearBackoffMS = 200,
|
|
2517
|
-
shouldRetryOnError = () => true
|
|
2518
|
-
}) => {
|
|
2519
|
-
try {
|
|
2520
|
-
return await tryFn();
|
|
2521
|
-
} catch (err) {
|
|
2522
|
-
if (shouldRetryOnError(err)) {
|
|
2523
|
-
if (atTry <= maxTries) {
|
|
2524
|
-
await wait(atTry * linearBackoffMS);
|
|
2525
|
-
return await retryInternal({
|
|
2526
|
-
tryFn,
|
|
2527
|
-
maxTries,
|
|
2528
|
-
atTry: atTry + 1,
|
|
2529
|
-
linearBackoffMS,
|
|
2530
|
-
shouldRetryOnError
|
|
2531
|
-
});
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
throw err;
|
|
2535
|
-
}
|
|
2536
|
-
};
|
|
2537
|
-
var retriesGeneric = async (params) => {
|
|
2538
|
-
return retryInternal({
|
|
2539
|
-
...params,
|
|
2540
|
-
atTry: 1
|
|
2541
|
-
});
|
|
2542
|
-
};
|
|
2543
|
-
|
|
2544
|
-
// src/apis/http-api-base.ts
|
|
2545
|
-
var BadResponseError = class extends Error {
|
|
2546
|
-
constructor(message, status, json) {
|
|
2547
|
-
super(message);
|
|
2548
|
-
this.name = "BadResponseError";
|
|
2549
|
-
this.status = status;
|
|
2550
|
-
this.json = json;
|
|
2551
|
-
}
|
|
2552
|
-
};
|
|
2553
|
-
var get = async (url) => {
|
|
2554
|
-
const response = await fetch(url, { method: "GET" });
|
|
2555
|
-
if (response.status !== 200) {
|
|
2556
|
-
let json;
|
|
2557
|
-
try {
|
|
2558
|
-
json = await response.json();
|
|
2559
|
-
} catch (e) {
|
|
2560
|
-
}
|
|
2561
|
-
throw new BadResponseError(
|
|
2562
|
-
`Invalid response, status ${response.status}`,
|
|
2563
|
-
response.status,
|
|
2564
|
-
json
|
|
2565
|
-
);
|
|
2566
|
-
}
|
|
2567
|
-
return await response.json();
|
|
2568
|
-
};
|
|
2569
|
-
var post = async (url, data) => {
|
|
2570
|
-
const controller = new AbortController();
|
|
2571
|
-
const { signal } = controller;
|
|
2572
|
-
const timeout = 30 * 60 * 1e3;
|
|
2573
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2574
|
-
const response = await fetch(url, {
|
|
2575
|
-
method: "POST",
|
|
2576
|
-
headers: {
|
|
2577
|
-
"content-type": "application/json",
|
|
2578
|
-
accept: "application/json"
|
|
2579
|
-
},
|
|
2580
|
-
body: JSON.stringify(data),
|
|
2581
|
-
signal
|
|
2582
|
-
});
|
|
2583
|
-
clearTimeout(timeoutId);
|
|
2584
|
-
if (response.status !== 200) {
|
|
2585
|
-
let json;
|
|
2586
|
-
try {
|
|
2587
|
-
json = await response.json();
|
|
2588
|
-
} catch (e) {
|
|
2589
|
-
}
|
|
2590
|
-
throw new BadResponseError(
|
|
2591
|
-
`Bad response: ${response.status}`,
|
|
2592
|
-
response.status,
|
|
2593
|
-
json
|
|
2594
|
-
);
|
|
2595
|
-
}
|
|
2596
|
-
return await response.json();
|
|
2597
|
-
};
|
|
2598
|
-
var defaultShouldRetry = (err) => {
|
|
2599
|
-
return err instanceof BadResponseError && err.status >= 500;
|
|
2600
|
-
};
|
|
2601
|
-
var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
|
|
2602
|
-
return retriesGeneric({
|
|
2603
|
-
tryFn,
|
|
2604
|
-
maxTries,
|
|
2605
|
-
linearBackoffMS,
|
|
2606
|
-
shouldRetryOnError: shouldRetry
|
|
2607
|
-
});
|
|
2608
|
-
};
|
|
2609
|
-
var httpClient = {
|
|
2610
|
-
get,
|
|
2611
|
-
post,
|
|
2612
|
-
retries
|
|
2613
|
-
};
|
|
2614
|
-
|
|
2615
|
-
// src/apis/subgraph-querier.ts
|
|
2616
|
-
var SubgraphQuerier = class {
|
|
2617
|
-
constructor(httpClient2) {
|
|
2618
|
-
this.httpClient = httpClient2;
|
|
2619
|
-
}
|
|
2620
|
-
async query({
|
|
2621
|
-
subgraphUrl,
|
|
2622
|
-
query,
|
|
2623
|
-
variables
|
|
2624
|
-
}) {
|
|
2625
|
-
const { retries: retries2, post: post2 } = this.httpClient;
|
|
2626
|
-
const result = await retries2(async () => {
|
|
2627
|
-
return await post2(subgraphUrl, {
|
|
2628
|
-
query,
|
|
2629
|
-
variables
|
|
2630
|
-
});
|
|
2631
|
-
});
|
|
2632
|
-
return result?.data;
|
|
2633
|
-
}
|
|
2634
|
-
};
|
|
2635
|
-
|
|
2636
2506
|
// src/mint/subgraph-queries.ts
|
|
2637
2507
|
var NFT_SALE_STRATEGY_FRAGMENT = `
|
|
2638
2508
|
fragment SaleStrategy on SalesStrategyConfig {
|
|
@@ -2759,59 +2629,209 @@ function buildPremintsOfContractQuery({
|
|
|
2759
2629
|
};
|
|
2760
2630
|
}
|
|
2761
2631
|
|
|
2762
|
-
// src/
|
|
2763
|
-
var
|
|
2764
|
-
|
|
2765
|
-
|
|
2632
|
+
// src/apis/subgraph-querier.ts
|
|
2633
|
+
var SubgraphQuerier = class {
|
|
2634
|
+
constructor(httpClient2) {
|
|
2635
|
+
this.httpClient = httpClient2;
|
|
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;
|
|
2766
2650
|
}
|
|
2767
|
-
return networkConfigByChain[chainId];
|
|
2768
2651
|
};
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2652
|
+
|
|
2653
|
+
// src/retries.ts
|
|
2654
|
+
async function wait(delayMs) {
|
|
2655
|
+
return new Promise((resolve) => {
|
|
2656
|
+
setTimeout(resolve, delayMs);
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
var retryInternal = async ({
|
|
2660
|
+
tryFn,
|
|
2661
|
+
maxTries = 3,
|
|
2662
|
+
atTry,
|
|
2663
|
+
linearBackoffMS = 200,
|
|
2664
|
+
shouldRetryOnError = () => true
|
|
2665
|
+
}) => {
|
|
2666
|
+
try {
|
|
2667
|
+
return await tryFn();
|
|
2668
|
+
} catch (err) {
|
|
2669
|
+
if (shouldRetryOnError(err)) {
|
|
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
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
throw err;
|
|
2790
2682
|
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2683
|
+
};
|
|
2684
|
+
var retriesGeneric = async (params) => {
|
|
2685
|
+
return retryInternal({
|
|
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;
|
|
2800
2698
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2699
|
+
};
|
|
2700
|
+
var get = async (url) => {
|
|
2701
|
+
const response = await fetch(url, { method: "GET" });
|
|
2702
|
+
if (response.status !== 200) {
|
|
2703
|
+
let json;
|
|
2704
|
+
try {
|
|
2705
|
+
json = await response.json();
|
|
2706
|
+
} catch (e) {
|
|
2707
|
+
}
|
|
2708
|
+
throw new BadResponseError(
|
|
2709
|
+
`Invalid response, status ${response.status}`,
|
|
2710
|
+
response.status,
|
|
2711
|
+
json
|
|
2712
|
+
);
|
|
2713
|
+
}
|
|
2714
|
+
return await response.json();
|
|
2715
|
+
};
|
|
2716
|
+
var post = async (url, data) => {
|
|
2717
|
+
const controller = new AbortController();
|
|
2718
|
+
const { signal } = controller;
|
|
2719
|
+
const timeout = 30 * 60 * 1e3;
|
|
2720
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2721
|
+
const response = await fetch(url, {
|
|
2722
|
+
method: "POST",
|
|
2723
|
+
headers: {
|
|
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
|
+
);
|
|
2742
|
+
}
|
|
2743
|
+
return await response.json();
|
|
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);
|
|
2767
|
+
}
|
|
2768
|
+
async querySubgraphWithRetries({
|
|
2769
|
+
query,
|
|
2770
|
+
variables,
|
|
2771
|
+
parseResponseData
|
|
2772
|
+
}) {
|
|
2773
|
+
const responseData = await this.subgraphQuerier.query({
|
|
2774
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
2775
|
+
query,
|
|
2776
|
+
variables
|
|
2777
|
+
});
|
|
2778
|
+
return parseResponseData(responseData);
|
|
2779
|
+
}
|
|
2780
|
+
};
|
|
2781
|
+
|
|
2782
|
+
// src/mint/subgraph-mint-getter.ts
|
|
2783
|
+
var getApiNetworkConfigForChain = (chainId) => {
|
|
2784
|
+
if (!networkConfigByChain[chainId]) {
|
|
2785
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
2786
|
+
}
|
|
2787
|
+
return networkConfigByChain[chainId];
|
|
2788
|
+
};
|
|
2789
|
+
function parseSalesConfig(targetStrategy, contractMintFee) {
|
|
2790
|
+
if (targetStrategy.type === "FIXED_PRICE")
|
|
2791
|
+
return {
|
|
2792
|
+
saleType: "fixedPrice",
|
|
2793
|
+
...targetStrategy.fixedPrice,
|
|
2794
|
+
maxTokensPerAddress: BigInt(
|
|
2795
|
+
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
2796
|
+
),
|
|
2797
|
+
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken),
|
|
2798
|
+
mintFeePerQuantity: contractMintFee
|
|
2799
|
+
};
|
|
2800
|
+
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
2801
|
+
return {
|
|
2802
|
+
saleType: "erc20",
|
|
2803
|
+
...targetStrategy.erc20Minter,
|
|
2804
|
+
maxTokensPerAddress: BigInt(
|
|
2805
|
+
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
2806
|
+
),
|
|
2807
|
+
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
|
|
2808
|
+
mintFeePerQuantity: 0n
|
|
2809
|
+
};
|
|
2810
|
+
}
|
|
2811
|
+
if (targetStrategy.type === "PRESALE") {
|
|
2812
|
+
return {
|
|
2813
|
+
saleType: "allowlist",
|
|
2814
|
+
address: targetStrategy.presale.address,
|
|
2815
|
+
merkleRoot: targetStrategy.presale.merkleRoot,
|
|
2816
|
+
saleStart: targetStrategy.presale.presaleStart,
|
|
2817
|
+
saleEnd: targetStrategy.presale.presaleEnd,
|
|
2818
|
+
mintFeePerQuantity: contractMintFee
|
|
2819
|
+
};
|
|
2820
|
+
}
|
|
2821
|
+
if (targetStrategy.type === "ZORA_TIMED") {
|
|
2822
|
+
return {
|
|
2823
|
+
saleType: "timed",
|
|
2824
|
+
address: targetStrategy.zoraTimedMinter.address,
|
|
2825
|
+
mintFee: BigInt(targetStrategy.zoraTimedMinter.mintFee),
|
|
2826
|
+
saleStart: targetStrategy.zoraTimedMinter.saleStart,
|
|
2827
|
+
saleEnd: targetStrategy.zoraTimedMinter.saleEnd,
|
|
2828
|
+
erc20Z: targetStrategy.zoraTimedMinter.erc20Z.id,
|
|
2829
|
+
pool: targetStrategy.zoraTimedMinter.erc20Z.pool,
|
|
2830
|
+
secondaryActivated: targetStrategy.zoraTimedMinter.secondaryActivated,
|
|
2831
|
+
mintFeePerQuantity: BigInt(targetStrategy.zoraTimedMinter.mintFee),
|
|
2832
|
+
marketCountdown: targetStrategy.zoraTimedMinter.marketCountdown ? BigInt(targetStrategy.zoraTimedMinter.marketCountdown) : void 0,
|
|
2833
|
+
minimumMarketEth: targetStrategy.zoraTimedMinter.minimumMarketEth ? BigInt(targetStrategy.zoraTimedMinter.minimumMarketEth) : void 0
|
|
2834
|
+
};
|
|
2815
2835
|
}
|
|
2816
2836
|
throw new Error("Unknown saleType");
|
|
2817
2837
|
}
|
|
@@ -2868,8 +2888,9 @@ function getTargetStrategy({
|
|
|
2868
2888
|
}
|
|
2869
2889
|
return targetStrategy;
|
|
2870
2890
|
}
|
|
2871
|
-
var SubgraphMintGetter = class {
|
|
2891
|
+
var SubgraphMintGetter = class extends SubgraphGetter {
|
|
2872
2892
|
constructor(chainId, subgraphQuerier) {
|
|
2893
|
+
super(chainId, subgraphQuerier);
|
|
2873
2894
|
this.getMintable = async ({
|
|
2874
2895
|
tokenAddress,
|
|
2875
2896
|
tokenId,
|
|
@@ -2894,24 +2915,10 @@ var SubgraphMintGetter = class {
|
|
|
2894
2915
|
blockTime
|
|
2895
2916
|
});
|
|
2896
2917
|
};
|
|
2897
|
-
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
2898
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
2899
2918
|
}
|
|
2900
2919
|
async getContractMintFee(contract) {
|
|
2901
2920
|
return BigInt(contract.mintFeePerQuantity);
|
|
2902
2921
|
}
|
|
2903
|
-
async querySubgraphWithRetries({
|
|
2904
|
-
query,
|
|
2905
|
-
variables,
|
|
2906
|
-
parseResponseData
|
|
2907
|
-
}) {
|
|
2908
|
-
const responseData = await this.subgraphQuerier.query({
|
|
2909
|
-
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
2910
|
-
query,
|
|
2911
|
-
variables
|
|
2912
|
-
});
|
|
2913
|
-
return parseResponseData(responseData);
|
|
2914
|
-
}
|
|
2915
2922
|
async getContractMintable({
|
|
2916
2923
|
tokenAddress,
|
|
2917
2924
|
preferredSaleType,
|
|
@@ -3016,6 +3023,7 @@ function mintRecipientOrAccount({
|
|
|
3016
3023
|
}) {
|
|
3017
3024
|
return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
3018
3025
|
}
|
|
3026
|
+
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
3019
3027
|
|
|
3020
3028
|
// src/premint/premint-client.ts
|
|
3021
3029
|
var defaultTokenConfigV1MintArguments = () => ({
|
|
@@ -5128,7 +5136,6 @@ import {
|
|
|
5128
5136
|
encodeFunctionData as encodeFunctionData3,
|
|
5129
5137
|
zeroAddress as zeroAddress7
|
|
5130
5138
|
} from "viem";
|
|
5131
|
-
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
5132
5139
|
var mintWithEthParams = ({
|
|
5133
5140
|
tokenId,
|
|
5134
5141
|
quantity,
|
|
@@ -5382,22 +5389,9 @@ function buildContractInfoQuery({
|
|
|
5382
5389
|
}
|
|
5383
5390
|
|
|
5384
5391
|
// src/create/contract-getter.ts
|
|
5385
|
-
var SubgraphContractGetter = class {
|
|
5392
|
+
var SubgraphContractGetter = class extends SubgraphGetter {
|
|
5386
5393
|
constructor(chainId, subgraphQuerier) {
|
|
5387
|
-
|
|
5388
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
5389
|
-
}
|
|
5390
|
-
async querySubgraphWithRetries({
|
|
5391
|
-
query,
|
|
5392
|
-
variables,
|
|
5393
|
-
parseResponseData
|
|
5394
|
-
}) {
|
|
5395
|
-
const responseData = await this.subgraphQuerier.query({
|
|
5396
|
-
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
5397
|
-
query,
|
|
5398
|
-
variables
|
|
5399
|
-
});
|
|
5400
|
-
return parseResponseData(responseData);
|
|
5394
|
+
super(chainId, subgraphQuerier);
|
|
5401
5395
|
}
|
|
5402
5396
|
async getContractInfo({
|
|
5403
5397
|
contractAddress,
|
|
@@ -5428,6 +5422,773 @@ var SubgraphContractGetter = class {
|
|
|
5428
5422
|
}
|
|
5429
5423
|
};
|
|
5430
5424
|
|
|
5425
|
+
// src/rewards/rewards-queries.ts
|
|
5426
|
+
import {
|
|
5427
|
+
protocolRewardsABI,
|
|
5428
|
+
protocolRewardsAddress,
|
|
5429
|
+
erc20ZRoyaltiesABI,
|
|
5430
|
+
erc20ZRoyaltiesAddress,
|
|
5431
|
+
wethAddress
|
|
5432
|
+
} from "@zoralabs/protocol-deployments";
|
|
5433
|
+
import { encodeFunctionData as encodeFunctionData4, parseAbi as parseAbi2 } from "viem";
|
|
5434
|
+
|
|
5435
|
+
// src/apis/multicall3.ts
|
|
5436
|
+
var multicall3Abi = [
|
|
5437
|
+
"struct Call { address target; bytes callData; }",
|
|
5438
|
+
"struct Call3 { address target; bool allowFailure; bytes callData; }",
|
|
5439
|
+
"struct Call3Value { address target; bool allowFailure; uint256 value; bytes callData; }",
|
|
5440
|
+
"struct Result { bool success; bytes returnData; }",
|
|
5441
|
+
"function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData)",
|
|
5442
|
+
"function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData)",
|
|
5443
|
+
"function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData)"
|
|
5444
|
+
];
|
|
5445
|
+
var multicall3Address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
5446
|
+
|
|
5447
|
+
// src/rewards/rewards-queries.ts
|
|
5448
|
+
function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
|
|
5449
|
+
let ethBalance = 0n;
|
|
5450
|
+
const unclaimedFeesAggregate = unclaimedFees.reduce(
|
|
5451
|
+
(acc, fee) => {
|
|
5452
|
+
const addFee = (token, amount) => {
|
|
5453
|
+
if (token === wethAddress2) {
|
|
5454
|
+
ethBalance += amount;
|
|
5455
|
+
} else if (acc[token]) {
|
|
5456
|
+
acc[token] += amount;
|
|
5457
|
+
} else {
|
|
5458
|
+
acc[token] = amount;
|
|
5459
|
+
}
|
|
5460
|
+
};
|
|
5461
|
+
addFee(fee.token0, fee.token0Amount * 75n / 100n);
|
|
5462
|
+
addFee(fee.token1, fee.token1Amount * 75n / 100n);
|
|
5463
|
+
return acc;
|
|
5464
|
+
},
|
|
5465
|
+
{}
|
|
5466
|
+
);
|
|
5467
|
+
return {
|
|
5468
|
+
eth: ethBalance * 75n / 100n,
|
|
5469
|
+
// Apply 75% fee to ETH balance
|
|
5470
|
+
erc20: unclaimedFeesAggregate
|
|
5471
|
+
};
|
|
5472
|
+
}
|
|
5473
|
+
var getRewardsBalance = async ({
|
|
5474
|
+
account,
|
|
5475
|
+
// The account to check rewards for (Address or Account object)
|
|
5476
|
+
publicClient,
|
|
5477
|
+
// The public client for making blockchain queries
|
|
5478
|
+
chainId,
|
|
5479
|
+
// The ID of the blockchain network
|
|
5480
|
+
rewardsGetter
|
|
5481
|
+
// Interface for getting ERC20Z tokens for a creator
|
|
5482
|
+
}) => {
|
|
5483
|
+
const address = typeof account === "string" ? account : account.address;
|
|
5484
|
+
const erc20Zs = await rewardsGetter.getErc20ZzForCreator({ address });
|
|
5485
|
+
const result = await publicClient.multicall({
|
|
5486
|
+
contracts: [
|
|
5487
|
+
{
|
|
5488
|
+
address: protocolRewardsAddress[chainId],
|
|
5489
|
+
abi: protocolRewardsABI,
|
|
5490
|
+
functionName: "balanceOf",
|
|
5491
|
+
args: [address]
|
|
5492
|
+
},
|
|
5493
|
+
{
|
|
5494
|
+
address: erc20ZRoyaltiesAddress[chainId],
|
|
5495
|
+
abi: erc20ZRoyaltiesABI,
|
|
5496
|
+
functionName: "getUnclaimedFeesBatch",
|
|
5497
|
+
args: [erc20Zs]
|
|
5498
|
+
}
|
|
5499
|
+
],
|
|
5500
|
+
multicallAddress: multicall3Address,
|
|
5501
|
+
allowFailure: false
|
|
5502
|
+
});
|
|
5503
|
+
const protocolRewardsBalance = result[0];
|
|
5504
|
+
const wethAddressForChain = wethAddress[chainId];
|
|
5505
|
+
const unclaimedFeesAggregate = aggregateUnclaimedFees(
|
|
5506
|
+
result[1],
|
|
5507
|
+
wethAddressForChain
|
|
5508
|
+
);
|
|
5509
|
+
return {
|
|
5510
|
+
protocolRewards: protocolRewardsBalance,
|
|
5511
|
+
secondaryRoyalties: unclaimedFeesAggregate
|
|
5512
|
+
};
|
|
5513
|
+
};
|
|
5514
|
+
var withdrawProtocolRewards = ({
|
|
5515
|
+
withdrawFor,
|
|
5516
|
+
chainId
|
|
5517
|
+
}) => {
|
|
5518
|
+
return makeContractParameters({
|
|
5519
|
+
abi: protocolRewardsABI,
|
|
5520
|
+
functionName: "withdrawFor",
|
|
5521
|
+
address: protocolRewardsAddress[chainId],
|
|
5522
|
+
args: [withdrawFor, 0n]
|
|
5523
|
+
});
|
|
5524
|
+
};
|
|
5525
|
+
var makeClaimSecondaryRoyaltiesCalls = async ({
|
|
5526
|
+
claimFor,
|
|
5527
|
+
chainId,
|
|
5528
|
+
rewardsGetter
|
|
5529
|
+
}) => {
|
|
5530
|
+
const erc20z = await rewardsGetter.getErc20ZzForCreator({
|
|
5531
|
+
address: claimFor
|
|
5532
|
+
});
|
|
5533
|
+
const royaltiesAddress = erc20ZRoyaltiesAddress[chainId];
|
|
5534
|
+
if (erc20z.length === 0) {
|
|
5535
|
+
return [];
|
|
5536
|
+
}
|
|
5537
|
+
return erc20z.map((erc20z2) => ({
|
|
5538
|
+
target: royaltiesAddress,
|
|
5539
|
+
callData: encodeFunctionData4({
|
|
5540
|
+
abi: erc20ZRoyaltiesABI,
|
|
5541
|
+
functionName: "claimFor",
|
|
5542
|
+
args: [erc20z2]
|
|
5543
|
+
}),
|
|
5544
|
+
allowFailure: false
|
|
5545
|
+
}));
|
|
5546
|
+
};
|
|
5547
|
+
var createProtocolRewardsCall = (chainId, withdrawFor) => ({
|
|
5548
|
+
target: protocolRewardsAddress[chainId],
|
|
5549
|
+
callData: encodeFunctionData4({
|
|
5550
|
+
abi: protocolRewardsABI,
|
|
5551
|
+
functionName: "withdrawFor",
|
|
5552
|
+
args: [withdrawFor, 0n]
|
|
5553
|
+
}),
|
|
5554
|
+
allowFailure: false
|
|
5555
|
+
});
|
|
5556
|
+
var createMulticallParameters = (calls, account) => makeContractParameters({
|
|
5557
|
+
abi: parseAbi2(multicall3Abi),
|
|
5558
|
+
functionName: "aggregate3",
|
|
5559
|
+
address: multicall3Address,
|
|
5560
|
+
args: [calls],
|
|
5561
|
+
account
|
|
5562
|
+
});
|
|
5563
|
+
var withdrawRewards = async ({
|
|
5564
|
+
account,
|
|
5565
|
+
withdrawFor,
|
|
5566
|
+
claimSecondaryRoyalties = true,
|
|
5567
|
+
chainId,
|
|
5568
|
+
rewardsGetter
|
|
5569
|
+
}) => {
|
|
5570
|
+
if (!claimSecondaryRoyalties) {
|
|
5571
|
+
return {
|
|
5572
|
+
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
5573
|
+
account
|
|
5574
|
+
};
|
|
5575
|
+
}
|
|
5576
|
+
const protocolRewardsCall = createProtocolRewardsCall(chainId, withdrawFor);
|
|
5577
|
+
const secondaryRoyaltiesCalls = await makeClaimSecondaryRoyaltiesCalls({
|
|
5578
|
+
chainId,
|
|
5579
|
+
claimFor: withdrawFor,
|
|
5580
|
+
rewardsGetter
|
|
5581
|
+
});
|
|
5582
|
+
const allCalls = [protocolRewardsCall, ...secondaryRoyaltiesCalls];
|
|
5583
|
+
return createMulticallParameters(allCalls, account);
|
|
5584
|
+
};
|
|
5585
|
+
|
|
5586
|
+
// src/rewards/rewards-client.ts
|
|
5587
|
+
var RewardsClient = class {
|
|
5588
|
+
constructor({
|
|
5589
|
+
chainId,
|
|
5590
|
+
publicClient,
|
|
5591
|
+
rewardsGetter
|
|
5592
|
+
}) {
|
|
5593
|
+
this.chainId = chainId;
|
|
5594
|
+
this.publicClient = publicClient;
|
|
5595
|
+
this.rewardsGetter = rewardsGetter;
|
|
5596
|
+
}
|
|
5597
|
+
/** Withdraws rewards for a given account */
|
|
5598
|
+
async withdrawRewards({
|
|
5599
|
+
account,
|
|
5600
|
+
withdrawFor,
|
|
5601
|
+
claimSecondaryRoyalties
|
|
5602
|
+
}) {
|
|
5603
|
+
return {
|
|
5604
|
+
parameters: await withdrawRewards({
|
|
5605
|
+
chainId: this.chainId,
|
|
5606
|
+
rewardsGetter: this.rewardsGetter,
|
|
5607
|
+
withdrawFor,
|
|
5608
|
+
claimSecondaryRoyalties,
|
|
5609
|
+
account
|
|
5610
|
+
})
|
|
5611
|
+
};
|
|
5612
|
+
}
|
|
5613
|
+
/** Retrieves the rewards balances for a given account */
|
|
5614
|
+
async getRewardsBalances(params) {
|
|
5615
|
+
return getRewardsBalance({
|
|
5616
|
+
account: params.account,
|
|
5617
|
+
chainId: this.chainId,
|
|
5618
|
+
publicClient: this.publicClient,
|
|
5619
|
+
rewardsGetter: this.rewardsGetter
|
|
5620
|
+
});
|
|
5621
|
+
}
|
|
5622
|
+
};
|
|
5623
|
+
|
|
5624
|
+
// src/rewards/subgraph-queries.ts
|
|
5625
|
+
function buildCreatorERC20zs({
|
|
5626
|
+
address
|
|
5627
|
+
}) {
|
|
5628
|
+
return {
|
|
5629
|
+
query: `
|
|
5630
|
+
query ($address: Bytes!) {
|
|
5631
|
+
zoraCreateTokens(
|
|
5632
|
+
where: { royalties_: { user: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
|
|
5633
|
+
) {
|
|
5634
|
+
royalties {
|
|
5635
|
+
user
|
|
5636
|
+
}
|
|
5637
|
+
salesStrategies {
|
|
5638
|
+
zoraTimedMinter {
|
|
5639
|
+
erc20Z {
|
|
5640
|
+
id
|
|
5641
|
+
}
|
|
5642
|
+
}
|
|
5643
|
+
}
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
`,
|
|
5647
|
+
variables: { address },
|
|
5648
|
+
parseResponseData: (responseData) => {
|
|
5649
|
+
return responseData?.zoraCreateTokens;
|
|
5650
|
+
}
|
|
5651
|
+
};
|
|
5652
|
+
}
|
|
5653
|
+
|
|
5654
|
+
// src/rewards/subgraph-rewards-getter.ts
|
|
5655
|
+
var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
5656
|
+
constructor(chainId, subgraphQuerier) {
|
|
5657
|
+
super(chainId, subgraphQuerier);
|
|
5658
|
+
}
|
|
5659
|
+
async getErc20ZzForCreator({
|
|
5660
|
+
address
|
|
5661
|
+
}) {
|
|
5662
|
+
const queryResults = await this.querySubgraphWithRetries(
|
|
5663
|
+
buildCreatorERC20zs({ address })
|
|
5664
|
+
);
|
|
5665
|
+
return queryResults?.map(
|
|
5666
|
+
(result) => result.salesStrategies[0].zoraTimedMinter.erc20Z.id
|
|
5667
|
+
) || [];
|
|
5668
|
+
}
|
|
5669
|
+
};
|
|
5670
|
+
|
|
5671
|
+
// src/secondary/secondary-client.ts
|
|
5672
|
+
import { encodeAbiParameters as encodeAbiParameters2 } from "viem";
|
|
5673
|
+
import {
|
|
5674
|
+
secondarySwapAddress,
|
|
5675
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
|
|
5676
|
+
safeTransferSwapAbiParameters,
|
|
5677
|
+
secondarySwapABI
|
|
5678
|
+
} from "@zoralabs/protocol-deployments";
|
|
5679
|
+
|
|
5680
|
+
// src/secondary/uniswap/uniswapQuote.ts
|
|
5681
|
+
import { erc20Abi } from "viem";
|
|
5682
|
+
|
|
5683
|
+
// src/secondary/uniswap/uniswapReserves.ts
|
|
5684
|
+
import { createPublicClient, http } from "viem";
|
|
5685
|
+
import { mainnet as mainnet2 } from "viem/chains";
|
|
5686
|
+
|
|
5687
|
+
// src/secondary/uniswap/abis.ts
|
|
5688
|
+
import { parseAbi as parseAbi3 } from "viem";
|
|
5689
|
+
var uniswapQuoterABI = parseAbi3([
|
|
5690
|
+
"struct QuoteExactInputSingleParams { address tokenIn; address tokenOut; uint256 amountIn; uint24 fee; uint160 sqrtPriceLimitX96; }",
|
|
5691
|
+
"struct QuoteExactOutputSingleParams { address tokenIn; address tokenOut; uint256 amount; uint24 fee; uint160 sqrtPriceLimitX96; }",
|
|
5692
|
+
"function quoteExactInputSingle(QuoteExactInputSingleParams calldata params) external returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)",
|
|
5693
|
+
"function quoteExactOutputSingle(QuoteExactOutputSingleParams calldata params) external returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)"
|
|
5694
|
+
]);
|
|
5695
|
+
var uniswapV3PoolAbi = parseAbi3([
|
|
5696
|
+
"function fee() external view returns (uint24)",
|
|
5697
|
+
"function liquidity() external view returns (uint128)",
|
|
5698
|
+
"function slot0() external view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)",
|
|
5699
|
+
"function token0() external view returns (address)",
|
|
5700
|
+
"function token1() external view returns (address)"
|
|
5701
|
+
]);
|
|
5702
|
+
var uniswapV2USDCAbi = parseAbi3([
|
|
5703
|
+
"function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)"
|
|
5704
|
+
]);
|
|
5705
|
+
|
|
5706
|
+
// src/secondary/uniswap/uniswapReserves.ts
|
|
5707
|
+
var uniswapV2USDCMainnetAddress = "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc";
|
|
5708
|
+
function getUniswapV2USDCReserves() {
|
|
5709
|
+
const mainnetClient = createPublicClient({
|
|
5710
|
+
chain: mainnet2,
|
|
5711
|
+
transport: http()
|
|
5712
|
+
});
|
|
5713
|
+
return mainnetClient.readContract({
|
|
5714
|
+
address: uniswapV2USDCMainnetAddress,
|
|
5715
|
+
abi: uniswapV2USDCAbi,
|
|
5716
|
+
functionName: "getReserves"
|
|
5717
|
+
});
|
|
5718
|
+
}
|
|
5719
|
+
function toEthPriceInUSDC({
|
|
5720
|
+
reserve0,
|
|
5721
|
+
reserve1
|
|
5722
|
+
}) {
|
|
5723
|
+
return Number(reserve0 * BigInt(1e14) / reserve1) / 100;
|
|
5724
|
+
}
|
|
5725
|
+
async function getEthPriceInUSDC() {
|
|
5726
|
+
const reserves = await getUniswapV2USDCReserves();
|
|
5727
|
+
return toEthPriceInUSDC({ reserve0: reserves[0], reserve1: reserves[1] });
|
|
5728
|
+
}
|
|
5729
|
+
|
|
5730
|
+
// src/secondary/conversions.ts
|
|
5731
|
+
import { formatEther } from "viem";
|
|
5732
|
+
var WEI_PER_SPARK = 1000000000000n;
|
|
5733
|
+
function convertWeiToSparks(wei) {
|
|
5734
|
+
return BigInt(wei) / WEI_PER_SPARK;
|
|
5735
|
+
}
|
|
5736
|
+
function convertWeiToUSD({
|
|
5737
|
+
amount,
|
|
5738
|
+
ethPriceInUSD
|
|
5739
|
+
}) {
|
|
5740
|
+
const amountInEth = formatEther(amount);
|
|
5741
|
+
return parseFloat(amountInEth) * ethPriceInUSD;
|
|
5742
|
+
}
|
|
5743
|
+
|
|
5744
|
+
// src/secondary/uniswap/uniswapQuote.ts
|
|
5745
|
+
import { wethAddress as wethAddresses } from "@zoralabs/protocol-deployments";
|
|
5746
|
+
|
|
5747
|
+
// src/secondary/uniswap/uniswapQuoteExact.ts
|
|
5748
|
+
import {
|
|
5749
|
+
mainnet as mainnet3,
|
|
5750
|
+
sepolia as sepolia2,
|
|
5751
|
+
zora as zora2,
|
|
5752
|
+
zoraSepolia as zoraSepolia2,
|
|
5753
|
+
base as base2,
|
|
5754
|
+
baseSepolia as baseSepolia2,
|
|
5755
|
+
optimism as optimism2,
|
|
5756
|
+
arbitrum as arbitrum2,
|
|
5757
|
+
blast
|
|
5758
|
+
} from "viem/chains";
|
|
5759
|
+
var UniswapQuoterAddress = {
|
|
5760
|
+
[mainnet3.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
|
|
5761
|
+
[sepolia2.id]: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3",
|
|
5762
|
+
[zora2.id]: "0x11867e1b3348F3ce4FcC170BC5af3d23E07E64Df",
|
|
5763
|
+
[zoraSepolia2.id]: "0xC195976fEF0985886E37036E2DF62bF371E12Df0",
|
|
5764
|
+
[base2.id]: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",
|
|
5765
|
+
[baseSepolia2.id]: "0xC5290058841028F1614F3A6F0F5816cAd0df5E27",
|
|
5766
|
+
[optimism2.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
|
|
5767
|
+
[arbitrum2.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
|
|
5768
|
+
[blast.id]: "0x6Cdcd65e03c1CEc3730AeeCd45bc140D57A25C77"
|
|
5769
|
+
};
|
|
5770
|
+
async function quoteExactOutputSingle({
|
|
5771
|
+
tokenIn,
|
|
5772
|
+
tokenOut,
|
|
5773
|
+
amountOut,
|
|
5774
|
+
fee,
|
|
5775
|
+
chainId,
|
|
5776
|
+
client
|
|
5777
|
+
}) {
|
|
5778
|
+
const quote = await client.simulateContract({
|
|
5779
|
+
abi: uniswapQuoterABI,
|
|
5780
|
+
address: UniswapQuoterAddress[chainId],
|
|
5781
|
+
functionName: "quoteExactOutputSingle",
|
|
5782
|
+
args: [
|
|
5783
|
+
{
|
|
5784
|
+
tokenIn,
|
|
5785
|
+
tokenOut,
|
|
5786
|
+
amount: amountOut,
|
|
5787
|
+
fee,
|
|
5788
|
+
sqrtPriceLimitX96: 0n
|
|
5789
|
+
}
|
|
5790
|
+
]
|
|
5791
|
+
});
|
|
5792
|
+
return quote.result[0];
|
|
5793
|
+
}
|
|
5794
|
+
async function quoteExactInputSingle({
|
|
5795
|
+
tokenIn,
|
|
5796
|
+
tokenOut,
|
|
5797
|
+
amountIn,
|
|
5798
|
+
fee,
|
|
5799
|
+
chainId,
|
|
5800
|
+
client
|
|
5801
|
+
}) {
|
|
5802
|
+
const quote = await client.simulateContract({
|
|
5803
|
+
abi: uniswapQuoterABI,
|
|
5804
|
+
address: UniswapQuoterAddress[chainId],
|
|
5805
|
+
functionName: "quoteExactInputSingle",
|
|
5806
|
+
args: [
|
|
5807
|
+
{
|
|
5808
|
+
tokenIn,
|
|
5809
|
+
tokenOut,
|
|
5810
|
+
amountIn,
|
|
5811
|
+
fee,
|
|
5812
|
+
sqrtPriceLimitX96: 0n
|
|
5813
|
+
}
|
|
5814
|
+
]
|
|
5815
|
+
});
|
|
5816
|
+
return quote.result[0];
|
|
5817
|
+
}
|
|
5818
|
+
|
|
5819
|
+
// src/secondary/uniswap/uniswapQuote.ts
|
|
5820
|
+
async function getPoolInfo({
|
|
5821
|
+
poolAddress,
|
|
5822
|
+
client,
|
|
5823
|
+
WETH,
|
|
5824
|
+
erc20z
|
|
5825
|
+
}) {
|
|
5826
|
+
const [fee, wethBalance, erc20zBalance] = await client.multicall({
|
|
5827
|
+
contracts: [
|
|
5828
|
+
{
|
|
5829
|
+
abi: uniswapV3PoolAbi,
|
|
5830
|
+
address: poolAddress,
|
|
5831
|
+
functionName: "fee"
|
|
5832
|
+
},
|
|
5833
|
+
// get WETH and erc20z balance for pool
|
|
5834
|
+
{
|
|
5835
|
+
abi: erc20Abi,
|
|
5836
|
+
address: WETH,
|
|
5837
|
+
functionName: "balanceOf",
|
|
5838
|
+
args: [poolAddress]
|
|
5839
|
+
},
|
|
5840
|
+
{
|
|
5841
|
+
abi: erc20Abi,
|
|
5842
|
+
address: erc20z,
|
|
5843
|
+
functionName: "balanceOf",
|
|
5844
|
+
args: [poolAddress]
|
|
5845
|
+
}
|
|
5846
|
+
],
|
|
5847
|
+
multicallAddress: multicall3Address,
|
|
5848
|
+
allowFailure: false
|
|
5849
|
+
});
|
|
5850
|
+
return {
|
|
5851
|
+
wethBalance,
|
|
5852
|
+
erc20zBalance,
|
|
5853
|
+
fee
|
|
5854
|
+
};
|
|
5855
|
+
}
|
|
5856
|
+
async function getUniswapQuote(input, client) {
|
|
5857
|
+
const { type, quantity, poolAddress, chainId, erc20z } = input;
|
|
5858
|
+
const WETH = wethAddresses[chainId];
|
|
5859
|
+
const pool = await getPoolInfo({ poolAddress, WETH, erc20z, client });
|
|
5860
|
+
const { fee, wethBalance, erc20zBalance } = pool;
|
|
5861
|
+
const amountWithDecimals = input.quantity * 10n ** 18n;
|
|
5862
|
+
const amount = type === "buy" ? await quoteExactOutputSingle({
|
|
5863
|
+
tokenIn: WETH,
|
|
5864
|
+
tokenOut: erc20z,
|
|
5865
|
+
amountOut: amountWithDecimals,
|
|
5866
|
+
fee,
|
|
5867
|
+
chainId,
|
|
5868
|
+
client
|
|
5869
|
+
}) : await quoteExactInputSingle({
|
|
5870
|
+
tokenIn: erc20z,
|
|
5871
|
+
tokenOut: WETH,
|
|
5872
|
+
amountIn: amountWithDecimals,
|
|
5873
|
+
fee,
|
|
5874
|
+
chainId,
|
|
5875
|
+
client
|
|
5876
|
+
});
|
|
5877
|
+
const price = amount;
|
|
5878
|
+
const pricePerToken = amount / BigInt(quantity);
|
|
5879
|
+
const getUsdPrice = async () => {
|
|
5880
|
+
const ethPriceInUSD = await getEthPriceInUSDC();
|
|
5881
|
+
return {
|
|
5882
|
+
perToken: convertWeiToUSD({ amount: pricePerToken, ethPriceInUSD }),
|
|
5883
|
+
total: convertWeiToUSD({ amount: price, ethPriceInUSD })
|
|
5884
|
+
};
|
|
5885
|
+
};
|
|
5886
|
+
return {
|
|
5887
|
+
amount,
|
|
5888
|
+
poolBalance: {
|
|
5889
|
+
erc20z: erc20zBalance,
|
|
5890
|
+
weth: wethBalance
|
|
5891
|
+
},
|
|
5892
|
+
price: {
|
|
5893
|
+
wei: {
|
|
5894
|
+
perToken: pricePerToken,
|
|
5895
|
+
total: price
|
|
5896
|
+
},
|
|
5897
|
+
sparks: {
|
|
5898
|
+
perToken: convertWeiToSparks(pricePerToken),
|
|
5899
|
+
total: convertWeiToSparks(price)
|
|
5900
|
+
},
|
|
5901
|
+
usdc: getUsdPrice
|
|
5902
|
+
}
|
|
5903
|
+
};
|
|
5904
|
+
}
|
|
5905
|
+
|
|
5906
|
+
// src/secondary/slippage.ts
|
|
5907
|
+
var SCALE = 1e18;
|
|
5908
|
+
var ONE_SCALED = BigInt(SCALE);
|
|
5909
|
+
function calculateSlippageUp(amount, slippage) {
|
|
5910
|
+
return typeof amount === "bigint" ? amount * (ONE_SCALED + BigInt(slippage * SCALE)) / ONE_SCALED : parseFloat(String(amount)) * (1 + slippage);
|
|
5911
|
+
}
|
|
5912
|
+
function calculateSlippageDown(amount, slippage) {
|
|
5913
|
+
return typeof amount === "bigint" ? amount * (ONE_SCALED - BigInt(slippage * SCALE)) / ONE_SCALED : parseFloat(String(amount)) * (1 - slippage);
|
|
5914
|
+
}
|
|
5915
|
+
|
|
5916
|
+
// src/secondary/utils.ts
|
|
5917
|
+
import {
|
|
5918
|
+
zoraTimedSaleStrategyABI as zoraTimedSaleStrategyABI3,
|
|
5919
|
+
zoraTimedSaleStrategyAddress as zoraTimedSaleStrategyAddress2
|
|
5920
|
+
} from "@zoralabs/protocol-deployments";
|
|
5921
|
+
async function getSecondaryInfo({
|
|
5922
|
+
contract,
|
|
5923
|
+
tokenId,
|
|
5924
|
+
publicClient,
|
|
5925
|
+
chainId
|
|
5926
|
+
}) {
|
|
5927
|
+
const result = await publicClient.readContract({
|
|
5928
|
+
abi: zoraTimedSaleStrategyABI3,
|
|
5929
|
+
address: zoraTimedSaleStrategyAddress2[chainId],
|
|
5930
|
+
functionName: "sale",
|
|
5931
|
+
args: [contract, tokenId]
|
|
5932
|
+
});
|
|
5933
|
+
if (!result.erc20zAddress) {
|
|
5934
|
+
return void 0;
|
|
5935
|
+
}
|
|
5936
|
+
return {
|
|
5937
|
+
erc20z: result.erc20zAddress,
|
|
5938
|
+
pool: result.poolAddress,
|
|
5939
|
+
secondaryActivated: result.secondaryActivated,
|
|
5940
|
+
saleEnd: result.saleEnd === 0n ? void 0 : result.saleEnd
|
|
5941
|
+
};
|
|
5942
|
+
}
|
|
5943
|
+
|
|
5944
|
+
// src/secondary/secondary-client.ts
|
|
5945
|
+
var UNISWAP_SLIPPAGE = 5e-3;
|
|
5946
|
+
var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
|
|
5947
|
+
var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
|
|
5948
|
+
var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
|
|
5949
|
+
var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
|
|
5950
|
+
function makeError(errorMessage) {
|
|
5951
|
+
return { error: errorMessage };
|
|
5952
|
+
}
|
|
5953
|
+
async function makeBuy({
|
|
5954
|
+
erc20z,
|
|
5955
|
+
poolBalance,
|
|
5956
|
+
amount,
|
|
5957
|
+
quantity,
|
|
5958
|
+
account,
|
|
5959
|
+
recipient,
|
|
5960
|
+
chainId,
|
|
5961
|
+
slippage,
|
|
5962
|
+
publicClient
|
|
5963
|
+
}) {
|
|
5964
|
+
const costWithSlippage = calculateSlippageUp(amount, slippage);
|
|
5965
|
+
const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
|
|
5966
|
+
const accountAddress = addressOrAccountAddress(account);
|
|
5967
|
+
const availableToSpend = await publicClient.getBalance({
|
|
5968
|
+
address: accountAddress
|
|
5969
|
+
});
|
|
5970
|
+
if (costWithSlippage > availableToSpend) {
|
|
5971
|
+
return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
|
|
5972
|
+
}
|
|
5973
|
+
if (availableToBuy < BigInt(quantity)) {
|
|
5974
|
+
return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
|
|
5975
|
+
}
|
|
5976
|
+
return {
|
|
5977
|
+
parameters: makeContractParameters({
|
|
5978
|
+
abi: secondarySwapABI,
|
|
5979
|
+
address: secondarySwapAddress[chainId],
|
|
5980
|
+
functionName: "buy1155",
|
|
5981
|
+
args: [
|
|
5982
|
+
erc20z,
|
|
5983
|
+
quantity,
|
|
5984
|
+
recipient || accountAddress,
|
|
5985
|
+
accountAddress,
|
|
5986
|
+
costWithSlippage,
|
|
5987
|
+
0n
|
|
5988
|
+
],
|
|
5989
|
+
account,
|
|
5990
|
+
value: costWithSlippage
|
|
5991
|
+
})
|
|
5992
|
+
};
|
|
5993
|
+
}
|
|
5994
|
+
async function buyWithSlippage({
|
|
5995
|
+
contract,
|
|
5996
|
+
tokenId,
|
|
5997
|
+
publicClient,
|
|
5998
|
+
quantity,
|
|
5999
|
+
chainId,
|
|
6000
|
+
account,
|
|
6001
|
+
slippage = UNISWAP_SLIPPAGE,
|
|
6002
|
+
recipient
|
|
6003
|
+
}) {
|
|
6004
|
+
const secondaryInfo = await getSecondaryInfo({
|
|
6005
|
+
contract,
|
|
6006
|
+
tokenId,
|
|
6007
|
+
publicClient,
|
|
6008
|
+
chainId
|
|
6009
|
+
});
|
|
6010
|
+
if (!secondaryInfo) {
|
|
6011
|
+
return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
|
|
6012
|
+
}
|
|
6013
|
+
const { erc20z, pool, secondaryActivated } = secondaryInfo;
|
|
6014
|
+
if (!secondaryActivated) {
|
|
6015
|
+
return makeError(ERROR_SECONDARY_NOT_STARTED);
|
|
6016
|
+
}
|
|
6017
|
+
const { poolBalance, amount, price } = await getUniswapQuote(
|
|
6018
|
+
{
|
|
6019
|
+
type: "buy",
|
|
6020
|
+
quantity,
|
|
6021
|
+
poolAddress: pool,
|
|
6022
|
+
erc20z,
|
|
6023
|
+
chainId
|
|
6024
|
+
},
|
|
6025
|
+
publicClient
|
|
6026
|
+
);
|
|
6027
|
+
const call = await makeBuy({
|
|
6028
|
+
erc20z,
|
|
6029
|
+
poolBalance,
|
|
6030
|
+
amount,
|
|
6031
|
+
quantity,
|
|
6032
|
+
account,
|
|
6033
|
+
recipient,
|
|
6034
|
+
chainId,
|
|
6035
|
+
slippage,
|
|
6036
|
+
publicClient
|
|
6037
|
+
});
|
|
6038
|
+
return {
|
|
6039
|
+
...call,
|
|
6040
|
+
price
|
|
6041
|
+
};
|
|
6042
|
+
}
|
|
6043
|
+
async function makeSell({
|
|
6044
|
+
contract,
|
|
6045
|
+
tokenId,
|
|
6046
|
+
poolBalance,
|
|
6047
|
+
amount,
|
|
6048
|
+
quantity,
|
|
6049
|
+
account,
|
|
6050
|
+
recipient,
|
|
6051
|
+
chainId,
|
|
6052
|
+
slippage,
|
|
6053
|
+
publicClient
|
|
6054
|
+
}) {
|
|
6055
|
+
const accountAddress = addressOrAccountAddress(account);
|
|
6056
|
+
const tokenCount = await publicClient.readContract({
|
|
6057
|
+
abi: zoraCreator1155ImplABI7,
|
|
6058
|
+
address: contract,
|
|
6059
|
+
functionName: "balanceOf",
|
|
6060
|
+
args: [accountAddress, tokenId]
|
|
6061
|
+
});
|
|
6062
|
+
const availableToSell = tokenCount ?? 0n;
|
|
6063
|
+
const availableToReceive = poolBalance.weth;
|
|
6064
|
+
if (quantity > availableToSell) {
|
|
6065
|
+
return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
|
|
6066
|
+
}
|
|
6067
|
+
if (amount > availableToReceive) {
|
|
6068
|
+
return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
|
|
6069
|
+
}
|
|
6070
|
+
const receivedWithSlippage = calculateSlippageDown(amount, slippage);
|
|
6071
|
+
const data = encodeAbiParameters2(safeTransferSwapAbiParameters, [
|
|
6072
|
+
recipient || accountAddress,
|
|
6073
|
+
receivedWithSlippage,
|
|
6074
|
+
0n
|
|
6075
|
+
]);
|
|
6076
|
+
return {
|
|
6077
|
+
parameters: makeContractParameters({
|
|
6078
|
+
abi: zoraCreator1155ImplABI7,
|
|
6079
|
+
address: contract,
|
|
6080
|
+
functionName: "safeTransferFrom",
|
|
6081
|
+
account,
|
|
6082
|
+
args: [
|
|
6083
|
+
accountAddress,
|
|
6084
|
+
secondarySwapAddress[chainId],
|
|
6085
|
+
tokenId,
|
|
6086
|
+
quantity,
|
|
6087
|
+
data
|
|
6088
|
+
]
|
|
6089
|
+
})
|
|
6090
|
+
};
|
|
6091
|
+
}
|
|
6092
|
+
async function sellWithSlippage({
|
|
6093
|
+
contract,
|
|
6094
|
+
tokenId,
|
|
6095
|
+
publicClient,
|
|
6096
|
+
quantity,
|
|
6097
|
+
chainId,
|
|
6098
|
+
account,
|
|
6099
|
+
slippage = UNISWAP_SLIPPAGE,
|
|
6100
|
+
recipient
|
|
6101
|
+
}) {
|
|
6102
|
+
const secondaryInfo = await getSecondaryInfo({
|
|
6103
|
+
contract,
|
|
6104
|
+
tokenId,
|
|
6105
|
+
publicClient,
|
|
6106
|
+
chainId
|
|
6107
|
+
});
|
|
6108
|
+
if (!secondaryInfo) {
|
|
6109
|
+
return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
|
|
6110
|
+
}
|
|
6111
|
+
const { pool, secondaryActivated, erc20z } = secondaryInfo;
|
|
6112
|
+
if (!secondaryActivated) {
|
|
6113
|
+
return makeError(ERROR_SECONDARY_NOT_STARTED);
|
|
6114
|
+
}
|
|
6115
|
+
const { poolBalance, amount, price } = await getUniswapQuote(
|
|
6116
|
+
{ type: "sell", quantity, poolAddress: pool, chainId, erc20z },
|
|
6117
|
+
publicClient
|
|
6118
|
+
);
|
|
6119
|
+
const call = await makeSell({
|
|
6120
|
+
contract,
|
|
6121
|
+
tokenId,
|
|
6122
|
+
poolBalance,
|
|
6123
|
+
amount,
|
|
6124
|
+
quantity,
|
|
6125
|
+
account,
|
|
6126
|
+
recipient,
|
|
6127
|
+
chainId,
|
|
6128
|
+
slippage,
|
|
6129
|
+
publicClient
|
|
6130
|
+
});
|
|
6131
|
+
return {
|
|
6132
|
+
...call,
|
|
6133
|
+
price
|
|
6134
|
+
};
|
|
6135
|
+
}
|
|
6136
|
+
var SecondaryClient = class {
|
|
6137
|
+
/**
|
|
6138
|
+
* Creates a new SecondaryClient instance.
|
|
6139
|
+
* @param publicClient - The public client for interacting with the blockchain.
|
|
6140
|
+
* @param chainId - The ID of the blockchain network.
|
|
6141
|
+
*/
|
|
6142
|
+
constructor({
|
|
6143
|
+
publicClient,
|
|
6144
|
+
chainId
|
|
6145
|
+
}) {
|
|
6146
|
+
this.publicClient = publicClient;
|
|
6147
|
+
this.chainId = chainId;
|
|
6148
|
+
}
|
|
6149
|
+
/**
|
|
6150
|
+
* Get the secondary info for a given contract and token ID.
|
|
6151
|
+
* @param contract - The address of the contract.
|
|
6152
|
+
* @param tokenId - The ID of the token.
|
|
6153
|
+
* @returns A promise that resolves to the secondary info.
|
|
6154
|
+
*/
|
|
6155
|
+
async getSecondaryInfo({
|
|
6156
|
+
contract,
|
|
6157
|
+
tokenId
|
|
6158
|
+
}) {
|
|
6159
|
+
return getSecondaryInfo({
|
|
6160
|
+
contract,
|
|
6161
|
+
tokenId,
|
|
6162
|
+
publicClient: this.publicClient,
|
|
6163
|
+
chainId: this.chainId
|
|
6164
|
+
});
|
|
6165
|
+
}
|
|
6166
|
+
/**
|
|
6167
|
+
* Prepares a buy operation with slippage protection for purchasing a quantity of ERC1155 tokens with ETH on the secondary market.
|
|
6168
|
+
* @param input - The input parameters for the buy operation.
|
|
6169
|
+
* @returns A promise that resolves to the result of the buy operation, including price breakdown and transaction parameters.
|
|
6170
|
+
*/
|
|
6171
|
+
async buy1155OnSecondary(input) {
|
|
6172
|
+
return buyWithSlippage({
|
|
6173
|
+
...input,
|
|
6174
|
+
publicClient: this.publicClient,
|
|
6175
|
+
chainId: this.chainId
|
|
6176
|
+
});
|
|
6177
|
+
}
|
|
6178
|
+
/**
|
|
6179
|
+
* Prepares a sell operation with slippage protection for selling a quantity of ERC1155 tokens for ETH on the secondary market.
|
|
6180
|
+
* @param input - The input parameters for the sell operation.
|
|
6181
|
+
* @returns A promise that resolves to the result of the sell operation, including price breakdown and transaction parameters.
|
|
6182
|
+
*/
|
|
6183
|
+
async sell1155OnSecondary(input) {
|
|
6184
|
+
return sellWithSlippage({
|
|
6185
|
+
...input,
|
|
6186
|
+
publicClient: this.publicClient,
|
|
6187
|
+
chainId: this.chainId
|
|
6188
|
+
});
|
|
6189
|
+
}
|
|
6190
|
+
};
|
|
6191
|
+
|
|
5431
6192
|
// src/sdk.ts
|
|
5432
6193
|
function createCreatorClient(clientConfig) {
|
|
5433
6194
|
const premintClient = new PremintClient({
|
|
@@ -5440,12 +6201,19 @@ function createCreatorClient(clientConfig) {
|
|
|
5440
6201
|
publicClient: clientConfig.publicClient,
|
|
5441
6202
|
contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
|
|
5442
6203
|
});
|
|
6204
|
+
const rewardsClient = new RewardsClient({
|
|
6205
|
+
chainId: clientConfig.chainId,
|
|
6206
|
+
publicClient: clientConfig.publicClient,
|
|
6207
|
+
rewardsGetter: clientConfig.rewardsGetter || new SubgraphRewardsGetter(clientConfig.chainId)
|
|
6208
|
+
});
|
|
5443
6209
|
return {
|
|
5444
6210
|
createPremint: (p) => premintClient.createPremint(p),
|
|
5445
6211
|
updatePremint: (p) => premintClient.updatePremint(p),
|
|
5446
6212
|
deletePremint: (p) => premintClient.deletePremint(p),
|
|
5447
6213
|
create1155: (p) => create1155CreatorClient.createNew1155(p),
|
|
5448
|
-
create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
|
|
6214
|
+
create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p),
|
|
6215
|
+
getRewardsBalances: (p) => rewardsClient.getRewardsBalances(p),
|
|
6216
|
+
withdrawRewards: (p) => rewardsClient.withdrawRewards(p)
|
|
5449
6217
|
};
|
|
5450
6218
|
}
|
|
5451
6219
|
function createCollectorClient(params) {
|
|
@@ -5456,6 +6224,10 @@ function createCollectorClient(params) {
|
|
|
5456
6224
|
premintGetter: premintGetterToUse,
|
|
5457
6225
|
mintGetter: mintGetterToUse
|
|
5458
6226
|
});
|
|
6227
|
+
const secondaryClient = new SecondaryClient({
|
|
6228
|
+
publicClient: params.publicClient,
|
|
6229
|
+
chainId: params.chainId
|
|
6230
|
+
});
|
|
5459
6231
|
return {
|
|
5460
6232
|
getPremint: (p) => premintGetterToUse.get({
|
|
5461
6233
|
collectionAddress: p.address,
|
|
@@ -5465,7 +6237,10 @@ function createCollectorClient(params) {
|
|
|
5465
6237
|
getToken: (p) => mintClient.get(p),
|
|
5466
6238
|
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
5467
6239
|
mint: (p) => mintClient.mint(p),
|
|
5468
|
-
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
6240
|
+
getMintCosts: (p) => mintClient.getMintCosts(p),
|
|
6241
|
+
buy1155OnSecondary: (p) => secondaryClient.buy1155OnSecondary(p),
|
|
6242
|
+
sell1155OnSecondary: (p) => secondaryClient.sell1155OnSecondary(p),
|
|
6243
|
+
getSecondaryInfo: (p) => secondaryClient.getSecondaryInfo(p)
|
|
5469
6244
|
};
|
|
5470
6245
|
}
|
|
5471
6246
|
|
|
@@ -5501,7 +6276,7 @@ function coerce3(o) {
|
|
|
5501
6276
|
}
|
|
5502
6277
|
|
|
5503
6278
|
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
5504
|
-
function
|
|
6279
|
+
function base3(ALPHABET, name) {
|
|
5505
6280
|
if (ALPHABET.length >= 255) {
|
|
5506
6281
|
throw new TypeError("Alphabet too long");
|
|
5507
6282
|
}
|
|
@@ -5632,7 +6407,7 @@ function base2(ALPHABET, name) {
|
|
|
5632
6407
|
decode: decode5
|
|
5633
6408
|
};
|
|
5634
6409
|
}
|
|
5635
|
-
var src =
|
|
6410
|
+
var src = base3;
|
|
5636
6411
|
var _brrp__multiformats_scope_baseX = src;
|
|
5637
6412
|
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
5638
6413
|
|
|
@@ -5993,13 +6768,13 @@ var Digest = class {
|
|
|
5993
6768
|
};
|
|
5994
6769
|
|
|
5995
6770
|
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
|
|
5996
|
-
function format(link,
|
|
6771
|
+
function format(link, base4) {
|
|
5997
6772
|
const { bytes, version } = link;
|
|
5998
6773
|
switch (version) {
|
|
5999
6774
|
case 0:
|
|
6000
|
-
return toStringV0(bytes, baseCache(link),
|
|
6775
|
+
return toStringV0(bytes, baseCache(link), base4 ?? base58btc.encoder);
|
|
6001
6776
|
default:
|
|
6002
|
-
return toStringV1(bytes, baseCache(link),
|
|
6777
|
+
return toStringV1(bytes, baseCache(link), base4 ?? base32.encoder);
|
|
6003
6778
|
}
|
|
6004
6779
|
}
|
|
6005
6780
|
var cache = /* @__PURE__ */ new WeakMap();
|
|
@@ -6091,8 +6866,8 @@ var CID = class _CID {
|
|
|
6091
6866
|
const unknown = other;
|
|
6092
6867
|
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
6093
6868
|
}
|
|
6094
|
-
toString(
|
|
6095
|
-
return format(this,
|
|
6869
|
+
toString(base4) {
|
|
6870
|
+
return format(this, base4);
|
|
6096
6871
|
}
|
|
6097
6872
|
toJSON() {
|
|
6098
6873
|
return { "/": format(this) };
|
|
@@ -6251,8 +7026,8 @@ var CID = class _CID {
|
|
|
6251
7026
|
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
6252
7027
|
* a default decoder).
|
|
6253
7028
|
*/
|
|
6254
|
-
static parse(source,
|
|
6255
|
-
const [prefix, bytes] = parseCIDtoBytes(source,
|
|
7029
|
+
static parse(source, base4) {
|
|
7030
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base4);
|
|
6256
7031
|
const cid = _CID.decode(bytes);
|
|
6257
7032
|
if (cid.version === 0 && source[0] !== "Q") {
|
|
6258
7033
|
throw Error("Version 0 CID string must not include multibase prefix");
|
|
@@ -6261,50 +7036,50 @@ var CID = class _CID {
|
|
|
6261
7036
|
return cid;
|
|
6262
7037
|
}
|
|
6263
7038
|
};
|
|
6264
|
-
function parseCIDtoBytes(source,
|
|
7039
|
+
function parseCIDtoBytes(source, base4) {
|
|
6265
7040
|
switch (source[0]) {
|
|
6266
7041
|
case "Q": {
|
|
6267
|
-
const decoder =
|
|
7042
|
+
const decoder = base4 ?? base58btc;
|
|
6268
7043
|
return [
|
|
6269
7044
|
base58btc.prefix,
|
|
6270
7045
|
decoder.decode(`${base58btc.prefix}${source}`)
|
|
6271
7046
|
];
|
|
6272
7047
|
}
|
|
6273
7048
|
case base58btc.prefix: {
|
|
6274
|
-
const decoder =
|
|
7049
|
+
const decoder = base4 ?? base58btc;
|
|
6275
7050
|
return [base58btc.prefix, decoder.decode(source)];
|
|
6276
7051
|
}
|
|
6277
7052
|
case base32.prefix: {
|
|
6278
|
-
const decoder =
|
|
7053
|
+
const decoder = base4 ?? base32;
|
|
6279
7054
|
return [base32.prefix, decoder.decode(source)];
|
|
6280
7055
|
}
|
|
6281
7056
|
default: {
|
|
6282
|
-
if (
|
|
7057
|
+
if (base4 == null) {
|
|
6283
7058
|
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
6284
7059
|
}
|
|
6285
|
-
return [source[0],
|
|
7060
|
+
return [source[0], base4.decode(source)];
|
|
6286
7061
|
}
|
|
6287
7062
|
}
|
|
6288
7063
|
}
|
|
6289
|
-
function toStringV0(bytes, cache2,
|
|
6290
|
-
const { prefix } =
|
|
7064
|
+
function toStringV0(bytes, cache2, base4) {
|
|
7065
|
+
const { prefix } = base4;
|
|
6291
7066
|
if (prefix !== base58btc.prefix) {
|
|
6292
|
-
throw Error(`Cannot string encode V0 in ${
|
|
7067
|
+
throw Error(`Cannot string encode V0 in ${base4.name} encoding`);
|
|
6293
7068
|
}
|
|
6294
7069
|
const cid = cache2.get(prefix);
|
|
6295
7070
|
if (cid == null) {
|
|
6296
|
-
const cid2 =
|
|
7071
|
+
const cid2 = base4.encode(bytes).slice(1);
|
|
6297
7072
|
cache2.set(prefix, cid2);
|
|
6298
7073
|
return cid2;
|
|
6299
7074
|
} else {
|
|
6300
7075
|
return cid;
|
|
6301
7076
|
}
|
|
6302
7077
|
}
|
|
6303
|
-
function toStringV1(bytes, cache2,
|
|
6304
|
-
const { prefix } =
|
|
7078
|
+
function toStringV1(bytes, cache2, base4) {
|
|
7079
|
+
const { prefix } = base4;
|
|
6305
7080
|
const cid = cache2.get(prefix);
|
|
6306
7081
|
if (cid == null) {
|
|
6307
|
-
const cid2 =
|
|
7082
|
+
const cid2 = base4.encode(bytes);
|
|
6308
7083
|
cache2.set(prefix, cid2);
|
|
6309
7084
|
return cid2;
|
|
6310
7085
|
} else {
|