feat: expand non-evm relay and route planning support

This commit is contained in:
defiQUG
2026-04-18 12:05:34 -07:00
parent da78073104
commit 843cdbf71c
113 changed files with 8542 additions and 222 deletions

View File

@@ -9,6 +9,8 @@ import { CoinGeckoAdapter } from '../adapters/coingecko-adapter';
import { CoinMarketCapAdapter } from '../adapters/cmc-adapter';
import { DexScreenerAdapter } from '../adapters/dexscreener-adapter';
import { logger } from '../utils/logger';
import { getCanonicalPriceUsd } from '../services/canonical-price-oracle';
import { pickExternalMarketDataForIndexer } from '../services/valuation-precedence';
export class ChainIndexer {
private chainId: number;
@@ -153,8 +155,12 @@ export class ChainIndexer {
this.adapters.dexscreener.getMarketData(this.chainId, tokenAddress),
]);
// Merge external data (prefer CoinGecko, fallback to others)
const externalData = coingeckoData || dexscreenerData || cmcData;
const externalData = pickExternalMarketDataForIndexer(this.chainId, tokenAddress.toLowerCase(), {
coingecko: coingeckoData,
cmc: cmcData,
dexscreener: dexscreenerData,
});
const canonicalPriceUsd = getCanonicalPriceUsd(this.chainId, tokenAddress);
// Get pools for liquidity calculation
const tokenPools = pools.filter(
@@ -166,7 +172,7 @@ export class ChainIndexer {
await this.marketDataRepo.upsertMarketData({
chainId: this.chainId,
tokenAddress,
priceUsd: externalData?.priceUsd,
priceUsd: externalData?.priceUsd ?? canonicalPriceUsd,
priceChange24h: externalData?.priceChange24h,
volume24h: volumeMetrics.volume24h || externalData?.volume24h || 0,
volume7d: volumeMetrics.volume7d,

View File

@@ -83,6 +83,7 @@ export class PoolIndexer {
const hasDexConfig =
!!dexConfig &&
(dexConfig.uniswap_v2?.length ||
dexConfig.sushiswap?.length ||
dexConfig.uniswap_v3?.length ||
dexConfig.dodo?.length ||
dexConfig.custom?.length);
@@ -100,7 +101,14 @@ export class PoolIndexer {
// Index UniswapV2 pools
if (dexConfig.uniswap_v2) {
for (const config of dexConfig.uniswap_v2) {
const pools = await this.indexUniswapV2Pools(config);
const pools = await this.indexUniswapV2Pools(config, 'uniswap_v2');
allPools.push(...pools);
}
}
if (dexConfig.sushiswap) {
for (const config of dexConfig.sushiswap) {
const pools = await this.indexUniswapV2Pools(config, 'sushiswap');
allPools.push(...pools);
}
}
@@ -208,7 +216,10 @@ export class PoolIndexer {
/**
* Index UniswapV2 pools from PairCreated events
*/
private async indexUniswapV2Pools(config: UniswapV2Config): Promise<LiquidityPool[]> {
private async indexUniswapV2Pools(
config: UniswapV2Config,
dexType: 'uniswap_v2' | 'sushiswap'
): Promise<LiquidityPool[]> {
const pools: LiquidityPool[] = [];
const factory = new ethers.Contract(config.factory, UNISWAP_V2_FACTORY_ABI, this.provider);
@@ -237,7 +248,7 @@ export class PoolIndexer {
poolAddress: pairAddress.toLowerCase(),
token0Address: token0.toLowerCase(),
token1Address: token1.toLowerCase(),
dexType: 'uniswap_v2',
dexType,
factoryAddress: config.factory.toLowerCase(),
routerAddress: config.router?.toLowerCase(),
reserve0: reserve0.toString(),
@@ -255,7 +266,7 @@ export class PoolIndexer {
}
}
} catch (error) {
logger.error(`Error indexing UniswapV2 pools:`, error);
logger.error(`Error indexing ${dexType} pools:`, error);
}
return pools;
@@ -390,7 +401,7 @@ export class PoolIndexer {
}
try {
if (dexType === 'uniswap_v2') {
if (dexType === 'uniswap_v2' || dexType === 'sushiswap') {
const pair = new ethers.Contract(poolAddress, UNISWAP_V2_PAIR_ABI, this.provider);
const [reserve0, reserve1] = await pair.getReserves();