jest.mock('ethers', () => ({ ethers: { Contract: class {} }, })); jest.mock('../../src/routers/uniswap/uniswap-v3-router', () => ({ UniswapCustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'uniswap-v3' })), })); jest.mock('../../src/routers/uniswap/uniswap-v4-router', () => ({ UniswapCustomRouterV2: jest .fn() .mockImplementation(() => ({ kind: 'uniswap-v4' })), })); jest.mock('../../src/routers/algebra/algebra-router', () => ({ AlgebraCustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'algebra' })), })); jest.mock('../../src/routers/algebra/algebra-integral-router', () => ({ AlgebraIntegralCustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'algebra-integral' })), })); jest.mock('../../src/routers/algebra/algebra-integral-v2-router', () => ({ AlgebraIntegralV2CustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'algebra-integral-v2' })), })); jest.mock('../../src/routers/poolshark/poolshark-router', () => ({ PoolSharkCustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'poolshark' })), })); jest.mock('../../src/routers/aerodrome/aerodrome-router', () => ({ AerodromeCustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'aerodrome' })), })); jest.mock('../../src/routers/shadow/shadow-router', () => ({ ShadowCustomRouter: jest.fn().mockImplementation(() => ({ kind: 'shadow' })), })); jest.mock('../../src/routers/thickv2/thickv2-router', () => ({ ThickV2CustomRouter: jest .fn() .mockImplementation(() => ({ kind: 'thickv2' })), })); jest.mock('../../src/factory/protocol-detector', () => { const state = { algebraIntegral19: false, algebraIntegral: false, algebra: false, poolshark: false, thickv2: false, shadow: false, aerodrome: false, protocol: null as any, }; return { __state: state, ProtocolDetector: jest.fn().mockImplementation(() => ({ isAlgebraIntegral19Vault: () => state.algebraIntegral19, isAlgebraIntegralVault: () => state.algebraIntegral, isAlgebraVault: () => state.algebra, isPoolSharkVault: () => state.poolshark, isThickV2Vault: () => state.thickv2, isShadowVault: () => state.shadow, isAerodromeVault: () => state.aerodrome, getProtocol: () => state.protocol, })), }; }); jest.mock('@steerprotocol/sdk', () => ({ Protocol: { Blackhole: 'Blackhole' }, })); import { CustomRouterFactory } from '../../src/factory/custom-router-factory'; describe('CustomRouterFactory', () => { const logger = { warn: jest.fn(), info: jest.fn(), error: jest.fn(), log: jest.fn(), debug: jest.fn(), } as any; const getState = () => (require('../../src/factory/protocol-detector') as any).__state as { algebraIntegral19: boolean; algebraIntegral: boolean; algebra: boolean; poolshark: boolean; thickv2: boolean; shadow: boolean; aerodrome: boolean; protocol: any; }; beforeEach(() => { const state = getState(); state.algebraIntegral19 = false; state.algebraIntegral = false; state.algebra = false; state.poolshark = false; state.thickv2 = false; state.shadow = false; state.aerodrome = false; state.protocol = null; jest.clearAllMocks(); }); it('creates AlgebraIntegralV2 router with deployer', () => { const state = getState(); state.algebraIntegral19 = true; const factory = new CustomRouterFactory(logger); const result = factory.createCustomRouter({ beaconName: 'test', quoterV2: {} as any, poolObj: {} as any, protocolParams: { algebraIntegralV2Deployer: '0xdeployer' }, }); const routerModule = require('../../src/routers/algebra/algebra-integral-v2-router'); expect(routerModule.AlgebraIntegralV2CustomRouter).toHaveBeenCalledWith( {}, logger, '0xdeployer', ); expect((result as any).kind).toBe('algebra-integral-v2'); expect(logger.warn).not.toHaveBeenCalled(); }); it('warns for blackhole without deployer', () => { const state = getState(); state.algebraIntegral19 = true; state.protocol = 'Blackhole'; const factory = new CustomRouterFactory(logger); const result = factory.createCustomRouter({ beaconName: 'test', quoterV2: {} as any, poolObj: {} as any, }); const routerModule = require('../../src/routers/algebra/algebra-integral-v2-router'); expect(routerModule.AlgebraIntegralV2CustomRouter).toHaveBeenCalledWith( {}, logger, undefined, ); expect((result as any).kind).toBe('algebra-integral-v2'); expect(logger.warn).toHaveBeenCalled(); }); it('routes to specific protocol routers', () => { const factory = new CustomRouterFactory(logger); const state = getState(); state.algebraIntegral = true; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('algebra-integral'); state.algebraIntegral = false; state.algebra = true; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('algebra'); state.algebra = false; state.poolshark = true; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('poolshark'); state.poolshark = false; state.thickv2 = true; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('thickv2'); state.thickv2 = false; state.shadow = true; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('shadow'); state.shadow = false; state.aerodrome = true; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('aerodrome'); state.aerodrome = false; expect( (factory.createCustomRouter('beacon', {} as any, {} as any) as any).kind, ).toBe('uniswap-v3'); }); });