- 新增 ARB Sepolia + BNB Testnet 多链支持 - 添加 LendingPanel 借贷系统组件 - 添加 LendingAdminPanel 管理面板 - 添加 USDCPanel USDC 操作组件 - 添加 HoldersPanel 持有人信息组件 - 添加 AutoTestPanel 自动化测试组件 - 重构 LP 组件为模块化结构 (LP/) - 添加多个调试和测试脚本 - 修复 USDC 精度动态配置 - 优化合约配置支持多链切换 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
101 lines
3.7 KiB
JavaScript
101 lines
3.7 KiB
JavaScript
import { createPublicClient, http, getAddress } 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')
|
||
|
||
const LENDING_ABI = [
|
||
{
|
||
inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
|
||
name: 'getUserAccountData',
|
||
outputs: [
|
||
{ internalType: 'uint256', name: 'totalCollateralValue', type: 'uint256' },
|
||
{ internalType: 'uint256', name: 'totalBorrowValue', type: 'uint256' },
|
||
{ internalType: 'uint256', name: 'availableToBorrow', type: 'uint256' },
|
||
{ internalType: 'uint256', name: 'healthFactor', type: 'uint256' }
|
||
],
|
||
stateMutability: 'view',
|
||
type: 'function'
|
||
},
|
||
{
|
||
inputs: [
|
||
{ internalType: 'address', name: '_user', type: 'address' },
|
||
{ internalType: 'address', name: '_collateralAsset', type: 'address' }
|
||
],
|
||
name: 'getUserCollateral',
|
||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||
stateMutability: 'view',
|
||
type: 'function'
|
||
}
|
||
]
|
||
|
||
async function main() {
|
||
console.log('\n检查用户账户数据...\n')
|
||
console.log('用户地址:', USER)
|
||
console.log('Lending 合约:', LENDING_PROXY)
|
||
|
||
try {
|
||
// 1. 检查抵押品余额
|
||
console.log('\n--- 1. 检查 getUserCollateral (YT-A) ---')
|
||
const collateral = await client.readContract({
|
||
address: LENDING_PROXY,
|
||
abi: LENDING_ABI,
|
||
functionName: 'getUserCollateral',
|
||
args: [USER, YT_A]
|
||
})
|
||
console.log('✓ getUserCollateral:', Number(collateral) / 1e18, 'YT-A')
|
||
console.log(' 原始值:', collateral.toString())
|
||
|
||
// 2. 检查账户数据
|
||
console.log('\n--- 2. 检查 getUserAccountData ---')
|
||
const accountData = await client.readContract({
|
||
address: LENDING_PROXY,
|
||
abi: LENDING_ABI,
|
||
functionName: 'getUserAccountData',
|
||
args: [USER]
|
||
})
|
||
|
||
console.log('✓ getUserAccountData 返回:')
|
||
console.log(' totalCollateralValue:', Number(accountData[0]) / 1e6, 'USD')
|
||
console.log(' totalBorrowValue:', Number(accountData[1]) / 1e6, 'USD')
|
||
console.log(' availableToBorrow:', Number(accountData[2]) / 1e6, 'USD')
|
||
console.log(' healthFactor:', Number(accountData[3]) / 1e4, '%')
|
||
|
||
console.log('\n 原始值:')
|
||
console.log(' [0]:', accountData[0].toString())
|
||
console.log(' [1]:', accountData[1].toString())
|
||
console.log(' [2]:', accountData[2].toString())
|
||
console.log(' [3]:', accountData[3].toString())
|
||
|
||
// 3. 诊断
|
||
console.log('\n--- 诊断 ---')
|
||
if (collateral > 0n && accountData[0] === 0n) {
|
||
console.log('⚠️ 问题发现:')
|
||
console.log(' - getUserCollateral 返回有值(', Number(collateral) / 1e18, 'YT-A)')
|
||
console.log(' - 但 getUserAccountData 返回总抵押价值为 0')
|
||
console.log(' 可能原因:')
|
||
console.log(' 1. 价格预言机返回 0(YT-A 价格未设置)')
|
||
console.log(' 2. getUserAccountData 函数逻辑错误')
|
||
console.log(' 3. 抵押品资产未在配置中激活')
|
||
} else if (collateral === 0n) {
|
||
console.log('✓ 抵押品余额为 0,这是正常的(如果之前交易失败)')
|
||
} else if (accountData[0] > 0n) {
|
||
console.log('✓ 一切正常,抵押品价值已正确计算')
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('\n✗ 调用失败:', error.message)
|
||
if (error.message.includes('Contract function')) {
|
||
console.log('\n可能原因:getUserAccountData 函数不存在或签名不匹配')
|
||
}
|
||
}
|
||
}
|
||
|
||
main()
|