feat: 添加多链支持和 Lending 借贷系统
- 新增 ARB Sepolia + BNB Testnet 多链支持 - 添加 LendingPanel 借贷系统组件 - 添加 LendingAdminPanel 管理面板 - 添加 USDCPanel USDC 操作组件 - 添加 HoldersPanel 持有人信息组件 - 添加 AutoTestPanel 自动化测试组件 - 重构 LP 组件为模块化结构 (LP/) - 添加多个调试和测试脚本 - 修复 USDC 精度动态配置 - 优化合约配置支持多链切换 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
107
frontend/scripts/debug-contract-view-functions.js
Normal file
107
frontend/scripts/debug-contract-view-functions.js
Normal file
@@ -0,0 +1,107 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user