// Gas配置 - 用于解决Arbitrum测试网gas预估问题
// YT Asset Vault ABI - 用于读取 YT 代币本身的价格
export const YT_ASSET_VAULT_ABI = [
  {
    inputs: [],
    name: 'ytPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'usdcPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

export const GAS_CONFIG = {
  // 简单操作（approve等） - Arbitrum 需要更高的 gas 限制
  SIMPLE: BigInt(500000),
  // 标准操作（单一合约调用）
  STANDARD: BigInt(800000),
  // 复杂操作（涉及多个合约）
  COMPLEX: BigInt(1500000),
  // 非常复杂的操作
  VERY_COMPLEX: BigInt(3000000),
  // Gas价格设置 (单位: wei)
  // maxFeePerGas: 最大愿意支付的gas价格 (0.1 gwei = 100000000 wei)
  MAX_FEE_PER_GAS: BigInt(100000000),
  // maxPriorityFeePerGas: 给矿工的小费 (0.01 gwei = 10000000 wei)
  MAX_PRIORITY_FEE_PER_GAS: BigInt(10000000),
}

import { getContractAddress } from './contractRegistry'

// ===== 多链支持配置 =====

/**
 * 多链配置结构（仅保留精度和链信息，地址从后端动态加载）
 * 支持 ARB Sepolia (Chain ID: 421614) 和 BNB Testnet (Chain ID: 97)
 */
export const MULTI_CHAIN_CONFIG = {
  421614: {
    chainName: 'ARB Sepolia',
    rpcUrl: 'https://sepolia-rollup.arbitrum.io/rpc',
    blockExplorer: 'https://sepolia.arbiscan.io',
    decimals: {
      USDC: 6,
      YT: 18,
      YT_LP: 18,
      USDY: 18,
      DEFAULT: 18,
      CHAINLINK_PRICE: 8,
      INTERNAL_PRICE: 30,
    },
  },
  97: {
    chainName: 'BNB Testnet',
    rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545',
    blockExplorer: 'https://testnet.bscscan.com',
    decimals: {
      USDC: 18,
      YT: 18,
      YT_LP: 18,
      USDY: 18,
      DEFAULT: 18,
      CHAINLINK_PRICE: 8,
      INTERNAL_PRICE: 30,
    },
  },
} as const

// 类型定义
export type ChainId = keyof typeof MULTI_CHAIN_CONFIG
export type ChainConfig = (typeof MULTI_CHAIN_CONFIG)[ChainId]

// ===== 多链辅助函数 =====

export function getChainConfig(chainId: number): ChainConfig | undefined {
  return MULTI_CHAIN_CONFIG[chainId as ChainId]
}

/**
 * 获取当前链的合约地址配置（从后端动态加载的 registry 读取）
 * registry 由 useContractRegistry() hook 在应用启动时填充。
 * 未加载完成前各字段返回 undefined，页面通过 enabled: !!address 优雅处理。
 */
export function getContracts(chainId: number) {
  const a = (name: string) => getContractAddress(name, chainId)
  return {
    FACTORY:              a('YTAssetFactory'),
    USDC:                 a('USDC'),
    USDC_PRICE_FEED:      a('USDCPriceFeed'),
    YT_VAULT:             a('YTVault'),
    YT_POOL_MANAGER:      a('YTPoolManager'),
    YT_REWARD_ROUTER:     a('YTRewardRouter'),
    YT_PRICE_FEED:        a('YTPriceFeed'),
    YT_LP_TOKEN:          a('YTLPToken'),
    USDY:                 a('USDY'),
    LENDING_PROXY:        a('lendingProxy'),
    LENDING_CONFIGURATOR: a('LendingConfigurator'),
    LENDING_FACTORY:      a('LendingFactory'),
    LENDING_PRICE_FEED:   a('LendingPriceFeed'),
  }
}

/**
 * 获取当前链的代币精度配置
 * @param chainId 链 ID
 * @returns 精度配置对象
 * @throws 如果链不支持会抛出错误
 */
export function getDecimals(chainId: number) {
  const config = getChainConfig(chainId)
  if (!config) {
    throw new Error(`不支持的链 ID: ${chainId}。支持的链: ARB Sepolia (421614), BNB Testnet (97)`)
  }
  return config.decimals
}

/**
 * 获取 USDC 的精度（最常用）
 * ⚠️ 重要：ARB Sepolia 是 6 位，BNB Testnet 是 18 位
 * @param chainId 链 ID
 * @returns USDC 精度
 */
export function getUSDCDecimals(chainId: number): number {
  return getDecimals(chainId).USDC
}

/**
 * 检查链是否被支持
 * @param chainId 链 ID
 * @returns 是否支持该链
 */
export function isSupportedChain(chainId: number): boolean {
  return chainId in MULTI_CHAIN_CONFIG
}

/**
 * 获取所有支持的链 ID 列表
 * @returns 链 ID 数组
 */
export function getSupportedChainIds(): number[] {
  return Object.keys(MULTI_CHAIN_CONFIG).map(Number)
}

/**
 * 获取链的名称
 * @param chainId 链 ID
 * @returns 链名称
 */
export function getChainName(chainId: number): string {
  const config = getChainConfig(chainId)
  return config?.chainName || `Unknown Chain (${chainId})`
}

export function getBlockExplorer(chainId: number): string {
  const config = getChainConfig(chainId)
  return config?.blockExplorer || 'https://sepolia.arbiscan.io'
}


export function getTokenDecimals(tokenAddress: string, chainId: number): number {
  const addr = tokenAddress.toLowerCase()
  const contracts = getContracts(chainId)
  const decimals = getDecimals(chainId)

  if (contracts.USDC && addr === contracts.USDC.toLowerCase()) return decimals.USDC
  if (contracts.YT_LP_TOKEN && addr === contracts.YT_LP_TOKEN.toLowerCase()) return decimals.YT_LP
  if (contracts.USDY && addr === contracts.USDY.toLowerCase()) return decimals.USDY

  const vaultAddresses = Object.values(contracts.VAULTS).filter(Boolean).map(v => v!.toLowerCase())
  if (vaultAddresses.includes(addr)) return decimals.YT

  return decimals.DEFAULT
}

export function isUSDC(tokenAddress: string, chainId: number): boolean {
  const usdc = getContracts(chainId).USDC
  return !!usdc && tokenAddress.toLowerCase() === usdc.toLowerCase()
}

export function isYTToken(tokenAddress: string, chainId: number): boolean {
  const addr = tokenAddress.toLowerCase()
  const vaultAddresses = Object.values(getContracts(chainId).VAULTS).filter(Boolean).map(v => v!.toLowerCase())
  return vaultAddresses.includes(addr)
}

export const FACTORY_ABI = [
  {
    inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    name: 'allVaults',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'string', name: '_name', type: 'string' },
      { internalType: 'string', name: '_symbol', type: 'string' },
      { internalType: 'address', name: '_manager', type: 'address' },
      { internalType: 'uint256', name: '_hardCap', type: 'uint256' },
      { internalType: 'address', name: '_usdc', type: 'address' },
      { internalType: 'uint256', name: '_redemptionTime', type: 'uint256' },
      { internalType: 'uint256', name: '_initialYtPrice', type: 'uint256' },
      { internalType: 'address', name: '_usdcPriceFeed', type: 'address' }
    ],
    name: 'createVault',
    outputs: [{ internalType: 'address', name: 'vault', type: 'address' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [],
    name: 'defaultHardCap',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'getAllVaults',
    outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'getVaultCount',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
    name: 'getVaultInfo',
    outputs: [
      { internalType: 'bool', name: 'exists', type: 'bool' },
      { internalType: 'uint256', name: 'totalAssets', type: 'uint256' },
      { internalType: 'uint256', name: 'idleAssets', type: 'uint256' },
      { internalType: 'uint256', name: 'managedAssets', type: 'uint256' },
      { internalType: 'uint256', name: 'totalSupply', type: 'uint256' },
      { internalType: 'uint256', name: 'hardCap', type: 'uint256' },
      { internalType: 'uint256', name: 'usdcPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'ytPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'nextRedemptionTime', type: 'uint256' }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'isVault',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'owner',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_defaultHardCap', type: 'uint256' }],
    name: 'setDefaultHardCap',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_vault', type: 'address' },
      { internalType: 'uint256', name: '_hardCap', type: 'uint256' }
    ],
    name: 'setHardCap',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_vault', type: 'address' },
      { internalType: 'address', name: '_manager', type: 'address' }
    ],
    name: 'setVaultManager',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_vault', type: 'address' },
      { internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }
    ],
    name: 'setVaultNextRedemptionTime',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_vault', type: 'address' },
      { internalType: 'uint256', name: '_ytPrice', type: 'uint256' }
    ],
    name: 'updateVaultPrices',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [],
    name: 'vaultImplementation',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 批量获取金库（分页）
  {
    inputs: [
      { internalType: 'uint256', name: '_start', type: 'uint256' },
      { internalType: 'uint256', name: '_end', type: 'uint256' }
    ],
    name: 'getVaults',
    outputs: [{ internalType: 'address[]', name: 'vaults', type: 'address[]' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 批量设置硬顶
  {
    inputs: [
      { internalType: 'address[]', name: '_vaults', type: 'address[]' },
      { internalType: 'uint256[]', name: '_hardCaps', type: 'uint256[]' }
    ],
    name: 'setHardCapBatch',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 批量更新价格
  {
    inputs: [
      { internalType: 'address[]', name: '_vaults', type: 'address[]' },
      { internalType: 'uint256[]', name: '_ytPrices', type: 'uint256[]' }
    ],
    name: 'updateVaultPricesBatch',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 批量设置赎回时间
  {
    inputs: [
      { internalType: 'address[]', name: '_vaults', type: 'address[]' },
      { internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }
    ],
    name: 'setVaultNextRedemptionTimeBatch',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 设置金库实现地址
  {
    inputs: [{ internalType: 'address', name: '_newImplementation', type: 'address' }],
    name: 'setVaultImplementation',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 升级单个金库
  {
    inputs: [
      { internalType: 'address', name: '_vault', type: 'address' },
      { internalType: 'address', name: '_newImplementation', type: 'address' }
    ],
    name: 'upgradeVault',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 批量升级金库
  {
    inputs: [
      { internalType: 'address[]', name: '_vaults', type: 'address[]' },
      { internalType: 'address', name: '_newImplementation', type: 'address' }
    ],
    name: 'upgradeVaultBatch',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 批量创建金库
  {
    inputs: [
      { internalType: 'string[]', name: '_names', type: 'string[]' },
      { internalType: 'string[]', name: '_symbols', type: 'string[]' },
      { internalType: 'address[]', name: '_managers', type: 'address[]' },
      { internalType: 'uint256[]', name: '_hardCaps', type: 'uint256[]' },
      { internalType: 'address', name: '_usdc', type: 'address' },
      { internalType: 'uint256[]', name: '_redemptionTimes', type: 'uint256[]' },
      { internalType: 'uint256[]', name: '_initialYtPrices', type: 'uint256[]' },
      { internalType: 'address', name: '_usdcPriceFeed', type: 'address' }
    ],
    name: 'createVaultBatch',
    outputs: [{ internalType: 'address[]', name: 'vaults', type: 'address[]' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 暂停金库
  {
    inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
    name: 'pauseVault',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 批量暂停金库
  {
    inputs: [{ internalType: 'address[]', name: '_vaults', type: 'address[]' }],
    name: 'pauseVaultBatch',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 恢复金库
  {
    inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
    name: 'unpauseVault',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 批量恢复金库
  {
    inputs: [{ internalType: 'address[]', name: '_vaults', type: 'address[]' }],
    name: 'unpauseVaultBatch',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 设置默认硬顶
  {
    inputs: [{ internalType: 'uint256', name: '_defaultHardCap', type: 'uint256' }],
    name: 'setDefaultHardCap',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 读取默认硬顶
  {
    inputs: [],
    name: 'defaultHardCap',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取金库详情（扩展）
  {
    inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
    name: 'getVaultInfo',
    outputs: [
      { internalType: 'bool', name: 'exists', type: 'bool' },
      { internalType: 'uint256', name: 'totalAssets', type: 'uint256' },
      { internalType: 'uint256', name: 'idleAssets', type: 'uint256' },
      { internalType: 'uint256', name: 'managedAssets', type: 'uint256' },
      { internalType: 'uint256', name: 'totalSupply', type: 'uint256' },
      { internalType: 'uint256', name: 'hardCap', type: 'uint256' },
      { internalType: 'uint256', name: 'usdcPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'ytPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'nextRedemptionTime', type: 'uint256' }
    ],
    stateMutability: 'view',
    type: 'function'
  }
] as const

export const VAULT_ABI = [
  {
    inputs: [],
    name: 'PRICE_PRECISION',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'owner', type: 'address' },
      { internalType: 'address', name: 'spender', type: 'address' }
    ],
    name: 'allowance',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'spender', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'approve',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'canRedeemNow',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'decimals',
    outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_usdcAmount', type: 'uint256' }],
    name: 'depositYT',
    outputs: [{ internalType: 'uint256', name: 'ytAmount', type: 'uint256' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [],
    name: 'factory',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'getTimeUntilNextRedemption',
    outputs: [{ internalType: 'uint256', name: 'remainingTime', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'getVaultInfo',
    outputs: [
      { internalType: 'uint256', name: '_totalAssets', type: 'uint256' },
      { internalType: 'uint256', name: '_idleAssets', type: 'uint256' },
      { internalType: 'uint256', name: '_managedAssets', type: 'uint256' },
      { internalType: 'uint256', name: '_totalSupply', type: 'uint256' },
      { internalType: 'uint256', name: '_hardCap', type: 'uint256' },
      { internalType: 'uint256', name: '_usdcPrice', type: 'uint256' },
      { internalType: 'uint256', name: '_ytPrice', type: 'uint256' },
      { internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'hardCap',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'idleAssets',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'managedAssets',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'manager',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'name',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'nextRedemptionTime',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_usdcAmount', type: 'uint256' }],
    name: 'previewBuy',
    outputs: [{ internalType: 'uint256', name: 'ytAmount', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_ytAmount', type: 'uint256' }],
    name: 'previewSell',
    outputs: [{ internalType: 'uint256', name: 'usdcAmount', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'symbol',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'totalAssets',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'totalSupply',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'to', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'transfer',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'from', type: 'address' },
      { internalType: 'address', name: 'to', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'transferFrom',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 用户提交退出请求（排队机制），返回 requestId
  {
    inputs: [{ internalType: 'uint256', name: '_ytAmount', type: 'uint256' }],
    name: 'withdrawYT',
    outputs: [{ internalType: 'uint256', name: 'requestId', type: 'uint256' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 获取用户待处理的退出请求列表
  {
    inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
    name: 'getUserPendingRequests',
    outputs: [
      {
        components: [
          { internalType: 'address', name: 'user', type: 'address' },
          { internalType: 'uint256', name: 'ytAmount', type: 'uint256' },
          { internalType: 'uint256', name: 'usdcAmount', type: 'uint256' },
          { internalType: 'uint256', name: 'requestTime', type: 'uint256' },
          { internalType: 'uint256', name: 'queueIndex', type: 'uint256' },
          { internalType: 'bool', name: 'processed', type: 'bool' }
        ],
        internalType: 'struct YTAssetVault.WithdrawRequest[]',
        name: 'pendingRequests',
        type: 'tuple[]'
      }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取用户的所有请求ID
  {
    inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
    name: 'getUserRequestIds',
    outputs: [{ internalType: 'uint256[]', name: '', type: 'uint256[]' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取单个请求详情
  {
    inputs: [{ internalType: 'uint256', name: '_requestId', type: 'uint256' }],
    name: 'getRequestDetails',
    outputs: [
      {
        components: [
          { internalType: 'address', name: 'user', type: 'address' },
          { internalType: 'uint256', name: 'ytAmount', type: 'uint256' },
          { internalType: 'uint256', name: 'usdcAmount', type: 'uint256' },
          { internalType: 'uint256', name: 'requestTime', type: 'uint256' },
          { internalType: 'uint256', name: 'queueIndex', type: 'uint256' },
          { internalType: 'bool', name: 'processed', type: 'bool' }
        ],
        internalType: 'struct YTAssetVault.WithdrawRequest',
        name: 'request',
        type: 'tuple'
      }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取待处理请求数量
  {
    inputs: [],
    name: 'getPendingRequestsCount',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取队列进度
  {
    inputs: [],
    name: 'getQueueProgress',
    outputs: [
      { internalType: 'uint256', name: 'currentIndex', type: 'uint256' },
      { internalType: 'uint256', name: 'totalRequests', type: 'uint256' },
      { internalType: 'uint256', name: 'pendingRequests', type: 'uint256' }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  // 待处理请求数量（状态变量）
  {
    inputs: [],
    name: 'pendingRequestsCount',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 请求ID计数器
  {
    inputs: [],
    name: 'requestIdCounter',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 批量处理退出请求（Manager/Factory 调用）
  {
    inputs: [{ internalType: 'uint256', name: '_batchSize', type: 'uint256' }],
    name: 'processBatchWithdrawals',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 请求映射
  {
    inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    name: 'withdrawRequests',
    outputs: [
      { internalType: 'address', name: 'user', type: 'address' },
      { internalType: 'uint256', name: 'ytAmount', type: 'uint256' },
      { internalType: 'uint256', name: 'usdcAmount', type: 'uint256' },
      { internalType: 'uint256', name: 'requestTime', type: 'uint256' },
      { internalType: 'uint256', name: 'queueIndex', type: 'uint256' },
      { internalType: 'bool', name: 'processed', type: 'bool' }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'usdcAddress',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'usdcPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'ytPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
    name: 'depositManagedAssets',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_to', type: 'address' },
      { internalType: 'uint256', name: '_amount', type: 'uint256' }
    ],
    name: 'withdrawForManagement',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'uint256', name: '_ytPrice', type: 'uint256' }
    ],
    name: 'updatePrices',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_hardCap', type: 'uint256' }],
    name: 'setHardCap',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_manager', type: 'address' }],
    name: 'setManager',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }],
    name: 'setNextRedemptionTime',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 读取暂停状态
  {
    inputs: [],
    name: 'paused',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

// USDC 标准 ERC20 ABI (6位精度)
export const USDC_ABI = [
  {
    inputs: [
      { internalType: 'address', name: 'owner', type: 'address' },
      { internalType: 'address', name: 'spender', type: 'address' }
    ],
    name: 'allowance',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'spender', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'approve',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'decimals',
    outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'name',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'symbol',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'totalSupply',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'to', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'transfer',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'from', type: 'address' },
      { internalType: 'address', name: 'to', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'transferFrom',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  }
] as const

// 保留 WUSD_ABI 别名以便向后兼容
export const WUSD_ABI = USDC_ABI

// YT Reward Router ABI - for addLiquidity, removeLiquidity, swapYT
export const YT_REWARD_ROUTER_ABI = [
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_amount', type: 'uint256' },
      { internalType: 'uint256', name: '_minUsdy', type: 'uint256' },
      { internalType: 'uint256', name: '_minYtLP', type: 'uint256' }
    ],
    name: 'addLiquidity',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_tokenOut', type: 'address' },
      { internalType: 'uint256', name: '_ytLPAmount', type: 'uint256' },
      { internalType: 'uint256', name: '_minOut', type: 'uint256' },
      { internalType: 'address', name: '_receiver', type: 'address' }
    ],
    name: 'removeLiquidity',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_tokenIn', type: 'address' },
      { internalType: 'address', name: '_tokenOut', type: 'address' },
      { internalType: 'uint256', name: '_amountIn', type: 'uint256' },
      { internalType: 'uint256', name: '_minOut', type: 'uint256' },
      { internalType: 'address', name: '_receiver', type: 'address' }
    ],
    name: 'swapYT',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [],
    name: 'getYtLPPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_account', type: 'address' }],
    name: 'getAccountValue',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'gov',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'ytLP',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'ytPoolManager',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'ytVault',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

// YT LP Token ABI (ERC20)
export const YT_LP_TOKEN_ABI = [
  {
    inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'totalSupply',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'decimals',
    outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'symbol',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'name',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'spender', type: 'address' },
      { internalType: 'uint256', name: 'value', type: 'uint256' }
    ],
    name: 'approve',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: 'owner', type: 'address' },
      { internalType: 'address', name: 'spender', type: 'address' }
    ],
    name: 'allowance',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 设置 Minter
  {
    inputs: [
      { internalType: 'address', name: '_minter', type: 'address' },
      { internalType: 'bool', name: '_isActive', type: 'bool' }
    ],
    name: 'setMinter',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 检查 Minter 状态
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'isMinter',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 读取 Owner
  {
    inputs: [],
    name: 'owner',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 转移所有权
  {
    inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }],
    name: 'transferOwnership',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 设置 Gov
  {
    inputs: [{ internalType: 'address', name: '_gov', type: 'address' }],
    name: 'setGov',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 读取 Gov
  {
    inputs: [],
    name: 'gov',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

// YT Pool Manager ABI
export const YT_POOL_MANAGER_ABI = [
  {
    inputs: [{ internalType: 'bool', name: '_maximise', type: 'bool' }],
    name: 'getAumInUsdy',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'cooldownDuration',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'lastAddedAt',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'gov',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P1: 设置冷却时间
  {
    inputs: [{ internalType: 'uint256', name: '_duration', type: 'uint256' }],
    name: 'setCooldownDuration',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 暂停
  {
    inputs: [],
    name: 'pause',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 恢复
  {
    inputs: [],
    name: 'unpause',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 暂停状态读取
  {
    inputs: [],
    name: 'paused',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P2: 设置 AUM 调整
  {
    inputs: [
      { internalType: 'uint256', name: '_addition', type: 'uint256' },
      { internalType: 'uint256', name: '_deduction', type: 'uint256' }
    ],
    name: 'setAumAdjustment',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 读取 AUM 调整值
  {
    inputs: [],
    name: 'aumAddition',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'aumDeduction',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 设置 Gov
  {
    inputs: [{ internalType: 'address', name: '_gov', type: 'address' }],
    name: 'setGov',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 设置 Handler
  {
    inputs: [
      { internalType: 'address', name: '_handler', type: 'address' },
      { internalType: 'bool', name: '_isActive', type: 'bool' }
    ],
    name: 'setHandler',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 检查 Handler 状态
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'isHandler',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

// YT PriceFeed ABI - for price configuration
export const YT_PRICE_FEED_ABI = [
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_price', type: 'uint256' }
    ],
    name: 'forceUpdatePrice',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_spreadBasisPoints', type: 'uint256' }
    ],
    name: 'setSpreadBasisPoints',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'getPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'getMinPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'getMaxPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取完整价格信息 - 诊断用
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'getPriceInfo',
    outputs: [
      { internalType: 'uint256', name: 'currentPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'cachedPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'maxPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'minPrice', type: 'uint256' },
      { internalType: 'uint256', name: 'spread', type: 'uint256' }
    ],
    stateMutability: 'view',
    type: 'function'
  },
  // USDC 地址
  {
    inputs: [],
    name: 'USDC',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'spreadBasisPoints',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'lastPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'gov',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'usdcPriceSource',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'maxPriceChangeBps',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 设置 USDC 价格源
  {
    inputs: [{ internalType: 'address', name: '_usdcPriceSource', type: 'address' }],
    name: 'setUsdcPriceSource',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 设置稳定币
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'bool', name: '_isStable', type: 'bool' }
    ],
    name: 'setStableToken',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 检查是否是稳定币
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'stableTokens',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

// YT Vault ABI - for pool info
export const YT_VAULT_ABI = [
  {
    inputs: [],
    name: 'getAllWhitelistedTokens',
    outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'poolAmounts',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'usdyAmounts',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'tokenWeights',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'totalTokenWeights',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'whitelistedTokens',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'bool', name: '_maximise', type: 'bool' }
    ],
    name: 'getPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'getMinPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'getMaxPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'gov',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'tokenDecimals',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'maxUsdyAmounts',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 读取 priceFeed 地址
  {
    inputs: [],
    name: 'priceFeed',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 管理员配置函数 - 设置白名单代币（包含配置）
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_decimals', type: 'uint256' },
      { internalType: 'uint256', name: '_weight', type: 'uint256' },
      { internalType: 'uint256', name: '_maxUsdyAmount', type: 'uint256' },
      { internalType: 'bool', name: '_isStable', type: 'bool' }
    ],
    name: 'setWhitelistedToken',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 清除白名单代币
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'clearWhitelistedToken',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 获取交换手续费率 - 用于滑点计算
  {
    inputs: [
      { internalType: 'address', name: '_tokenIn', type: 'address' },
      { internalType: 'address', name: '_tokenOut', type: 'address' },
      { internalType: 'uint256', name: '_usdyAmount', type: 'uint256' }
    ],
    name: 'getSwapFeeBasisPoints',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取赎回手续费率 - 用于移除流动性滑点计算
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_usdyAmount', type: 'uint256' }
    ],
    name: 'getRedemptionFeeBasisPoints',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取动态手续费率
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_usdyDelta', type: 'uint256' },
      { internalType: 'uint256', name: '_feeBasisPoints', type: 'uint256' },
      { internalType: 'uint256', name: '_taxBasisPoints', type: 'uint256' },
      { internalType: 'bool', name: '_increment', type: 'bool' }
    ],
    name: 'getFeeBasisPoints',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取池子总价值
  {
    inputs: [{ internalType: 'bool', name: '_maximise', type: 'bool' }],
    name: 'getPoolValue',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 获取所有池子代币
  {
    inputs: [],
    name: 'getAllPoolTokens',
    outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 常量
  {
    inputs: [],
    name: 'BASIS_POINTS_DIVISOR',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'PRICE_PRECISION',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'USDY_DECIMALS',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 紧急模式
  {
    inputs: [],
    name: 'emergencyMode',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // swap 开关 (合约实际使用 isSwapEnabled)
  {
    inputs: [],
    name: 'isSwapEnabled',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // 设置紧急模式
  {
    inputs: [{ internalType: 'bool', name: '_emergencyMode', type: 'bool' }],
    name: 'setEmergencyMode',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 设置 swap 开关
  {
    inputs: [{ internalType: 'bool', name: '_isSwapEnabled', type: 'bool' }],
    name: 'setSwapEnabled',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // 稳定币标记
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'stableTokens',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P1: 设置交换手续费
  {
    inputs: [
      { internalType: 'uint256', name: '_swapFee', type: 'uint256' },
      { internalType: 'uint256', name: '_stableSwapFee', type: 'uint256' },
      { internalType: 'uint256', name: '_taxBasisPoints', type: 'uint256' },
      { internalType: 'uint256', name: '_stableTaxBasisPoints', type: 'uint256' }
    ],
    name: 'setSwapFees',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P1: 紧急提取代币
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'address', name: '_receiver', type: 'address' },
      { internalType: 'uint256', name: '_amount', type: 'uint256' }
    ],
    name: 'withdrawToken',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 设置动态手续费开关
  {
    inputs: [{ internalType: 'bool', name: '_dynamicFees', type: 'bool' }],
    name: 'setDynamicFees',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 读取动态手续费状态
  {
    inputs: [],
    name: 'dynamicFees',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P2: 设置最大交换金额
  {
    inputs: [
      { internalType: 'address', name: '_token', type: 'address' },
      { internalType: 'uint256', name: '_amount', type: 'uint256' }
    ],
    name: 'setMaxSwapAmount',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 读取最大交换金额
  {
    inputs: [{ internalType: 'address', name: '_token', type: 'address' }],
    name: 'maxSwapAmounts',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P2: 设置最大滑点
  {
    inputs: [{ internalType: 'uint256', name: '_slippageBps', type: 'uint256' }],
    name: 'setMaxSwapSlippageBps',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 读取最大滑点
  {
    inputs: [],
    name: 'maxSwapSlippageBps',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P2: 设置最大价格变化
  {
    inputs: [{ internalType: 'uint256', name: '_maxPriceChangeBps', type: 'uint256' }],
    name: 'setMaxPriceChangeBps',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P2: 读取最大价格变化
  {
    inputs: [],
    name: 'maxPriceChangeBps',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P1: 读取手续费配置
  {
    inputs: [],
    name: 'swapFee',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'stableSwapFee',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'taxBasisPoints',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'stableTaxBasisPoints',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 设置 Gov
  {
    inputs: [{ internalType: 'address', name: '_gov', type: 'address' }],
    name: 'setGov',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 设置 Keeper
  {
    inputs: [
      { internalType: 'address', name: '_keeper', type: 'address' },
      { internalType: 'bool', name: '_isActive', type: 'bool' }
    ],
    name: 'setKeeper',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 检查 Keeper 状态
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'isKeeper',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 设置 Pool Manager
  {
    inputs: [{ internalType: 'address', name: '_poolManager', type: 'address' }],
    name: 'setPoolManager',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 读取 Pool Manager
  {
    inputs: [],
    name: 'poolManager',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 设置 Swapper
  {
    inputs: [
      { internalType: 'address', name: '_swapper', type: 'address' },
      { internalType: 'bool', name: '_isActive', type: 'bool' }
    ],
    name: 'setSwapper',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 检查 Swapper 状态
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'isSwapper',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  // P3: 转移所有权
  {
    inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }],
    name: 'transferOwnership',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // P3: 读取 Owner
  {
    inputs: [],
    name: 'owner',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  }
] as const

// USDY 合约 ABI (内部计价代币)
export const USDY_ABI = [
  // 标准 ERC20 函数
  {
    inputs: [],
    name: 'name',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'symbol',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'decimals',
    outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [],
    name: 'totalSupply',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  },
  // Owner
  {
    inputs: [],
    name: 'owner',
    outputs: [{ internalType: 'address', name: '', type: 'address' }],
    stateMutability: 'view',
    type: 'function'
  },
  // Vault 白名单管理
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'vaults',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
    name: 'addVault',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
    name: 'removeVault',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  // mint/burn (仅白名单 Vault 可调用)
  {
    inputs: [
      { internalType: 'address', name: '_account', type: 'address' },
      { internalType: 'uint256', name: '_amount', type: 'uint256' }
    ],
    name: 'mint',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  },
  {
    inputs: [
      { internalType: 'address', name: '_account', type: 'address' },
      { internalType: 'uint256', name: '_amount', type: 'uint256' }
    ],
    name: 'burn',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function'
  }
] as const
export const LENDING_ABI = [
  {
    "inputs": [],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "target",
        "type": "address"
      }
    ],
    "name": "AddressEmptyCode",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "BorrowTooSmall",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "implementation",
        "type": "address"
      }
    ],
    "name": "ERC1967InvalidImplementation",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "ERC1967NonPayable",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "EnforcedPause",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "ExpectedPause",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "FailedCall",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InsufficientBalance",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InsufficientCollateral",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InsufficientReserves",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InvalidBorrowCollateralFactor",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InvalidInitialization",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InvalidLiquidateCollateralFactor",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "InvalidLiquidationFactor",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "NotForSale",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "NotInitializing",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "NotLiquidatable",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "name": "OwnableInvalidOwner",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "OwnableUnauthorizedAccount",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "ReentrancyGuardReentrantCall",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "token",
        "type": "address"
      }
    ],
    "name": "SafeERC20FailedOperation",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "SupplyCapExceeded",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "UUPSUnauthorizedCallContext",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "slot",
        "type": "bytes32"
      }
    ],
    "name": "UUPSUnsupportedProxiableUUID",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "Unauthorized",
    "type": "error"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "absorber",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "borrower",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "collateralAbsorbed",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "usdValue",
        "type": "uint256"
      }
    ],
    "name": "AbsorbCollateral",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "absorber",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "borrower",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "basePaidOut",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "usdValue",
        "type": "uint256"
      }
    ],
    "name": "AbsorbDebt",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "uint104",
        "name": "baseBorrowMin",
        "type": "uint104"
      }
    ],
    "name": "BaseBorrowMinUpdated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "buyer",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "baseAmount",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "collateralAmount",
        "type": "uint256"
      }
    ],
    "name": "BuyCollateral",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "uint64",
        "name": "version",
        "type": "uint64"
      }
    ],
    "name": "Initialized",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "previousOwner",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "newOwner",
        "type": "address"
      }
    ],
    "name": "OwnershipTransferred",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "Paused",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "dst",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "Supply",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "dst",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "SupplyCollateral",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "uint104",
        "name": "targetReserves",
        "type": "uint104"
      }
    ],
    "name": "TargetReservesUpdated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "Unpaused",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "implementation",
        "type": "address"
      }
    ],
    "name": "Upgraded",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "src",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "Withdraw",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "src",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "WithdrawCollateral",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "WithdrawReserves",
    "type": "event"
  },
  {
    "inputs": [],
    "name": "UPGRADE_INTERFACE_VERSION",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "borrower",
        "type": "address"
      }
    ],
    "name": "absorb",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "absorber",
        "type": "address"
      },
      {
        "internalType": "address[]",
        "name": "accounts",
        "type": "address[]"
      }
    ],
    "name": "absorbMultiple",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "accrueInterest",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "assetConfigs",
    "outputs": [
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "internalType": "uint8",
        "name": "decimals",
        "type": "uint8"
      },
      {
        "internalType": "uint64",
        "name": "borrowCollateralFactor",
        "type": "uint64"
      },
      {
        "internalType": "uint64",
        "name": "liquidateCollateralFactor",
        "type": "uint64"
      },
      {
        "internalType": "uint64",
        "name": "liquidationFactor",
        "type": "uint64"
      },
      {
        "internalType": "uint128",
        "name": "supplyCap",
        "type": "uint128"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "assetList",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "baseBorrowMin",
    "outputs": [
      {
        "internalType": "uint104",
        "name": "",
        "type": "uint104"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "baseToken",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "borrowBalanceOf",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "borrowIndex",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "borrowKink",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "borrowPerSecondInterestRateBase",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "borrowPerSecondInterestRateSlopeHigh",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "borrowPerSecondInterestRateSlopeLow",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "minAmount",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "baseAmount",
        "type": "uint256"
      },
      {
        "internalType": "address",
        "name": "recipient",
        "type": "address"
      }
    ],
    "name": "buyCollateral",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "collateralReserves",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "getBalance",
    "outputs": [
      {
        "internalType": "int256",
        "name": "",
        "type": "int256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getBorrowRate",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      }
    ],
    "name": "getCollateral",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      }
    ],
    "name": "getCollateralReserves",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getReserves",
    "outputs": [
      {
        "internalType": "int256",
        "name": "",
        "type": "int256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getSupplyRate",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getTotalBorrow",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getTotalSupply",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getUtilization",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "components": [
          {
            "internalType": "address",
            "name": "baseToken",
            "type": "address"
          },
          {
            "internalType": "address",
            "name": "lendingPriceSource",
            "type": "address"
          },
          {
            "internalType": "uint64",
            "name": "supplyKink",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "supplyPerYearInterestRateSlopeLow",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "supplyPerYearInterestRateSlopeHigh",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "supplyPerYearInterestRateBase",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "borrowKink",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "borrowPerYearInterestRateSlopeLow",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "borrowPerYearInterestRateSlopeHigh",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "borrowPerYearInterestRateBase",
            "type": "uint64"
          },
          {
            "internalType": "uint64",
            "name": "storeFrontPriceFactor",
            "type": "uint64"
          },
          {
            "internalType": "uint104",
            "name": "baseBorrowMin",
            "type": "uint104"
          },
          {
            "internalType": "uint104",
            "name": "targetReserves",
            "type": "uint104"
          },
          {
            "components": [
              {
                "internalType": "address",
                "name": "asset",
                "type": "address"
              },
              {
                "internalType": "uint8",
                "name": "decimals",
                "type": "uint8"
              },
              {
                "internalType": "uint64",
                "name": "borrowCollateralFactor",
                "type": "uint64"
              },
              {
                "internalType": "uint64",
                "name": "liquidateCollateralFactor",
                "type": "uint64"
              },
              {
                "internalType": "uint64",
                "name": "liquidationFactor",
                "type": "uint64"
              },
              {
                "internalType": "uint128",
                "name": "supplyCap",
                "type": "uint128"
              }
            ],
            "internalType": "struct LendingConfiguration.AssetConfig[]",
            "name": "assetConfigs",
            "type": "tuple[]"
          }
        ],
        "internalType": "struct LendingConfiguration.Configuration",
        "name": "config",
        "type": "tuple"
      }
    ],
    "name": "initialize",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "isLiquidatable",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "lastAccrualTime",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "lendingPriceSource",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "owner",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "pause",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "paused",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "proxiableUUID",
    "outputs": [
      {
        "internalType": "bytes32",
        "name": "",
        "type": "bytes32"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "baseAmount",
        "type": "uint256"
      }
    ],
    "name": "quoteCollateral",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "renounceOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint104",
        "name": "newBaseBorrowMin",
        "type": "uint104"
      }
    ],
    "name": "setBaseBorrowMin",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint104",
        "name": "newTargetReserves",
        "type": "uint104"
      }
    ],
    "name": "setTargetReserves",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "storeFrontPriceFactor",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "supply",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "supplyBalanceOf",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "supplyCollateral",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "supplyIndex",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "supplyKink",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "supplyPerSecondInterestRateBase",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "supplyPerSecondInterestRateSlopeHigh",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "supplyPerSecondInterestRateSlopeLow",
    "outputs": [
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "targetReserves",
    "outputs": [
      {
        "internalType": "uint104",
        "name": "",
        "type": "uint104"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalBorrowBase",
    "outputs": [
      {
        "internalType": "uint104",
        "name": "",
        "type": "uint104"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalSupplyBase",
    "outputs": [
      {
        "internalType": "uint104",
        "name": "",
        "type": "uint104"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "newOwner",
        "type": "address"
      }
    ],
    "name": "transferOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "unpause",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "newImplementation",
        "type": "address"
      },
      {
        "internalType": "bytes",
        "name": "data",
        "type": "bytes"
      }
    ],
    "name": "upgradeToAndCall",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "userBasic",
    "outputs": [
      {
        "internalType": "int104",
        "name": "principal",
        "type": "int104"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "userCollateral",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "withdraw",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "asset",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "withdrawCollateral",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "withdrawReserves",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
] as const

// YT Token ABI (ERC20 标准，18位精度) - 使用 USDC_ABI
export const YT_TOKEN_ABI = USDC_ABI

