import { createPublicClient, http, formatUnits } from 'viem'; import { arbitrumSepolia } from 'viem/chains'; const RPC_URL = 'https://sepolia-rollup.arbitrum.io/rpc'; const LENDING_PROXY = '0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D'; const client = createPublicClient({ chain: arbitrumSepolia, transport: http(RPC_URL) }); async function testBothFunctions() { console.log('\n=== 测试 getTotalSupply vs getTotalLiquidity ===\n'); // 测试 getTotalSupply console.log('1️⃣ 测试 getTotalSupply():'); try { const totalSupply = await client.readContract({ address: LENDING_PROXY, abi: [{ inputs: [], name: 'getTotalSupply', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' }], functionName: 'getTotalSupply' }); console.log(' ✅ 调用成功!'); console.log(' 值:', totalSupply.toString()); console.log(' 格式化:', formatUnits(totalSupply, 6), 'USDC'); } catch (error) { console.log(' ❌ 调用失败!'); console.log(' 错误:', error.message.split('\n')[0]); } console.log('\n2️⃣ 测试 getTotalLiquidity():'); try { const totalLiquidity = await client.readContract({ address: LENDING_PROXY, abi: [{ inputs: [], name: 'getTotalLiquidity', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' }], functionName: 'getTotalLiquidity' }); console.log(' ✅ 调用成功!'); console.log(' 值:', totalLiquidity.toString()); console.log(' 格式化:', formatUnits(totalLiquidity, 6), 'USDC'); } catch (error) { console.log(' ❌ 调用失败!'); console.log(' 错误:', error.message.split('\n')[0]); } // 测试其他可能的函数名 console.log('\n3️⃣ 测试 totalSupply() (Compound V3 标准):'); try { const totalSupply = await client.readContract({ address: LENDING_PROXY, abi: [{ inputs: [], name: 'totalSupply', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' }], functionName: 'totalSupply' }); console.log(' ✅ 调用成功!'); console.log(' 值:', totalSupply.toString()); console.log(' 格式化:', formatUnits(totalSupply, 6), 'USDC'); } catch (error) { console.log(' ❌ 调用失败!'); console.log(' 错误:', error.message.split('\n')[0]); } console.log('\n4️⃣ 测试 totalBorrow():'); try { const totalBorrow = await client.readContract({ address: LENDING_PROXY, abi: [{ inputs: [], name: 'totalBorrow', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' }], functionName: 'totalBorrow' }); console.log(' ✅ 调用成功!'); console.log(' 值:', totalBorrow.toString()); console.log(' 格式化:', formatUnits(totalBorrow, 6), 'USDC'); } catch (error) { console.log(' ❌ 调用失败!'); console.log(' 错误:', error.message.split('\n')[0]); } console.log('\n'); } testBothFunctions().catch(console.error);