@net-protocol/score 0.1.0 → 0.1.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/README.md +229 -0
- package/dist/index.d.mts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.js +667 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +660 -1
- 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-DIjbizO-.d.mts → scoreKeyUtils-Dn43l8hQ.d.mts} +14 -1
- package/dist/{scoreKeyUtils-DIjbizO-.d.ts → scoreKeyUtils-Dn43l8hQ.d.ts} +14 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1655,6 +1655,283 @@ var dynamic_split_strategy_default = [
|
|
|
1655
1655
|
}
|
|
1656
1656
|
];
|
|
1657
1657
|
|
|
1658
|
+
// src/abis/multi-version-uniswap-bulk-pool-finder.json
|
|
1659
|
+
var multi_version_uniswap_bulk_pool_finder_default = [
|
|
1660
|
+
{
|
|
1661
|
+
type: "function",
|
|
1662
|
+
name: "V2_FACTORY",
|
|
1663
|
+
inputs: [],
|
|
1664
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
1665
|
+
stateMutability: "view"
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
type: "function",
|
|
1669
|
+
name: "V3_FACTORY",
|
|
1670
|
+
inputs: [],
|
|
1671
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
1672
|
+
stateMutability: "view"
|
|
1673
|
+
},
|
|
1674
|
+
{
|
|
1675
|
+
type: "function",
|
|
1676
|
+
name: "V4_POOL_MANAGER",
|
|
1677
|
+
inputs: [],
|
|
1678
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
1679
|
+
stateMutability: "view"
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
type: "function",
|
|
1683
|
+
name: "_checkV4PoolExternal",
|
|
1684
|
+
inputs: [
|
|
1685
|
+
{
|
|
1686
|
+
name: "poolKey",
|
|
1687
|
+
type: "tuple",
|
|
1688
|
+
internalType: "struct PoolKey",
|
|
1689
|
+
components: [
|
|
1690
|
+
{
|
|
1691
|
+
name: "currency0",
|
|
1692
|
+
type: "address",
|
|
1693
|
+
internalType: "Currency"
|
|
1694
|
+
},
|
|
1695
|
+
{
|
|
1696
|
+
name: "currency1",
|
|
1697
|
+
type: "address",
|
|
1698
|
+
internalType: "Currency"
|
|
1699
|
+
},
|
|
1700
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
1701
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
1702
|
+
{
|
|
1703
|
+
name: "hooks",
|
|
1704
|
+
type: "address",
|
|
1705
|
+
internalType: "contract IHooks"
|
|
1706
|
+
}
|
|
1707
|
+
]
|
|
1708
|
+
}
|
|
1709
|
+
],
|
|
1710
|
+
outputs: [{ name: "exists", type: "bool", internalType: "bool" }],
|
|
1711
|
+
stateMutability: "view"
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
type: "function",
|
|
1715
|
+
name: "getPoolsMultiVersion",
|
|
1716
|
+
inputs: [
|
|
1717
|
+
{
|
|
1718
|
+
name: "params",
|
|
1719
|
+
type: "tuple",
|
|
1720
|
+
internalType: "struct MultiVersionUniswapBulkPoolFinder.PoolFinderParams",
|
|
1721
|
+
components: [
|
|
1722
|
+
{
|
|
1723
|
+
name: "tokenAs",
|
|
1724
|
+
type: "address[]",
|
|
1725
|
+
internalType: "address[]"
|
|
1726
|
+
},
|
|
1727
|
+
{
|
|
1728
|
+
name: "tokenBs",
|
|
1729
|
+
type: "address[]",
|
|
1730
|
+
internalType: "address[]"
|
|
1731
|
+
},
|
|
1732
|
+
{ name: "fees", type: "uint24[]", internalType: "uint24[]" },
|
|
1733
|
+
{
|
|
1734
|
+
name: "v4TickSpacings",
|
|
1735
|
+
type: "int24[]",
|
|
1736
|
+
internalType: "int24[]"
|
|
1737
|
+
},
|
|
1738
|
+
{
|
|
1739
|
+
name: "v4Hooks",
|
|
1740
|
+
type: "address[]",
|
|
1741
|
+
internalType: "address[]"
|
|
1742
|
+
}
|
|
1743
|
+
]
|
|
1744
|
+
}
|
|
1745
|
+
],
|
|
1746
|
+
outputs: [
|
|
1747
|
+
{
|
|
1748
|
+
name: "pools",
|
|
1749
|
+
type: "tuple[]",
|
|
1750
|
+
internalType: "struct MultiVersionUniswapBulkPoolFinder.PoolDiscovery[]",
|
|
1751
|
+
components: [
|
|
1752
|
+
{
|
|
1753
|
+
name: "pairIndex",
|
|
1754
|
+
type: "uint256",
|
|
1755
|
+
internalType: "uint256"
|
|
1756
|
+
},
|
|
1757
|
+
{ name: "version", type: "uint8", internalType: "uint8" },
|
|
1758
|
+
{
|
|
1759
|
+
name: "poolAddress",
|
|
1760
|
+
type: "address",
|
|
1761
|
+
internalType: "address"
|
|
1762
|
+
},
|
|
1763
|
+
{
|
|
1764
|
+
name: "poolKey",
|
|
1765
|
+
type: "tuple",
|
|
1766
|
+
internalType: "struct PoolKey",
|
|
1767
|
+
components: [
|
|
1768
|
+
{
|
|
1769
|
+
name: "currency0",
|
|
1770
|
+
type: "address",
|
|
1771
|
+
internalType: "Currency"
|
|
1772
|
+
},
|
|
1773
|
+
{
|
|
1774
|
+
name: "currency1",
|
|
1775
|
+
type: "address",
|
|
1776
|
+
internalType: "Currency"
|
|
1777
|
+
},
|
|
1778
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
1779
|
+
{
|
|
1780
|
+
name: "tickSpacing",
|
|
1781
|
+
type: "int24",
|
|
1782
|
+
internalType: "int24"
|
|
1783
|
+
},
|
|
1784
|
+
{
|
|
1785
|
+
name: "hooks",
|
|
1786
|
+
type: "address",
|
|
1787
|
+
internalType: "contract IHooks"
|
|
1788
|
+
}
|
|
1789
|
+
]
|
|
1790
|
+
},
|
|
1791
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
1792
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
1793
|
+
{ name: "hooks", type: "address", internalType: "address" }
|
|
1794
|
+
]
|
|
1795
|
+
},
|
|
1796
|
+
{ name: "count", type: "uint256", internalType: "uint256" }
|
|
1797
|
+
],
|
|
1798
|
+
stateMutability: "view"
|
|
1799
|
+
}
|
|
1800
|
+
];
|
|
1801
|
+
|
|
1802
|
+
// src/abis/multi-version-uniswap-pool-info-retriever.json
|
|
1803
|
+
var multi_version_uniswap_pool_info_retriever_default = [
|
|
1804
|
+
{
|
|
1805
|
+
type: "function",
|
|
1806
|
+
name: "V4_POOL_MANAGER",
|
|
1807
|
+
inputs: [],
|
|
1808
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
1809
|
+
stateMutability: "view"
|
|
1810
|
+
},
|
|
1811
|
+
{
|
|
1812
|
+
type: "function",
|
|
1813
|
+
name: "_getV4Slot0",
|
|
1814
|
+
inputs: [
|
|
1815
|
+
{
|
|
1816
|
+
name: "poolKey",
|
|
1817
|
+
type: "tuple",
|
|
1818
|
+
internalType: "struct PoolKey",
|
|
1819
|
+
components: [
|
|
1820
|
+
{
|
|
1821
|
+
name: "currency0",
|
|
1822
|
+
type: "address",
|
|
1823
|
+
internalType: "Currency"
|
|
1824
|
+
},
|
|
1825
|
+
{
|
|
1826
|
+
name: "currency1",
|
|
1827
|
+
type: "address",
|
|
1828
|
+
internalType: "Currency"
|
|
1829
|
+
},
|
|
1830
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
1831
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
1832
|
+
{
|
|
1833
|
+
name: "hooks",
|
|
1834
|
+
type: "address",
|
|
1835
|
+
internalType: "contract IHooks"
|
|
1836
|
+
}
|
|
1837
|
+
]
|
|
1838
|
+
}
|
|
1839
|
+
],
|
|
1840
|
+
outputs: [
|
|
1841
|
+
{ name: "sqrtPriceX96", type: "uint160", internalType: "uint160" }
|
|
1842
|
+
],
|
|
1843
|
+
stateMutability: "view"
|
|
1844
|
+
},
|
|
1845
|
+
{
|
|
1846
|
+
type: "function",
|
|
1847
|
+
name: "getPoolsFullInfoMultiVersion",
|
|
1848
|
+
inputs: [
|
|
1849
|
+
{
|
|
1850
|
+
name: "v2PoolAddresses",
|
|
1851
|
+
type: "address[]",
|
|
1852
|
+
internalType: "address[]"
|
|
1853
|
+
},
|
|
1854
|
+
{
|
|
1855
|
+
name: "v3PoolAddresses",
|
|
1856
|
+
type: "address[]",
|
|
1857
|
+
internalType: "address[]"
|
|
1858
|
+
},
|
|
1859
|
+
{
|
|
1860
|
+
name: "v4PoolKeys",
|
|
1861
|
+
type: "tuple[]",
|
|
1862
|
+
internalType: "struct PoolKey[]",
|
|
1863
|
+
components: [
|
|
1864
|
+
{
|
|
1865
|
+
name: "currency0",
|
|
1866
|
+
type: "address",
|
|
1867
|
+
internalType: "Currency"
|
|
1868
|
+
},
|
|
1869
|
+
{
|
|
1870
|
+
name: "currency1",
|
|
1871
|
+
type: "address",
|
|
1872
|
+
internalType: "Currency"
|
|
1873
|
+
},
|
|
1874
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
1875
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
1876
|
+
{
|
|
1877
|
+
name: "hooks",
|
|
1878
|
+
type: "address",
|
|
1879
|
+
internalType: "contract IHooks"
|
|
1880
|
+
}
|
|
1881
|
+
]
|
|
1882
|
+
},
|
|
1883
|
+
{ name: "baseToken", type: "address", internalType: "address" }
|
|
1884
|
+
],
|
|
1885
|
+
outputs: [
|
|
1886
|
+
{
|
|
1887
|
+
name: "",
|
|
1888
|
+
type: "tuple[]",
|
|
1889
|
+
internalType: "struct MultiVersionPoolInfoRetriever.PoolFullInfo[]",
|
|
1890
|
+
components: [
|
|
1891
|
+
{
|
|
1892
|
+
name: "poolAddress",
|
|
1893
|
+
type: "address",
|
|
1894
|
+
internalType: "address"
|
|
1895
|
+
},
|
|
1896
|
+
{ name: "token0", type: "address", internalType: "address" },
|
|
1897
|
+
{ name: "token1", type: "address", internalType: "address" },
|
|
1898
|
+
{
|
|
1899
|
+
name: "token0Decimals",
|
|
1900
|
+
type: "uint8",
|
|
1901
|
+
internalType: "uint8"
|
|
1902
|
+
},
|
|
1903
|
+
{
|
|
1904
|
+
name: "token1Decimals",
|
|
1905
|
+
type: "uint8",
|
|
1906
|
+
internalType: "uint8"
|
|
1907
|
+
},
|
|
1908
|
+
{
|
|
1909
|
+
name: "sqrtPriceX96",
|
|
1910
|
+
type: "uint256",
|
|
1911
|
+
internalType: "uint256"
|
|
1912
|
+
},
|
|
1913
|
+
{
|
|
1914
|
+
name: "baseTokenBalance",
|
|
1915
|
+
type: "uint256",
|
|
1916
|
+
internalType: "uint256"
|
|
1917
|
+
},
|
|
1918
|
+
{
|
|
1919
|
+
name: "token0Balance",
|
|
1920
|
+
type: "uint256",
|
|
1921
|
+
internalType: "uint256"
|
|
1922
|
+
},
|
|
1923
|
+
{
|
|
1924
|
+
name: "token1Balance",
|
|
1925
|
+
type: "uint256",
|
|
1926
|
+
internalType: "uint256"
|
|
1927
|
+
}
|
|
1928
|
+
]
|
|
1929
|
+
}
|
|
1930
|
+
],
|
|
1931
|
+
stateMutability: "view"
|
|
1932
|
+
}
|
|
1933
|
+
];
|
|
1934
|
+
|
|
1658
1935
|
// src/constants.ts
|
|
1659
1936
|
var SCORE_CONTRACT = {
|
|
1660
1937
|
address: "0x0000000fa09b022e5616e5a173b4b67fa2fbcf28",
|
|
@@ -1688,6 +1965,17 @@ var ALL_STRATEGY_ADDRESSES = [
|
|
|
1688
1965
|
var LEGACY_UPVOTE_V1_ADDRESS = "0x0ada882dbbdc12388a1f9ca85d2d847088f747df";
|
|
1689
1966
|
var LEGACY_UPVOTE_V2_ADDRESS = "0x9027dcad0a3dca5835895e14fbc022a1e5ea909b";
|
|
1690
1967
|
var SUPPORTED_SCORE_CHAINS = [8453];
|
|
1968
|
+
var MULTI_VERSION_UNISWAP_BULK_POOL_FINDER = {
|
|
1969
|
+
address: "0xbc237dac4c74c170780fc12f353a258bdd31a8cf",
|
|
1970
|
+
abi: multi_version_uniswap_bulk_pool_finder_default
|
|
1971
|
+
};
|
|
1972
|
+
var MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER = {
|
|
1973
|
+
address: "0x7A9EF0AC6F6a254cd570B05D62D094D3aa5067f1",
|
|
1974
|
+
abi: multi_version_uniswap_pool_info_retriever_default
|
|
1975
|
+
};
|
|
1976
|
+
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
1977
|
+
var NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1978
|
+
var UPVOTE_PRICE_ETH = 25e-6;
|
|
1691
1979
|
var encodeUpvoteKey = (tokenAddress) => {
|
|
1692
1980
|
return `0x${BigInt(`0x${tokenAddress.slice(2)}`).toString(16).padStart(64, "0")}`;
|
|
1693
1981
|
};
|
|
@@ -2114,7 +2402,378 @@ var encodePoolKey = (poolKey) => {
|
|
|
2114
2402
|
function isValidPoolKey2(poolKey) {
|
|
2115
2403
|
return poolKey.fee !== void 0 || poolKey.tickSpacing !== void 0 || poolKey.currency0 !== void 0;
|
|
2116
2404
|
}
|
|
2405
|
+
var V3_V4_FEE_TIERS = [500, 3e3, 1e4, 12e3, 8388608];
|
|
2406
|
+
var V4_TICK_SPACINGS = [200];
|
|
2407
|
+
var V4_HOOKS = [
|
|
2408
|
+
NULL_ADDRESS,
|
|
2409
|
+
"0xDd5EeaFf7BD481AD55Db083062b13a3cdf0A68CC",
|
|
2410
|
+
"0x34a45c6B61876d739400Bd71228CbcbD4F53E8cC",
|
|
2411
|
+
"0xb429d62f8f3bFFb98CdB9569533eA23bF0Ba28CC",
|
|
2412
|
+
"0xd60D6B218116cFd801E28F78d011a203D2b068Cc",
|
|
2413
|
+
"0x3e342a06f9592459D75721d6956B570F02eF2Dc0",
|
|
2414
|
+
"0xbB7784A4d481184283Ed89619A3e3ed143e1Adc0"
|
|
2415
|
+
];
|
|
2416
|
+
var LIQUIDITY_THRESHOLD_TO_PREFER_V2_V3_POOLS = 0.1 * 1e18;
|
|
2417
|
+
var LIQUIDITY_THRESHOLD_TO_CONSIDER_V2_V3_POOLS = 0.01 * 1e18;
|
|
2418
|
+
function normalizeTokenPairs(pairs) {
|
|
2419
|
+
return pairs.map((pair) => {
|
|
2420
|
+
const tokenA = pair.tokenAddress;
|
|
2421
|
+
const tokenB = pair.baseTokenAddress || WETH_ADDRESS;
|
|
2422
|
+
return {
|
|
2423
|
+
originalPair: pair,
|
|
2424
|
+
tokenA: tokenA.toLowerCase() < tokenB.toLowerCase() ? tokenA : tokenB,
|
|
2425
|
+
tokenB: tokenA.toLowerCase() < tokenB.toLowerCase() ? tokenB : tokenA
|
|
2426
|
+
};
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
function buildDiscoveryArgs(normalizedPairs) {
|
|
2430
|
+
return {
|
|
2431
|
+
tokenAs: normalizedPairs.map((p) => p.tokenA),
|
|
2432
|
+
tokenBs: normalizedPairs.map((p) => p.tokenB),
|
|
2433
|
+
fees: V3_V4_FEE_TIERS,
|
|
2434
|
+
v4TickSpacings: V4_TICK_SPACINGS,
|
|
2435
|
+
v4Hooks: V4_HOOKS
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
function parsePoolDiscoveries(poolResults, pairs) {
|
|
2439
|
+
if (!poolResults) {
|
|
2440
|
+
return {
|
|
2441
|
+
v2PoolAddresses: [],
|
|
2442
|
+
v3PoolAddresses: [],
|
|
2443
|
+
v4PoolKeys: [],
|
|
2444
|
+
v2PoolAddressToPair: {},
|
|
2445
|
+
v3PoolAddressToPair: {},
|
|
2446
|
+
v4PoolKeyToPair: {}
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
const [discoveries, countRaw] = poolResults;
|
|
2450
|
+
const countNum = typeof countRaw === "bigint" ? Number(countRaw) : Number(countRaw || 0);
|
|
2451
|
+
const v2PoolAddresses = [];
|
|
2452
|
+
const v3PoolAddresses = [];
|
|
2453
|
+
const v4PoolKeys = [];
|
|
2454
|
+
const seenV2V3Addresses = /* @__PURE__ */ new Set();
|
|
2455
|
+
const seenV4Keys = /* @__PURE__ */ new Set();
|
|
2456
|
+
const v2PoolAddressToPair = {};
|
|
2457
|
+
const v3PoolAddressToPair = {};
|
|
2458
|
+
const v4PoolKeyToPair = {};
|
|
2459
|
+
for (let i = 0; i < Math.min(countNum, discoveries.length); i++) {
|
|
2460
|
+
const discovery = discoveries[i];
|
|
2461
|
+
const version = Number(discovery?.version ?? 0);
|
|
2462
|
+
const poolAddressValue = discovery?.poolAddress;
|
|
2463
|
+
const pairIndex = Number(discovery?.pairIndex ?? 0);
|
|
2464
|
+
const feeNum = Number(discovery?.fee ?? 0);
|
|
2465
|
+
const poolKey = discovery?.poolKey;
|
|
2466
|
+
const pair = pairs[pairIndex];
|
|
2467
|
+
if (!pair) continue;
|
|
2468
|
+
if (version === 2 && poolAddressValue && poolAddressValue !== NULL_ADDRESS) {
|
|
2469
|
+
const poolAddress = poolAddressValue.toLowerCase();
|
|
2470
|
+
if (!seenV2V3Addresses.has(poolAddress)) {
|
|
2471
|
+
seenV2V3Addresses.add(poolAddress);
|
|
2472
|
+
v2PoolAddresses.push(poolAddressValue);
|
|
2473
|
+
v2PoolAddressToPair[poolAddress] = {
|
|
2474
|
+
tokenAddress: pair.tokenAddress,
|
|
2475
|
+
baseTokenAddress: pair.baseTokenAddress || WETH_ADDRESS,
|
|
2476
|
+
fee: feeNum
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
} else if (version === 3 && poolAddressValue && poolAddressValue !== NULL_ADDRESS) {
|
|
2480
|
+
const poolAddress = poolAddressValue.toLowerCase();
|
|
2481
|
+
if (!seenV2V3Addresses.has(poolAddress)) {
|
|
2482
|
+
seenV2V3Addresses.add(poolAddress);
|
|
2483
|
+
v3PoolAddresses.push(poolAddressValue);
|
|
2484
|
+
v3PoolAddressToPair[poolAddress] = {
|
|
2485
|
+
tokenAddress: pair.tokenAddress,
|
|
2486
|
+
baseTokenAddress: pair.baseTokenAddress || WETH_ADDRESS,
|
|
2487
|
+
fee: feeNum
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
} else if (version === 4 && poolKey) {
|
|
2491
|
+
const poolKeyString = JSON.stringify(poolKey);
|
|
2492
|
+
if (!seenV4Keys.has(poolKeyString)) {
|
|
2493
|
+
seenV4Keys.add(poolKeyString);
|
|
2494
|
+
v4PoolKeys.push(poolKey);
|
|
2495
|
+
v4PoolKeyToPair[poolKeyString] = {
|
|
2496
|
+
tokenAddress: pair.tokenAddress,
|
|
2497
|
+
baseTokenAddress: pair.baseTokenAddress || WETH_ADDRESS,
|
|
2498
|
+
fee: feeNum
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
return {
|
|
2504
|
+
v2PoolAddresses,
|
|
2505
|
+
v3PoolAddresses,
|
|
2506
|
+
v4PoolKeys,
|
|
2507
|
+
v2PoolAddressToPair,
|
|
2508
|
+
v3PoolAddressToPair,
|
|
2509
|
+
v4PoolKeyToPair
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
function determinePoolVersion(discoveries, index) {
|
|
2513
|
+
const {
|
|
2514
|
+
v2PoolAddresses,
|
|
2515
|
+
v3PoolAddresses,
|
|
2516
|
+
v4PoolKeys,
|
|
2517
|
+
v2PoolAddressToPair,
|
|
2518
|
+
v3PoolAddressToPair,
|
|
2519
|
+
v4PoolKeyToPair
|
|
2520
|
+
} = discoveries;
|
|
2521
|
+
if (index < v2PoolAddresses.length) {
|
|
2522
|
+
const poolAddress = v2PoolAddresses[index].toLowerCase();
|
|
2523
|
+
return {
|
|
2524
|
+
version: 2,
|
|
2525
|
+
pair: v2PoolAddressToPair[poolAddress],
|
|
2526
|
+
fee: 0,
|
|
2527
|
+
v4PoolKey: void 0
|
|
2528
|
+
};
|
|
2529
|
+
} else if (index < v2PoolAddresses.length + v3PoolAddresses.length) {
|
|
2530
|
+
const v3Index = index - v2PoolAddresses.length;
|
|
2531
|
+
const poolAddress = v3PoolAddresses[v3Index].toLowerCase();
|
|
2532
|
+
return {
|
|
2533
|
+
version: 3,
|
|
2534
|
+
pair: v3PoolAddressToPair[poolAddress],
|
|
2535
|
+
fee: v3PoolAddressToPair[poolAddress]?.fee || 0,
|
|
2536
|
+
v4PoolKey: void 0
|
|
2537
|
+
};
|
|
2538
|
+
} else {
|
|
2539
|
+
const v4Index = index - v2PoolAddresses.length - v3PoolAddresses.length;
|
|
2540
|
+
const poolKey = v4PoolKeys[v4Index];
|
|
2541
|
+
const poolKeyString = JSON.stringify(poolKey);
|
|
2542
|
+
return {
|
|
2543
|
+
version: 4,
|
|
2544
|
+
pair: v4PoolKeyToPair[poolKeyString],
|
|
2545
|
+
fee: v4PoolKeyToPair[poolKeyString]?.fee || 0,
|
|
2546
|
+
v4PoolKey: poolKey
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
function calculatePriceFromSqrtPriceX96(sqrtPriceX96, token0Decimals, token1Decimals, isToken0) {
|
|
2551
|
+
const sqrtPrice = Number(sqrtPriceX96);
|
|
2552
|
+
if (sqrtPrice === 0) return 0;
|
|
2553
|
+
const priceX96 = (sqrtPrice / 2 ** 96) ** 2;
|
|
2554
|
+
if (isToken0) {
|
|
2555
|
+
return priceX96 * 10 ** (token0Decimals - token1Decimals);
|
|
2556
|
+
} else {
|
|
2557
|
+
return 1 / priceX96 * 10 ** (token1Decimals - token0Decimals);
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
function calculatePoolPrice(info, pair, version) {
|
|
2561
|
+
try {
|
|
2562
|
+
const sqrtPriceX96 = Number(info.sqrtPriceX96);
|
|
2563
|
+
const token0Decimals = Number(info.token0Decimals);
|
|
2564
|
+
const token1Decimals = Number(info.token1Decimals);
|
|
2565
|
+
const isToken0 = info.token0.toLowerCase() === pair.tokenAddress.toLowerCase();
|
|
2566
|
+
if (version === 2) {
|
|
2567
|
+
const token0Balance = Number(info.token0Balance) / 10 ** token0Decimals;
|
|
2568
|
+
const token1Balance = Number(info.token1Balance) / 10 ** token1Decimals;
|
|
2569
|
+
if (token0Balance === 0 || token1Balance === 0) return null;
|
|
2570
|
+
if (isToken0) {
|
|
2571
|
+
return token1Balance / token0Balance;
|
|
2572
|
+
} else {
|
|
2573
|
+
return token0Balance / token1Balance;
|
|
2574
|
+
}
|
|
2575
|
+
} else {
|
|
2576
|
+
if (sqrtPriceX96 === 0) return null;
|
|
2577
|
+
if (isToken0) {
|
|
2578
|
+
return (sqrtPriceX96 / 2 ** 96) ** 2 * 10 ** (token0Decimals - token1Decimals);
|
|
2579
|
+
} else {
|
|
2580
|
+
const priceX96 = (sqrtPriceX96 / 2 ** 96) ** 2;
|
|
2581
|
+
return 1 / priceX96 * 10 ** (token1Decimals - token0Decimals);
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
} catch {
|
|
2585
|
+
return null;
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
function constructPoolKey(info, pair, version, v4PoolKey) {
|
|
2589
|
+
try {
|
|
2590
|
+
if (!info.token0 || !info.token1 || typeof pair.fee !== "number") {
|
|
2591
|
+
return void 0;
|
|
2592
|
+
}
|
|
2593
|
+
if (!info.token0.startsWith("0x") || !info.token1.startsWith("0x")) {
|
|
2594
|
+
return void 0;
|
|
2595
|
+
}
|
|
2596
|
+
const currency0 = info.token0.toLowerCase() < info.token1.toLowerCase() ? info.token0 : info.token1;
|
|
2597
|
+
const currency1 = info.token0.toLowerCase() < info.token1.toLowerCase() ? info.token1 : info.token0;
|
|
2598
|
+
if (version === 2) {
|
|
2599
|
+
return {
|
|
2600
|
+
currency0,
|
|
2601
|
+
currency1,
|
|
2602
|
+
fee: 0,
|
|
2603
|
+
tickSpacing: 0,
|
|
2604
|
+
hooks: NULL_ADDRESS
|
|
2605
|
+
};
|
|
2606
|
+
} else if (version === 3) {
|
|
2607
|
+
return {
|
|
2608
|
+
currency0,
|
|
2609
|
+
currency1,
|
|
2610
|
+
fee: pair.fee,
|
|
2611
|
+
tickSpacing: 0,
|
|
2612
|
+
hooks: NULL_ADDRESS
|
|
2613
|
+
};
|
|
2614
|
+
} else {
|
|
2615
|
+
if (!v4PoolKey || !v4PoolKey.currency0 || !v4PoolKey.currency1) {
|
|
2616
|
+
return void 0;
|
|
2617
|
+
}
|
|
2618
|
+
return v4PoolKey;
|
|
2619
|
+
}
|
|
2620
|
+
} catch {
|
|
2621
|
+
return void 0;
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
function getWethBalanceWei(pool) {
|
|
2625
|
+
if (pool.token0?.toLowerCase() === WETH_ADDRESS.toLowerCase()) {
|
|
2626
|
+
return Number(pool.token0Balance);
|
|
2627
|
+
} else if (pool.token1?.toLowerCase() === WETH_ADDRESS.toLowerCase()) {
|
|
2628
|
+
return Number(pool.token1Balance);
|
|
2629
|
+
} else {
|
|
2630
|
+
return Number(pool.baseTokenBalance);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
function filterV2V3PoolsByLiquidity(pools, threshold) {
|
|
2634
|
+
return pools.filter((pool) => {
|
|
2635
|
+
if (!pool.poolAddress) return false;
|
|
2636
|
+
const wethBalanceWei = getWethBalanceWei(pool);
|
|
2637
|
+
return wethBalanceWei >= threshold;
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
function selectBestV2V3Pool(pools) {
|
|
2641
|
+
return pools.reduce((a, b) => {
|
|
2642
|
+
const aIsV3 = a.fee > 0;
|
|
2643
|
+
const bIsV3 = b.fee > 0;
|
|
2644
|
+
if (aIsV3 && !bIsV3) return a;
|
|
2645
|
+
if (!aIsV3 && bIsV3) return b;
|
|
2646
|
+
return Number(a.baseTokenBalance) > Number(b.baseTokenBalance) ? a : b;
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
function selectBestV4Pool(pools) {
|
|
2650
|
+
return pools.reduce((a, b) => {
|
|
2651
|
+
return a.fee < b.fee ? a : b;
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
function selectBestV2V3PoolByFee(pools) {
|
|
2655
|
+
return pools.reduce((a, b) => {
|
|
2656
|
+
return a.fee < b.fee ? a : b;
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
function selectBestPoolPerPair(allPools) {
|
|
2660
|
+
const poolsByPair = {};
|
|
2661
|
+
for (const pool of allPools) {
|
|
2662
|
+
const key = pool.tokenAddress.toLowerCase() + "_" + pool.baseTokenAddress.toLowerCase();
|
|
2663
|
+
if (!poolsByPair[key]) poolsByPair[key] = [];
|
|
2664
|
+
poolsByPair[key].push(pool);
|
|
2665
|
+
}
|
|
2666
|
+
const bestPools = [];
|
|
2667
|
+
for (const [, group] of Object.entries(poolsByPair)) {
|
|
2668
|
+
let best;
|
|
2669
|
+
if (group.length === 1) {
|
|
2670
|
+
best = group[0];
|
|
2671
|
+
} else {
|
|
2672
|
+
const v2v3PoolsWithPreferredLiquidity = filterV2V3PoolsByLiquidity(
|
|
2673
|
+
group,
|
|
2674
|
+
LIQUIDITY_THRESHOLD_TO_PREFER_V2_V3_POOLS
|
|
2675
|
+
);
|
|
2676
|
+
if (v2v3PoolsWithPreferredLiquidity.length > 0) {
|
|
2677
|
+
best = selectBestV2V3Pool(v2v3PoolsWithPreferredLiquidity);
|
|
2678
|
+
} else {
|
|
2679
|
+
const v4Pools = group.filter((pool) => !pool.poolAddress);
|
|
2680
|
+
if (v4Pools.length > 0) {
|
|
2681
|
+
best = selectBestV4Pool(v4Pools);
|
|
2682
|
+
} else {
|
|
2683
|
+
const v2v3PoolsWithAcceptableLiquidity = filterV2V3PoolsByLiquidity(
|
|
2684
|
+
group,
|
|
2685
|
+
LIQUIDITY_THRESHOLD_TO_CONSIDER_V2_V3_POOLS
|
|
2686
|
+
);
|
|
2687
|
+
if (v2v3PoolsWithAcceptableLiquidity.length > 0) {
|
|
2688
|
+
best = selectBestV2V3PoolByFee(v2v3PoolsWithAcceptableLiquidity);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
if (best) {
|
|
2694
|
+
bestPools.push(best);
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
return bestPools;
|
|
2698
|
+
}
|
|
2699
|
+
async function discoverPools({
|
|
2700
|
+
publicClient,
|
|
2701
|
+
pairs
|
|
2702
|
+
}) {
|
|
2703
|
+
if (pairs.length === 0) return [];
|
|
2704
|
+
const normalizedPairs = normalizeTokenPairs(pairs);
|
|
2705
|
+
const discoveryArgs = buildDiscoveryArgs(normalizedPairs);
|
|
2706
|
+
const poolResults = await readContract(publicClient, {
|
|
2707
|
+
address: MULTI_VERSION_UNISWAP_BULK_POOL_FINDER.address,
|
|
2708
|
+
abi: MULTI_VERSION_UNISWAP_BULK_POOL_FINDER.abi,
|
|
2709
|
+
functionName: "getPoolsMultiVersion",
|
|
2710
|
+
args: [discoveryArgs]
|
|
2711
|
+
});
|
|
2712
|
+
const discoveries = parsePoolDiscoveries(poolResults, pairs);
|
|
2713
|
+
const totalPools = discoveries.v2PoolAddresses.length + discoveries.v3PoolAddresses.length + discoveries.v4PoolKeys.length;
|
|
2714
|
+
if (totalPools === 0) return [];
|
|
2715
|
+
const poolInfos = await readContract(publicClient, {
|
|
2716
|
+
address: MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER.address,
|
|
2717
|
+
abi: MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER.abi,
|
|
2718
|
+
functionName: "getPoolsFullInfoMultiVersion",
|
|
2719
|
+
args: [
|
|
2720
|
+
discoveries.v2PoolAddresses,
|
|
2721
|
+
discoveries.v3PoolAddresses,
|
|
2722
|
+
discoveries.v4PoolKeys,
|
|
2723
|
+
WETH_ADDRESS
|
|
2724
|
+
]
|
|
2725
|
+
});
|
|
2726
|
+
if (!Array.isArray(poolInfos) || poolInfos.length === 0) return [];
|
|
2727
|
+
const allPools = poolInfos.map((info, index) => {
|
|
2728
|
+
const poolData = determinePoolVersion(discoveries, index);
|
|
2729
|
+
if (!poolData || !poolData.pair) return null;
|
|
2730
|
+
return {
|
|
2731
|
+
tokenAddress: poolData.pair.tokenAddress,
|
|
2732
|
+
baseTokenAddress: poolData.pair.baseTokenAddress || WETH_ADDRESS,
|
|
2733
|
+
poolAddress: poolData.version === 4 ? null : info.poolAddress,
|
|
2734
|
+
price: calculatePoolPrice(info, poolData.pair, poolData.version),
|
|
2735
|
+
baseTokenBalance: String(info.baseTokenBalance || 0),
|
|
2736
|
+
token0: info.token0,
|
|
2737
|
+
token1: info.token1,
|
|
2738
|
+
token0Balance: String(info.token0Balance || 0),
|
|
2739
|
+
token1Balance: String(info.token1Balance || 0),
|
|
2740
|
+
fee: poolData.fee,
|
|
2741
|
+
poolKey: constructPoolKey(
|
|
2742
|
+
info,
|
|
2743
|
+
poolData.pair,
|
|
2744
|
+
poolData.version,
|
|
2745
|
+
poolData.v4PoolKey
|
|
2746
|
+
)
|
|
2747
|
+
};
|
|
2748
|
+
}).filter((p) => p !== null);
|
|
2749
|
+
const bestPools = selectBestPoolPerPair(allPools);
|
|
2750
|
+
return bestPools.map(
|
|
2751
|
+
(pool) => ({
|
|
2752
|
+
tokenAddress: pool.tokenAddress,
|
|
2753
|
+
baseTokenAddress: pool.baseTokenAddress,
|
|
2754
|
+
poolAddress: pool.poolAddress,
|
|
2755
|
+
price: pool.price,
|
|
2756
|
+
fee: pool.fee,
|
|
2757
|
+
poolKey: pool.poolKey,
|
|
2758
|
+
balances: {
|
|
2759
|
+
baseTokenBalance: pool.baseTokenBalance,
|
|
2760
|
+
token0Balance: pool.token0Balance,
|
|
2761
|
+
token1Balance: pool.token1Balance
|
|
2762
|
+
}
|
|
2763
|
+
})
|
|
2764
|
+
);
|
|
2765
|
+
}
|
|
2766
|
+
async function discoverTokenPool({
|
|
2767
|
+
publicClient,
|
|
2768
|
+
tokenAddress
|
|
2769
|
+
}) {
|
|
2770
|
+
const results = await discoverPools({
|
|
2771
|
+
publicClient,
|
|
2772
|
+
pairs: [{ tokenAddress }]
|
|
2773
|
+
});
|
|
2774
|
+
return results[0] ?? null;
|
|
2775
|
+
}
|
|
2117
2776
|
|
|
2118
|
-
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, PURE_ALPHA_STRATEGY, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_STORAGE_APP, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressFromScoreKey, getFeedContentKey, getScoreKey, getStorageScoreKey, getStorageUpvoteContext, getTokenScoreKey, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isTokenScoreKey, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };
|
|
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, WETH_ADDRESS, calculatePriceFromSqrtPriceX96, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressFromScoreKey, getFeedContentKey, getScoreKey, getStorageScoreKey, getStorageUpvoteContext, getTokenScoreKey, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isTokenScoreKey, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };
|
|
2119
2778
|
//# sourceMappingURL=index.mjs.map
|
|
2120
2779
|
//# sourceMappingURL=index.mjs.map
|