import { createPublicClient, http, getAddress, decodeErrorResult } from 'viem' import { arbitrumSepolia } from 'viem/chains' const client = createPublicClient({ chain: arbitrumSepolia, transport: http('https://api.zan.top/node/v1/arb/sepolia/baf84c429d284bb5b676cb8c9ca21c07') }) const LENDING_PROXY = getAddress('0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D') const USER = getAddress('0xa013422A5918CD099C63c8CC35283EACa99a705d') const YT_A = getAddress('0x97204190B35D9895a7a47aa7BaC61ac08De3cF05') async function testWithDetails(name, abi, args) { console.log(`\n=== 测试 ${name} ===`) try { const result = await client.readContract({ address: LENDING_PROXY, abi: [abi], functionName: name, args: args }) console.log('✓ 成功:', result) return result } catch (error) { console.log('✗ 失败') console.log('错误类型:', error.name) console.log('错误消息:', error.message.split('\n')[0]) // 尝试解码错误 if (error.data) { console.log('错误数据:', error.data) } // 打印完整堆栈 console.log('\n完整错误:') console.log(error) } } async function main() { console.log('诊断 Lending 合约 View 函数\n') console.log('合约:', LENDING_PROXY) console.log('用户:', USER) console.log('抵押品:', YT_A) // 测试 1: borrowBalanceOf (已知能工作) await testWithDetails('borrowBalanceOf', { inputs: [{ name: 'account', type: 'address' }], name: 'borrowBalanceOf', outputs: [{ name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' }, [USER]) // 测试 2: getUserAccountData await testWithDetails('getUserAccountData', { inputs: [{ name: '_user', type: 'address' }], name: 'getUserAccountData', outputs: [ { name: 'totalCollateralValue', type: 'uint256' }, { name: 'totalBorrowValue', type: 'uint256' }, { name: 'availableToBorrow', type: 'uint256' }, { name: 'healthFactor', type: 'uint256' } ], stateMutability: 'view', type: 'function' }, [USER]) // 测试 3: getUserCollateral await testWithDetails('getUserCollateral', { inputs: [ { name: '_user', type: 'address' }, { name: '_collateralAsset', type: 'address' } ], name: 'getUserCollateral', outputs: [{ name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' }, [USER, YT_A]) // 测试 4: getCollateralConfig (检查资产是否配置) await testWithDetails('getCollateralConfig', { inputs: [{ name: '_asset', type: 'address' }], name: 'getCollateralConfig', outputs: [ { name: 'isActive', type: 'bool' }, { name: 'decimals', type: 'uint8' }, { name: 'borrowCollateralFactor', type: 'uint64' }, { name: 'liquidateCollateralFactor', type: 'uint64' }, { name: 'liquidationFactor', type: 'uint64' }, { name: 'supplyCap', type: 'uint128' } ], stateMutability: 'view', type: 'function' }, [YT_A]) // 测试 5: paused (检查是否暂停) await testWithDetails('paused', { inputs: [], name: 'paused', outputs: [{ name: '', type: 'bool' }], stateMutability: 'view', type: 'function' }, []) } main()