import { mainnet } from 'wagmi/chains'
import type { Address } from 'viem'
import { TRUSTLESS } from './bridge'

// Contract addresses on Ethereum Mainnet and Chain 138
// Trustless bridge (Lockbox, Inbox, LP, Coordinators, ChallengeManager) — use TRUSTLESS from bridge.ts as single source of truth
export const CONTRACT_ADDRESSES = {
  mainnet: {
    MAINNET_TETHER: '0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619' as Address,
    TRANSACTION_MIRROR: '0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9' as Address,
    PAYMENT_CHANNEL_MANAGER: undefined as Address | undefined,
    GENERIC_STATE_CHANNEL_MANAGER: undefined as Address | undefined,
    TWOWAY_BRIDGE_L1: undefined as Address | undefined,
    INBOX_ETH: TRUSTLESS.mainnet.INBOX_ETH as Address,
    LIQUIDITY_POOL: TRUSTLESS.mainnet.LIQUIDITY_POOL as Address,
    BRIDGE_SWAP_COORDINATOR: TRUSTLESS.mainnet.BRIDGE_SWAP_COORDINATOR as Address,
    DUAL_ROUTER_BRIDGE_SWAP_COORDINATOR: TRUSTLESS.mainnet.DUAL_ROUTER_BRIDGE_SWAP_COORDINATOR as Address,
    CHALLENGE_MANAGER: TRUSTLESS.mainnet.CHALLENGE_MANAGER as Address,
  },
  chain138: {
    TRANSACTION_MIRROR: '0xE362aa10D3Af1A16880A799b78D18F923403B55a' as Address,
    PAYMENT_CHANNEL_MANAGER: undefined as Address | undefined,
    GENERIC_STATE_CHANNEL_MANAGER: undefined as Address | undefined,
    TWOWAY_BRIDGE_L2: undefined as Address | undefined,
    LOCKBOX_138: TRUSTLESS.chain138.LOCKBOX_138 as Address,
  },
} as const

export { TRUSTLESS } from './bridge'

// Chain 138 for wagmi (custom chain)
export const chain138 = {
  id: 138,
  name: 'Chain 138',
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://rpc.chain138.example'] },
  },
  blockExplorers: {
    default: { name: 'Explorer', url: 'https://explorer.chain138.example' },
  },
} as const

export const SUPPORTED_CHAINS = {
  mainnet,
  chain138,
} as const
