@net-protocol/score 0.1.1 → 0.1.3
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/dist/index.d.mts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +42 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -24
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs.map +1 -1
- package/dist/{scoreKeyUtils-Dn43l8hQ.d.mts → scoreKeyUtils-DgHOtf44.d.mts} +1 -1
- package/dist/{scoreKeyUtils-Dn43l8hQ.d.ts → scoreKeyUtils-DgHOtf44.d.ts} +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1973,7 +1973,19 @@ var MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER = {
|
|
|
1973
1973
|
address: "0x7A9EF0AC6F6a254cd570B05D62D094D3aa5067f1",
|
|
1974
1974
|
abi: multi_version_uniswap_pool_info_retriever_default
|
|
1975
1975
|
};
|
|
1976
|
-
var
|
|
1976
|
+
var WETH_BY_CHAIN = {
|
|
1977
|
+
8453: "0x4200000000000000000000000000000000000006",
|
|
1978
|
+
// Base (L2 predeploy)
|
|
1979
|
+
1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
1980
|
+
// Ethereum mainnet
|
|
1981
|
+
};
|
|
1982
|
+
function getWethAddress(chainId) {
|
|
1983
|
+
const addr = WETH_BY_CHAIN[chainId];
|
|
1984
|
+
if (!addr) {
|
|
1985
|
+
throw new Error(`Score: No WETH address for chain ${chainId}`);
|
|
1986
|
+
}
|
|
1987
|
+
return addr;
|
|
1988
|
+
}
|
|
1977
1989
|
var NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1978
1990
|
var UPVOTE_PRICE_ETH = 25e-6;
|
|
1979
1991
|
var encodeUpvoteKey = (tokenAddress) => {
|
|
@@ -2415,10 +2427,10 @@ var V4_HOOKS = [
|
|
|
2415
2427
|
];
|
|
2416
2428
|
var LIQUIDITY_THRESHOLD_TO_PREFER_V2_V3_POOLS = 0.1 * 1e18;
|
|
2417
2429
|
var LIQUIDITY_THRESHOLD_TO_CONSIDER_V2_V3_POOLS = 0.01 * 1e18;
|
|
2418
|
-
function normalizeTokenPairs(pairs) {
|
|
2430
|
+
function normalizeTokenPairs(pairs, wethAddress) {
|
|
2419
2431
|
return pairs.map((pair) => {
|
|
2420
2432
|
const tokenA = pair.tokenAddress;
|
|
2421
|
-
const tokenB = pair.baseTokenAddress ||
|
|
2433
|
+
const tokenB = pair.baseTokenAddress || wethAddress;
|
|
2422
2434
|
return {
|
|
2423
2435
|
originalPair: pair,
|
|
2424
2436
|
tokenA: tokenA.toLowerCase() < tokenB.toLowerCase() ? tokenA : tokenB,
|
|
@@ -2435,7 +2447,7 @@ function buildDiscoveryArgs(normalizedPairs) {
|
|
|
2435
2447
|
v4Hooks: V4_HOOKS
|
|
2436
2448
|
};
|
|
2437
2449
|
}
|
|
2438
|
-
function parsePoolDiscoveries(poolResults, pairs) {
|
|
2450
|
+
function parsePoolDiscoveries(poolResults, pairs, wethAddress) {
|
|
2439
2451
|
if (!poolResults) {
|
|
2440
2452
|
return {
|
|
2441
2453
|
v2PoolAddresses: [],
|
|
@@ -2472,7 +2484,7 @@ function parsePoolDiscoveries(poolResults, pairs) {
|
|
|
2472
2484
|
v2PoolAddresses.push(poolAddressValue);
|
|
2473
2485
|
v2PoolAddressToPair[poolAddress] = {
|
|
2474
2486
|
tokenAddress: pair.tokenAddress,
|
|
2475
|
-
baseTokenAddress: pair.baseTokenAddress ||
|
|
2487
|
+
baseTokenAddress: pair.baseTokenAddress || wethAddress,
|
|
2476
2488
|
fee: feeNum
|
|
2477
2489
|
};
|
|
2478
2490
|
}
|
|
@@ -2483,7 +2495,7 @@ function parsePoolDiscoveries(poolResults, pairs) {
|
|
|
2483
2495
|
v3PoolAddresses.push(poolAddressValue);
|
|
2484
2496
|
v3PoolAddressToPair[poolAddress] = {
|
|
2485
2497
|
tokenAddress: pair.tokenAddress,
|
|
2486
|
-
baseTokenAddress: pair.baseTokenAddress ||
|
|
2498
|
+
baseTokenAddress: pair.baseTokenAddress || wethAddress,
|
|
2487
2499
|
fee: feeNum
|
|
2488
2500
|
};
|
|
2489
2501
|
}
|
|
@@ -2494,7 +2506,7 @@ function parsePoolDiscoveries(poolResults, pairs) {
|
|
|
2494
2506
|
v4PoolKeys.push(poolKey);
|
|
2495
2507
|
v4PoolKeyToPair[poolKeyString] = {
|
|
2496
2508
|
tokenAddress: pair.tokenAddress,
|
|
2497
|
-
baseTokenAddress: pair.baseTokenAddress ||
|
|
2509
|
+
baseTokenAddress: pair.baseTokenAddress || wethAddress,
|
|
2498
2510
|
fee: feeNum
|
|
2499
2511
|
};
|
|
2500
2512
|
}
|
|
@@ -2621,19 +2633,19 @@ function constructPoolKey(info, pair, version, v4PoolKey) {
|
|
|
2621
2633
|
return void 0;
|
|
2622
2634
|
}
|
|
2623
2635
|
}
|
|
2624
|
-
function getWethBalanceWei(pool) {
|
|
2625
|
-
if (pool.token0?.toLowerCase() ===
|
|
2636
|
+
function getWethBalanceWei(pool, wethAddress) {
|
|
2637
|
+
if (pool.token0?.toLowerCase() === wethAddress.toLowerCase()) {
|
|
2626
2638
|
return Number(pool.token0Balance);
|
|
2627
|
-
} else if (pool.token1?.toLowerCase() ===
|
|
2639
|
+
} else if (pool.token1?.toLowerCase() === wethAddress.toLowerCase()) {
|
|
2628
2640
|
return Number(pool.token1Balance);
|
|
2629
2641
|
} else {
|
|
2630
2642
|
return Number(pool.baseTokenBalance);
|
|
2631
2643
|
}
|
|
2632
2644
|
}
|
|
2633
|
-
function filterV2V3PoolsByLiquidity(pools, threshold) {
|
|
2645
|
+
function filterV2V3PoolsByLiquidity(pools, threshold, wethAddress) {
|
|
2634
2646
|
return pools.filter((pool) => {
|
|
2635
2647
|
if (!pool.poolAddress) return false;
|
|
2636
|
-
const wethBalanceWei = getWethBalanceWei(pool);
|
|
2648
|
+
const wethBalanceWei = getWethBalanceWei(pool, wethAddress);
|
|
2637
2649
|
return wethBalanceWei >= threshold;
|
|
2638
2650
|
});
|
|
2639
2651
|
}
|
|
@@ -2656,7 +2668,7 @@ function selectBestV2V3PoolByFee(pools) {
|
|
|
2656
2668
|
return a.fee < b.fee ? a : b;
|
|
2657
2669
|
});
|
|
2658
2670
|
}
|
|
2659
|
-
function selectBestPoolPerPair(allPools) {
|
|
2671
|
+
function selectBestPoolPerPair(allPools, wethAddress) {
|
|
2660
2672
|
const poolsByPair = {};
|
|
2661
2673
|
for (const pool of allPools) {
|
|
2662
2674
|
const key = pool.tokenAddress.toLowerCase() + "_" + pool.baseTokenAddress.toLowerCase();
|
|
@@ -2671,7 +2683,8 @@ function selectBestPoolPerPair(allPools) {
|
|
|
2671
2683
|
} else {
|
|
2672
2684
|
const v2v3PoolsWithPreferredLiquidity = filterV2V3PoolsByLiquidity(
|
|
2673
2685
|
group,
|
|
2674
|
-
LIQUIDITY_THRESHOLD_TO_PREFER_V2_V3_POOLS
|
|
2686
|
+
LIQUIDITY_THRESHOLD_TO_PREFER_V2_V3_POOLS,
|
|
2687
|
+
wethAddress
|
|
2675
2688
|
);
|
|
2676
2689
|
if (v2v3PoolsWithPreferredLiquidity.length > 0) {
|
|
2677
2690
|
best = selectBestV2V3Pool(v2v3PoolsWithPreferredLiquidity);
|
|
@@ -2682,7 +2695,8 @@ function selectBestPoolPerPair(allPools) {
|
|
|
2682
2695
|
} else {
|
|
2683
2696
|
const v2v3PoolsWithAcceptableLiquidity = filterV2V3PoolsByLiquidity(
|
|
2684
2697
|
group,
|
|
2685
|
-
LIQUIDITY_THRESHOLD_TO_CONSIDER_V2_V3_POOLS
|
|
2698
|
+
LIQUIDITY_THRESHOLD_TO_CONSIDER_V2_V3_POOLS,
|
|
2699
|
+
wethAddress
|
|
2686
2700
|
);
|
|
2687
2701
|
if (v2v3PoolsWithAcceptableLiquidity.length > 0) {
|
|
2688
2702
|
best = selectBestV2V3PoolByFee(v2v3PoolsWithAcceptableLiquidity);
|
|
@@ -2698,10 +2712,12 @@ function selectBestPoolPerPair(allPools) {
|
|
|
2698
2712
|
}
|
|
2699
2713
|
async function discoverPools({
|
|
2700
2714
|
publicClient,
|
|
2701
|
-
pairs
|
|
2715
|
+
pairs,
|
|
2716
|
+
chainId = 8453
|
|
2702
2717
|
}) {
|
|
2703
2718
|
if (pairs.length === 0) return [];
|
|
2704
|
-
const
|
|
2719
|
+
const wethAddress = getWethAddress(chainId);
|
|
2720
|
+
const normalizedPairs = normalizeTokenPairs(pairs, wethAddress);
|
|
2705
2721
|
const discoveryArgs = buildDiscoveryArgs(normalizedPairs);
|
|
2706
2722
|
const poolResults = await readContract(publicClient, {
|
|
2707
2723
|
address: MULTI_VERSION_UNISWAP_BULK_POOL_FINDER.address,
|
|
@@ -2709,7 +2725,7 @@ async function discoverPools({
|
|
|
2709
2725
|
functionName: "getPoolsMultiVersion",
|
|
2710
2726
|
args: [discoveryArgs]
|
|
2711
2727
|
});
|
|
2712
|
-
const discoveries = parsePoolDiscoveries(poolResults, pairs);
|
|
2728
|
+
const discoveries = parsePoolDiscoveries(poolResults, pairs, wethAddress);
|
|
2713
2729
|
const totalPools = discoveries.v2PoolAddresses.length + discoveries.v3PoolAddresses.length + discoveries.v4PoolKeys.length;
|
|
2714
2730
|
if (totalPools === 0) return [];
|
|
2715
2731
|
const poolInfos = await readContract(publicClient, {
|
|
@@ -2720,7 +2736,7 @@ async function discoverPools({
|
|
|
2720
2736
|
discoveries.v2PoolAddresses,
|
|
2721
2737
|
discoveries.v3PoolAddresses,
|
|
2722
2738
|
discoveries.v4PoolKeys,
|
|
2723
|
-
|
|
2739
|
+
wethAddress
|
|
2724
2740
|
]
|
|
2725
2741
|
});
|
|
2726
2742
|
if (!Array.isArray(poolInfos) || poolInfos.length === 0) return [];
|
|
@@ -2729,7 +2745,7 @@ async function discoverPools({
|
|
|
2729
2745
|
if (!poolData || !poolData.pair) return null;
|
|
2730
2746
|
return {
|
|
2731
2747
|
tokenAddress: poolData.pair.tokenAddress,
|
|
2732
|
-
baseTokenAddress: poolData.pair.baseTokenAddress ||
|
|
2748
|
+
baseTokenAddress: poolData.pair.baseTokenAddress || wethAddress,
|
|
2733
2749
|
poolAddress: poolData.version === 4 ? null : info.poolAddress,
|
|
2734
2750
|
price: calculatePoolPrice(info, poolData.pair, poolData.version),
|
|
2735
2751
|
baseTokenBalance: String(info.baseTokenBalance || 0),
|
|
@@ -2746,7 +2762,7 @@ async function discoverPools({
|
|
|
2746
2762
|
)
|
|
2747
2763
|
};
|
|
2748
2764
|
}).filter((p) => p !== null);
|
|
2749
|
-
const bestPools = selectBestPoolPerPair(allPools);
|
|
2765
|
+
const bestPools = selectBestPoolPerPair(allPools, wethAddress);
|
|
2750
2766
|
return bestPools.map(
|
|
2751
2767
|
(pool) => ({
|
|
2752
2768
|
tokenAddress: pool.tokenAddress,
|
|
@@ -2765,15 +2781,17 @@ async function discoverPools({
|
|
|
2765
2781
|
}
|
|
2766
2782
|
async function discoverTokenPool({
|
|
2767
2783
|
publicClient,
|
|
2768
|
-
tokenAddress
|
|
2784
|
+
tokenAddress,
|
|
2785
|
+
chainId = 8453
|
|
2769
2786
|
}) {
|
|
2770
2787
|
const results = await discoverPools({
|
|
2771
2788
|
publicClient,
|
|
2772
|
-
pairs: [{ tokenAddress }]
|
|
2789
|
+
pairs: [{ tokenAddress }],
|
|
2790
|
+
chainId
|
|
2773
2791
|
});
|
|
2774
2792
|
return results[0] ?? null;
|
|
2775
2793
|
}
|
|
2776
2794
|
|
|
2777
|
-
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, MULTI_VERSION_UNISWAP_BULK_POOL_FINDER, MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER, NULL_ADDRESS, PURE_ALPHA_STRATEGY, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP,
|
|
2795
|
+
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, MULTI_VERSION_UNISWAP_BULK_POOL_FINDER, MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER, NULL_ADDRESS, PURE_ALPHA_STRATEGY, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, calculatePriceFromSqrtPriceX96, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressFromScoreKey, getFeedContentKey, getScoreKey, getStorageScoreKey, getStorageUpvoteContext, getTokenScoreKey, getWethAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isTokenScoreKey, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };
|
|
2778
2796
|
//# sourceMappingURL=index.mjs.map
|
|
2779
2797
|
//# sourceMappingURL=index.mjs.map
|