@net-protocol/score 0.1.5 → 0.1.7
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +147 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -83
- 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-DuH70ypB.d.mts → scoreKeyUtils-D-ONTPej.d.mts} +2 -0
- package/dist/{scoreKeyUtils-DuH70ypB.d.ts → scoreKeyUtils-D-ONTPej.d.ts} +2 -0
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1805,7 +1805,59 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1805
1805
|
type: "function",
|
|
1806
1806
|
name: "V4_POOL_MANAGER",
|
|
1807
1807
|
inputs: [],
|
|
1808
|
-
outputs: [
|
|
1808
|
+
outputs: [
|
|
1809
|
+
{
|
|
1810
|
+
name: "",
|
|
1811
|
+
type: "address",
|
|
1812
|
+
internalType: "address"
|
|
1813
|
+
}
|
|
1814
|
+
],
|
|
1815
|
+
stateMutability: "view"
|
|
1816
|
+
},
|
|
1817
|
+
{
|
|
1818
|
+
type: "function",
|
|
1819
|
+
name: "_getV4Liquidity",
|
|
1820
|
+
inputs: [
|
|
1821
|
+
{
|
|
1822
|
+
name: "poolKey",
|
|
1823
|
+
type: "tuple",
|
|
1824
|
+
internalType: "struct PoolKey",
|
|
1825
|
+
components: [
|
|
1826
|
+
{
|
|
1827
|
+
name: "currency0",
|
|
1828
|
+
type: "address",
|
|
1829
|
+
internalType: "Currency"
|
|
1830
|
+
},
|
|
1831
|
+
{
|
|
1832
|
+
name: "currency1",
|
|
1833
|
+
type: "address",
|
|
1834
|
+
internalType: "Currency"
|
|
1835
|
+
},
|
|
1836
|
+
{
|
|
1837
|
+
name: "fee",
|
|
1838
|
+
type: "uint24",
|
|
1839
|
+
internalType: "uint24"
|
|
1840
|
+
},
|
|
1841
|
+
{
|
|
1842
|
+
name: "tickSpacing",
|
|
1843
|
+
type: "int24",
|
|
1844
|
+
internalType: "int24"
|
|
1845
|
+
},
|
|
1846
|
+
{
|
|
1847
|
+
name: "hooks",
|
|
1848
|
+
type: "address",
|
|
1849
|
+
internalType: "contract IHooks"
|
|
1850
|
+
}
|
|
1851
|
+
]
|
|
1852
|
+
}
|
|
1853
|
+
],
|
|
1854
|
+
outputs: [
|
|
1855
|
+
{
|
|
1856
|
+
name: "liquidity",
|
|
1857
|
+
type: "uint128",
|
|
1858
|
+
internalType: "uint128"
|
|
1859
|
+
}
|
|
1860
|
+
],
|
|
1809
1861
|
stateMutability: "view"
|
|
1810
1862
|
},
|
|
1811
1863
|
{
|
|
@@ -1827,8 +1879,16 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1827
1879
|
type: "address",
|
|
1828
1880
|
internalType: "Currency"
|
|
1829
1881
|
},
|
|
1830
|
-
{
|
|
1831
|
-
|
|
1882
|
+
{
|
|
1883
|
+
name: "fee",
|
|
1884
|
+
type: "uint24",
|
|
1885
|
+
internalType: "uint24"
|
|
1886
|
+
},
|
|
1887
|
+
{
|
|
1888
|
+
name: "tickSpacing",
|
|
1889
|
+
type: "int24",
|
|
1890
|
+
internalType: "int24"
|
|
1891
|
+
},
|
|
1832
1892
|
{
|
|
1833
1893
|
name: "hooks",
|
|
1834
1894
|
type: "address",
|
|
@@ -1838,7 +1898,11 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1838
1898
|
}
|
|
1839
1899
|
],
|
|
1840
1900
|
outputs: [
|
|
1841
|
-
{
|
|
1901
|
+
{
|
|
1902
|
+
name: "sqrtPriceX96",
|
|
1903
|
+
type: "uint160",
|
|
1904
|
+
internalType: "uint160"
|
|
1905
|
+
}
|
|
1842
1906
|
],
|
|
1843
1907
|
stateMutability: "view"
|
|
1844
1908
|
},
|
|
@@ -1871,8 +1935,16 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1871
1935
|
type: "address",
|
|
1872
1936
|
internalType: "Currency"
|
|
1873
1937
|
},
|
|
1874
|
-
{
|
|
1875
|
-
|
|
1938
|
+
{
|
|
1939
|
+
name: "fee",
|
|
1940
|
+
type: "uint24",
|
|
1941
|
+
internalType: "uint24"
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
name: "tickSpacing",
|
|
1945
|
+
type: "int24",
|
|
1946
|
+
internalType: "int24"
|
|
1947
|
+
},
|
|
1876
1948
|
{
|
|
1877
1949
|
name: "hooks",
|
|
1878
1950
|
type: "address",
|
|
@@ -1880,7 +1952,11 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1880
1952
|
}
|
|
1881
1953
|
]
|
|
1882
1954
|
},
|
|
1883
|
-
{
|
|
1955
|
+
{
|
|
1956
|
+
name: "baseToken",
|
|
1957
|
+
type: "address",
|
|
1958
|
+
internalType: "address"
|
|
1959
|
+
}
|
|
1884
1960
|
],
|
|
1885
1961
|
outputs: [
|
|
1886
1962
|
{
|
|
@@ -1893,8 +1969,16 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1893
1969
|
type: "address",
|
|
1894
1970
|
internalType: "address"
|
|
1895
1971
|
},
|
|
1896
|
-
{
|
|
1897
|
-
|
|
1972
|
+
{
|
|
1973
|
+
name: "token0",
|
|
1974
|
+
type: "address",
|
|
1975
|
+
internalType: "address"
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
name: "token1",
|
|
1979
|
+
type: "address",
|
|
1980
|
+
internalType: "address"
|
|
1981
|
+
},
|
|
1898
1982
|
{
|
|
1899
1983
|
name: "token0Decimals",
|
|
1900
1984
|
type: "uint8",
|
|
@@ -1924,6 +2008,11 @@ var multi_version_uniswap_pool_info_retriever_default = [
|
|
|
1924
2008
|
name: "token1Balance",
|
|
1925
2009
|
type: "uint256",
|
|
1926
2010
|
internalType: "uint256"
|
|
2011
|
+
},
|
|
2012
|
+
{
|
|
2013
|
+
name: "liquidity",
|
|
2014
|
+
type: "uint128",
|
|
2015
|
+
internalType: "uint128"
|
|
1927
2016
|
}
|
|
1928
2017
|
]
|
|
1929
2018
|
}
|
|
@@ -2431,7 +2520,7 @@ var MULTI_VERSION_UNISWAP_BULK_POOL_FINDER = {
|
|
|
2431
2520
|
abi: multi_version_uniswap_bulk_pool_finder_default
|
|
2432
2521
|
};
|
|
2433
2522
|
var MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER = {
|
|
2434
|
-
address: "
|
|
2523
|
+
address: "0x00000002986Ca76897216a8A3A7Db10FcB0d29Cf",
|
|
2435
2524
|
abi: multi_version_uniswap_pool_info_retriever_default
|
|
2436
2525
|
};
|
|
2437
2526
|
var WETH_BY_CHAIN = {
|
|
@@ -3162,10 +3251,27 @@ var V4_HOOKS = [
|
|
|
3162
3251
|
"0xb429d62f8f3bFFb98CdB9569533eA23bF0Ba28CC",
|
|
3163
3252
|
"0xd60D6B218116cFd801E28F78d011a203D2b068Cc",
|
|
3164
3253
|
"0x3e342a06f9592459D75721d6956B570F02eF2Dc0",
|
|
3165
|
-
"0xbB7784A4d481184283Ed89619A3e3ed143e1Adc0"
|
|
3254
|
+
"0xbB7784A4d481184283Ed89619A3e3ed143e1Adc0",
|
|
3255
|
+
"0xBDF938149ac6a781F94FAa0ed45E6A0e984c6544"
|
|
3166
3256
|
];
|
|
3167
|
-
var
|
|
3168
|
-
var
|
|
3257
|
+
var Q96 = BigInt(2) ** BigInt(96);
|
|
3258
|
+
var ZERO_BI = BigInt(0);
|
|
3259
|
+
function deriveV4WethDepthWei(liquidity, sqrtPriceX96, wethIsCurrency1) {
|
|
3260
|
+
if (sqrtPriceX96 === ZERO_BI || liquidity === ZERO_BI) return ZERO_BI;
|
|
3261
|
+
if (wethIsCurrency1) {
|
|
3262
|
+
return liquidity * sqrtPriceX96 / Q96;
|
|
3263
|
+
}
|
|
3264
|
+
return liquidity * Q96 / sqrtPriceX96;
|
|
3265
|
+
}
|
|
3266
|
+
function deriveV2V3WethDepthWei(info, wethLower) {
|
|
3267
|
+
if ((info.token0 ?? "").toLowerCase() === wethLower) {
|
|
3268
|
+
return BigInt(info.token0Balance ?? 0);
|
|
3269
|
+
}
|
|
3270
|
+
if ((info.token1 ?? "").toLowerCase() === wethLower) {
|
|
3271
|
+
return BigInt(info.token1Balance ?? 0);
|
|
3272
|
+
}
|
|
3273
|
+
return BigInt(info.baseTokenBalance ?? 0);
|
|
3274
|
+
}
|
|
3169
3275
|
function normalizeTokenPairs(pairs, wethAddress) {
|
|
3170
3276
|
return pairs.map((pair) => {
|
|
3171
3277
|
const tokenA = pair.tokenAddress;
|
|
@@ -3372,42 +3478,7 @@ function constructPoolKey(info, pair, version, v4PoolKey) {
|
|
|
3372
3478
|
return void 0;
|
|
3373
3479
|
}
|
|
3374
3480
|
}
|
|
3375
|
-
function
|
|
3376
|
-
if (pool.token0?.toLowerCase() === wethAddress.toLowerCase()) {
|
|
3377
|
-
return Number(pool.token0Balance);
|
|
3378
|
-
} else if (pool.token1?.toLowerCase() === wethAddress.toLowerCase()) {
|
|
3379
|
-
return Number(pool.token1Balance);
|
|
3380
|
-
} else {
|
|
3381
|
-
return Number(pool.baseTokenBalance);
|
|
3382
|
-
}
|
|
3383
|
-
}
|
|
3384
|
-
function filterV2V3PoolsByLiquidity(pools, threshold, wethAddress) {
|
|
3385
|
-
return pools.filter((pool) => {
|
|
3386
|
-
if (!pool.poolAddress) return false;
|
|
3387
|
-
const wethBalanceWei = getWethBalanceWei(pool, wethAddress);
|
|
3388
|
-
return wethBalanceWei >= threshold;
|
|
3389
|
-
});
|
|
3390
|
-
}
|
|
3391
|
-
function selectBestV2V3Pool(pools) {
|
|
3392
|
-
return pools.reduce((a, b) => {
|
|
3393
|
-
const aIsV3 = a.fee > 0;
|
|
3394
|
-
const bIsV3 = b.fee > 0;
|
|
3395
|
-
if (aIsV3 && !bIsV3) return a;
|
|
3396
|
-
if (!aIsV3 && bIsV3) return b;
|
|
3397
|
-
return Number(a.baseTokenBalance) > Number(b.baseTokenBalance) ? a : b;
|
|
3398
|
-
});
|
|
3399
|
-
}
|
|
3400
|
-
function selectBestV4Pool(pools) {
|
|
3401
|
-
return pools.reduce((a, b) => {
|
|
3402
|
-
return a.fee < b.fee ? a : b;
|
|
3403
|
-
});
|
|
3404
|
-
}
|
|
3405
|
-
function selectBestV2V3PoolByFee(pools) {
|
|
3406
|
-
return pools.reduce((a, b) => {
|
|
3407
|
-
return a.fee < b.fee ? a : b;
|
|
3408
|
-
});
|
|
3409
|
-
}
|
|
3410
|
-
function selectBestPoolPerPair(allPools, wethAddress) {
|
|
3481
|
+
function selectBestPoolPerPair(allPools) {
|
|
3411
3482
|
const poolsByPair = {};
|
|
3412
3483
|
for (const pool of allPools) {
|
|
3413
3484
|
const key = pool.tokenAddress.toLowerCase() + "_" + pool.baseTokenAddress.toLowerCase();
|
|
@@ -3415,37 +3486,13 @@ function selectBestPoolPerPair(allPools, wethAddress) {
|
|
|
3415
3486
|
poolsByPair[key].push(pool);
|
|
3416
3487
|
}
|
|
3417
3488
|
const bestPools = [];
|
|
3418
|
-
for (const
|
|
3419
|
-
|
|
3420
|
-
if (
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
LIQUIDITY_THRESHOLD_TO_PREFER_V2_V3_POOLS,
|
|
3426
|
-
wethAddress
|
|
3427
|
-
);
|
|
3428
|
-
if (v2v3PoolsWithPreferredLiquidity.length > 0) {
|
|
3429
|
-
best = selectBestV2V3Pool(v2v3PoolsWithPreferredLiquidity);
|
|
3430
|
-
} else {
|
|
3431
|
-
const v4Pools = group.filter((pool) => !pool.poolAddress);
|
|
3432
|
-
if (v4Pools.length > 0) {
|
|
3433
|
-
best = selectBestV4Pool(v4Pools);
|
|
3434
|
-
} else {
|
|
3435
|
-
const v2v3PoolsWithAcceptableLiquidity = filterV2V3PoolsByLiquidity(
|
|
3436
|
-
group,
|
|
3437
|
-
LIQUIDITY_THRESHOLD_TO_CONSIDER_V2_V3_POOLS,
|
|
3438
|
-
wethAddress
|
|
3439
|
-
);
|
|
3440
|
-
if (v2v3PoolsWithAcceptableLiquidity.length > 0) {
|
|
3441
|
-
best = selectBestV2V3PoolByFee(v2v3PoolsWithAcceptableLiquidity);
|
|
3442
|
-
}
|
|
3443
|
-
}
|
|
3444
|
-
}
|
|
3445
|
-
}
|
|
3446
|
-
if (best) {
|
|
3447
|
-
bestPools.push(best);
|
|
3448
|
-
}
|
|
3489
|
+
for (const group of Object.values(poolsByPair)) {
|
|
3490
|
+
const withDepth = group.filter((p) => p.wethDepthWei > ZERO_BI);
|
|
3491
|
+
if (withDepth.length === 0) continue;
|
|
3492
|
+
const best = withDepth.reduce(
|
|
3493
|
+
(a, b) => a.wethDepthWei > b.wethDepthWei ? a : b
|
|
3494
|
+
);
|
|
3495
|
+
bestPools.push(best);
|
|
3449
3496
|
}
|
|
3450
3497
|
return bestPools;
|
|
3451
3498
|
}
|
|
@@ -3479,13 +3526,27 @@ async function discoverPools({
|
|
|
3479
3526
|
]
|
|
3480
3527
|
});
|
|
3481
3528
|
if (!Array.isArray(poolInfos) || poolInfos.length === 0) return [];
|
|
3529
|
+
const wethLower = wethAddress.toLowerCase();
|
|
3482
3530
|
const allPools = poolInfos.map((info, index) => {
|
|
3483
3531
|
const poolData = determinePoolVersion(discoveries, index);
|
|
3484
3532
|
if (!poolData || !poolData.pair) return null;
|
|
3533
|
+
const isV4 = poolData.version === 4;
|
|
3534
|
+
const liquidity = BigInt(info.liquidity ?? 0);
|
|
3535
|
+
let wethDepthWei;
|
|
3536
|
+
if (isV4) {
|
|
3537
|
+
const wethIsCurrency1 = poolData.v4PoolKey.currency1.toLowerCase() === wethLower;
|
|
3538
|
+
wethDepthWei = deriveV4WethDepthWei(
|
|
3539
|
+
liquidity,
|
|
3540
|
+
BigInt(info.sqrtPriceX96 ?? 0),
|
|
3541
|
+
wethIsCurrency1
|
|
3542
|
+
);
|
|
3543
|
+
} else {
|
|
3544
|
+
wethDepthWei = deriveV2V3WethDepthWei(info, wethLower);
|
|
3545
|
+
}
|
|
3485
3546
|
return {
|
|
3486
3547
|
tokenAddress: poolData.pair.tokenAddress,
|
|
3487
3548
|
baseTokenAddress: poolData.pair.baseTokenAddress || wethAddress,
|
|
3488
|
-
poolAddress:
|
|
3549
|
+
poolAddress: isV4 ? null : info.poolAddress,
|
|
3489
3550
|
price: calculatePoolPrice(info, poolData.pair, poolData.version),
|
|
3490
3551
|
baseTokenBalance: String(info.baseTokenBalance || 0),
|
|
3491
3552
|
token0: info.token0,
|
|
@@ -3498,10 +3559,12 @@ async function discoverPools({
|
|
|
3498
3559
|
poolData.pair,
|
|
3499
3560
|
poolData.version,
|
|
3500
3561
|
poolData.v4PoolKey
|
|
3501
|
-
)
|
|
3562
|
+
),
|
|
3563
|
+
liquidity: String(liquidity),
|
|
3564
|
+
wethDepthWei
|
|
3502
3565
|
};
|
|
3503
3566
|
}).filter((p) => p !== null);
|
|
3504
|
-
const bestPools = selectBestPoolPerPair(allPools
|
|
3567
|
+
const bestPools = selectBestPoolPerPair(allPools);
|
|
3505
3568
|
return bestPools.map(
|
|
3506
3569
|
(pool) => ({
|
|
3507
3570
|
tokenAddress: pool.tokenAddress,
|
|
@@ -3510,6 +3573,7 @@ async function discoverPools({
|
|
|
3510
3573
|
price: pool.price,
|
|
3511
3574
|
fee: pool.fee,
|
|
3512
3575
|
poolKey: pool.poolKey,
|
|
3576
|
+
liquidity: pool.liquidity,
|
|
3513
3577
|
balances: {
|
|
3514
3578
|
baseTokenBalance: pool.baseTokenBalance,
|
|
3515
3579
|
token0Balance: pool.token0Balance,
|