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

@@ -1,4 +1,4 @@
export type DexType = 'uniswap_v2' | 'uniswap_v3' | 'dodo' | 'custom';
export type DexType = 'uniswap_v2' | 'uniswap_v3' | 'sushiswap' | 'dodo' | 'custom';
export interface UniswapV2Config {
factory: string;
@@ -30,6 +30,7 @@ export interface CustomDexConfig {
export interface DexFactoryConfig {
uniswap_v2?: UniswapV2Config[];
uniswap_v3?: UniswapV3Config[];
sushiswap?: UniswapV2Config[];
dodo?: DodoConfig[];
custom?: CustomDexConfig[];
}
@@ -38,6 +39,35 @@ export interface DexFactoryConfig {
const CANONICAL_CHAIN138_DODO_PMM_INTEGRATION =
'0x86ADA6Ef91A3B450F89f2b751e93B1b7A3218895';
function getUniswapV2Config(chainId: number): UniswapV2Config[] | undefined {
const factory = process.env[`CHAIN_${chainId}_UNISWAP_V2_FACTORY`];
if (!factory) return undefined;
return [
{
factory,
router: process.env[`CHAIN_${chainId}_UNISWAP_V2_ROUTER`] || '',
startBlock: parseInt(process.env[`CHAIN_${chainId}_UNISWAP_V2_START_BLOCK`] || '0', 10),
},
];
}
function getDodoConfig(chainId: number): DodoConfig[] | undefined {
const poolManager = process.env[`CHAIN_${chainId}_DODO_POOL_MANAGER`] || '';
const dodoPmmIntegration = process.env[`CHAIN_${chainId}_DODO_PMM_INTEGRATION`] || '';
if (!poolManager && !dodoPmmIntegration) return undefined;
return [
{
poolManager,
dodoPmmIntegration,
dodoVendingMachine: process.env[`CHAIN_${chainId}_DODO_VENDING_MACHINE`] || '',
startBlock: parseInt(process.env[`CHAIN_${chainId}_DODO_START_BLOCK`] || '0', 10),
},
];
}
export const DEX_FACTORIES: Record<number, DexFactoryConfig> = {
138: {
// DODO PMM Integration - index from DODOPMMIntegration or PoolManager
@@ -51,12 +81,13 @@ export const DEX_FACTORIES: Record<number, DexFactoryConfig> = {
},
],
// UniswapV2 - if deployed
uniswap_v2: process.env.CHAIN_138_UNISWAP_V2_FACTORY
uniswap_v2: getUniswapV2Config(138),
sushiswap: process.env.CHAIN_138_SUSHISWAP_FACTORY
? [
{
factory: process.env.CHAIN_138_UNISWAP_V2_FACTORY,
router: process.env.CHAIN_138_UNISWAP_V2_ROUTER || '',
startBlock: parseInt(process.env.CHAIN_138_UNISWAP_V2_START_BLOCK || '0', 10),
factory: process.env.CHAIN_138_SUSHISWAP_FACTORY,
router: process.env.CHAIN_138_SUSHISWAP_ROUTER || '',
startBlock: parseInt(process.env.CHAIN_138_SUSHISWAP_START_BLOCK || '0', 10),
},
]
: undefined,
@@ -74,15 +105,7 @@ export const DEX_FACTORIES: Record<number, DexFactoryConfig> = {
651940: {
// ALL Mainnet - DEX factories to be discovered/configured
// These can be set via environment variables or discovered on-chain
uniswap_v2: process.env.CHAIN_651940_UNISWAP_V2_FACTORY
? [
{
factory: process.env.CHAIN_651940_UNISWAP_V2_FACTORY,
router: process.env.CHAIN_651940_UNISWAP_V2_ROUTER || '',
startBlock: parseInt(process.env.CHAIN_651940_UNISWAP_V2_START_BLOCK || '0', 10),
},
]
: undefined,
uniswap_v2: getUniswapV2Config(651940),
uniswap_v3: process.env.CHAIN_651940_UNISWAP_V3_FACTORY
? [
{
@@ -101,72 +124,61 @@ export const DEX_FACTORIES: Record<number, DexFactoryConfig> = {
},
]
: undefined,
custom: process.env.CHAIN_651940_HYDX_FACTORY
? [
{
factory: process.env.CHAIN_651940_HYDX_FACTORY,
router: process.env.CHAIN_651940_HYDX_ROUTER || '',
startBlock: parseInt(process.env.CHAIN_651940_HYDX_START_BLOCK || '0', 10),
pairCreatedEvent: process.env.CHAIN_651940_HYDX_PAIR_CREATED_EVENT || '',
},
]
: undefined,
},
// cW* edge chains (1, 10, 56, 100, 137): set CHAIN_*_DODO_PMM_INTEGRATION or CHAIN_*_DODO_POOL_MANAGER to index DODO/pools
1: {
dodo:
process.env.CHAIN_1_DODO_PMM_INTEGRATION || process.env.CHAIN_1_DODO_POOL_MANAGER
? [
{
poolManager: process.env.CHAIN_1_DODO_POOL_MANAGER || '',
dodoPmmIntegration: process.env.CHAIN_1_DODO_PMM_INTEGRATION || '',
dodoVendingMachine: process.env.CHAIN_1_DODO_VENDING_MACHINE || '',
startBlock: parseInt(process.env.CHAIN_1_DODO_START_BLOCK || '0', 10),
},
]
: undefined,
uniswap_v2: getUniswapV2Config(1),
dodo: getDodoConfig(1),
},
10: {
dodo:
process.env.CHAIN_10_DODO_PMM_INTEGRATION || process.env.CHAIN_10_DODO_POOL_MANAGER
? [
{
poolManager: process.env.CHAIN_10_DODO_POOL_MANAGER || '',
dodoPmmIntegration: process.env.CHAIN_10_DODO_PMM_INTEGRATION || '',
dodoVendingMachine: process.env.CHAIN_10_DODO_VENDING_MACHINE || '',
startBlock: parseInt(process.env.CHAIN_10_DODO_START_BLOCK || '0', 10),
},
]
: undefined,
uniswap_v2: getUniswapV2Config(10),
dodo: getDodoConfig(10),
},
25: {
uniswap_v2: getUniswapV2Config(25),
dodo: getDodoConfig(25),
},
56: {
dodo:
process.env.CHAIN_56_DODO_PMM_INTEGRATION || process.env.CHAIN_56_DODO_POOL_MANAGER
? [
{
poolManager: process.env.CHAIN_56_DODO_POOL_MANAGER || '',
dodoPmmIntegration: process.env.CHAIN_56_DODO_PMM_INTEGRATION || '',
dodoVendingMachine: process.env.CHAIN_56_DODO_VENDING_MACHINE || '',
startBlock: parseInt(process.env.CHAIN_56_DODO_START_BLOCK || '0', 10),
},
]
: undefined,
uniswap_v2: getUniswapV2Config(56),
dodo: getDodoConfig(56),
},
100: {
dodo:
process.env.CHAIN_100_DODO_PMM_INTEGRATION || process.env.CHAIN_100_DODO_POOL_MANAGER
? [
{
poolManager: process.env.CHAIN_100_DODO_POOL_MANAGER || '',
dodoPmmIntegration: process.env.CHAIN_100_DODO_PMM_INTEGRATION || '',
dodoVendingMachine: process.env.CHAIN_100_DODO_VENDING_MACHINE || '',
startBlock: parseInt(process.env.CHAIN_100_DODO_START_BLOCK || '0', 10),
},
]
: undefined,
uniswap_v2: getUniswapV2Config(100),
dodo: getDodoConfig(100),
},
137: {
dodo:
process.env.CHAIN_137_DODO_PMM_INTEGRATION || process.env.CHAIN_137_DODO_POOL_MANAGER
? [
{
poolManager: process.env.CHAIN_137_DODO_POOL_MANAGER || '',
dodoPmmIntegration: process.env.CHAIN_137_DODO_PMM_INTEGRATION || '',
dodoVendingMachine: process.env.CHAIN_137_DODO_VENDING_MACHINE || '',
startBlock: parseInt(process.env.CHAIN_137_DODO_START_BLOCK || '0', 10),
},
]
: undefined,
uniswap_v2: getUniswapV2Config(137),
dodo: getDodoConfig(137),
},
8453: {
uniswap_v2: getUniswapV2Config(8453),
dodo: getDodoConfig(8453),
},
42161: {
uniswap_v2: getUniswapV2Config(42161),
dodo: getDodoConfig(42161),
},
42220: {
uniswap_v2: getUniswapV2Config(42220),
dodo: getDodoConfig(42220),
},
43114: {
uniswap_v2: getUniswapV2Config(43114),
dodo: getDodoConfig(43114),
},
1111: {
uniswap_v2: getUniswapV2Config(1111),
dodo: getDodoConfig(1111),
},
};
@@ -189,6 +201,8 @@ export function hasDexType(chainId: number, dexType: DexType): boolean {
return !!config.uniswap_v2 && config.uniswap_v2.length > 0;
case 'uniswap_v3':
return !!config.uniswap_v3 && config.uniswap_v3.length > 0;
case 'sushiswap':
return !!config.sushiswap && config.sushiswap.length > 0;
case 'dodo':
return !!config.dodo && config.dodo.length > 0;
case 'custom':
@@ -208,6 +222,7 @@ export function getConfiguredDexTypes(chainId: number): DexType[] {
const types: DexType[] = [];
if (hasDexType(chainId, 'uniswap_v2')) types.push('uniswap_v2');
if (hasDexType(chainId, 'uniswap_v3')) types.push('uniswap_v3');
if (hasDexType(chainId, 'sushiswap')) types.push('sushiswap');
if (hasDexType(chainId, 'dodo')) types.push('dodo');
if (hasDexType(chainId, 'custom')) types.push('custom');