import { cashLiquidityUsdFromPool } from './token-cash-liquidity';

describe('cashLiquidityUsdFromPool', () => {
  it('values only USD cash legs in a stable-stable canonical pool', () => {
    const total = cashLiquidityUsdFromPool({
      chainId: 138,
      poolAddress: '0x9e89bae009adf128782e19e8341996c596ac40dc',
      token0Address: '0x93e66202a11b1772e55407b32b44e5cd8eda7f22',
      token1Address: '0xf22258f57794cc8e06237084b353ab30fffa640b',
      dexType: 'dodo',
      reserve0: '1783887197998',
      reserve1: '216112797998',
      reserve0Usd: 0,
      reserve1Usd: 0,
      totalLiquidityUsd: 0,
      volume24h: 0,
      lastUpdated: new Date(),
    });

    expect(total).toBeCloseTo(2_000_000, 0);
  });

  it('excludes non-cash legs such as cBTC from cash liquidity', () => {
    const total = cashLiquidityUsdFromPool({
      chainId: 138,
      poolAddress: '0x72f1a0794153c3b8a1e8a731f1d8e1a52cb10dc5',
      token0Address: '0xe94260c555ac1d9d3cc9e1632883452ebdf0082e',
      token1Address: '0xf22258f57794cc8e06237084b353ab30fffa640b',
      dexType: 'dodo',
      reserve0: '10000000000',
      reserve1: '9000000000000',
      reserve0Usd: 0,
      reserve1Usd: 0,
      totalLiquidityUsd: 0,
      volume24h: 0,
      lastUpdated: new Date(),
    });

    expect(total).toBeCloseTo(9_000_000, 0);
  });

  it('returns zero for non-Chain-138 pools', () => {
    expect(
      cashLiquidityUsdFromPool({
        chainId: 1,
        poolAddress: '0x0000000000000000000000000000000000000001',
        token0Address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
        token1Address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
        dexType: 'dodo',
        reserve0: '1000000',
        reserve1: '1000000',
        reserve0Usd: 1,
        reserve1Usd: 1,
        totalLiquidityUsd: 2,
        volume24h: 0,
        lastUpdated: new Date(),
      }),
    ).toBe(0);
  });
});
