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:
134
frontend/scripts/test-correct-function-names.js
Normal file
134
frontend/scripts/test-correct-function-names.js
Normal file
@@ -0,0 +1,134 @@
|
||||
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')
|
||||
|
||||
async function main() {
|
||||
console.log('\n测试合约文档中的正确函数名\n')
|
||||
console.log('合约:', LENDING_PROXY)
|
||||
console.log('用户:', USER)
|
||||
console.log('抵押品:', YT_A)
|
||||
console.log()
|
||||
|
||||
// 1. 测试 getCollateral(正确的函数名)
|
||||
console.log('=== 1. getCollateral(account, asset) ===')
|
||||
try {
|
||||
const collateral = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [{
|
||||
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'
|
||||
}],
|
||||
functionName: 'getCollateral',
|
||||
args: [USER, YT_A]
|
||||
})
|
||||
console.log('✓ 成功!')
|
||||
console.log(' 抵押品余额:', Number(collateral) / 1e18, 'YT-A')
|
||||
console.log(' 原始值:', collateral.toString())
|
||||
} catch (error) {
|
||||
console.log('✗ 失败:', error.message.split('\n')[0])
|
||||
}
|
||||
|
||||
// 2. 测试 getBalance(用户USDC余额)
|
||||
console.log('\n=== 2. getBalance(account) ===')
|
||||
try {
|
||||
const balance = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [{
|
||||
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
||||
name: 'getBalance',
|
||||
outputs: [{ internalType: 'int256', name: '', type: 'int256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'getBalance',
|
||||
args: [USER]
|
||||
})
|
||||
console.log('✓ 成功!')
|
||||
console.log(' USDC 余额:', Number(balance) / 1e6, 'USDC')
|
||||
console.log(' 原始值:', balance.toString())
|
||||
} catch (error) {
|
||||
console.log('✗ 失败:', error.message.split('\n')[0])
|
||||
}
|
||||
|
||||
// 3. 测试 borrowBalanceOf
|
||||
console.log('\n=== 3. borrowBalanceOf(account) ===')
|
||||
try {
|
||||
const borrowBalance = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [{
|
||||
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
||||
name: 'borrowBalanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'borrowBalanceOf',
|
||||
args: [USER]
|
||||
})
|
||||
console.log('✓ 成功!')
|
||||
console.log(' 借款余额:', Number(borrowBalance) / 1e6, 'USDC')
|
||||
} catch (error) {
|
||||
console.log('✗ 失败:', error.message.split('\n')[0])
|
||||
}
|
||||
|
||||
// 4. 测试系统函数
|
||||
console.log('\n=== 4. getTotalBorrow() ===')
|
||||
try {
|
||||
const totalBorrow = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [{
|
||||
inputs: [],
|
||||
name: 'getTotalBorrow',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'getTotalBorrow'
|
||||
})
|
||||
console.log('✓ 成功!')
|
||||
console.log(' 系统总借款:', Number(totalBorrow) / 1e6, 'USDC')
|
||||
} catch (error) {
|
||||
console.log('✗ 失败:', error.message.split('\n')[0])
|
||||
}
|
||||
|
||||
console.log('\n=== 5. 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(' 系统总供应:', Number(totalSupply) / 1e6, 'USDC')
|
||||
} catch (error) {
|
||||
console.log('✗ 失败:', error.message.split('\n')[0])
|
||||
}
|
||||
|
||||
console.log('\n=== 结论 ===')
|
||||
console.log('如果上面的函数都能工作,说明:')
|
||||
console.log('1. 合约使用的是文档中的函数名(getCollateral 等)')
|
||||
console.log('2. 前端 ABI 需要更新为文档中的正确函数名')
|
||||
console.log('3. getUserCollateral 和 getUserAccountData 不存在于合约中\n')
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user