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:
116
frontend/scripts/verify-current-borrow.js
Normal file
116
frontend/scripts/verify-current-borrow.js
Normal file
@@ -0,0 +1,116 @@
|
||||
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 LENDING_ABI = [
|
||||
{
|
||||
inputs: [{ name: 'account', type: 'address' }],
|
||||
name: 'getBalance',
|
||||
outputs: [{ name: '', type: 'int256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ name: 'account', type: 'address' }],
|
||||
name: 'borrowBalanceOf',
|
||||
outputs: [{ name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getBorrowRate',
|
||||
outputs: [{ name: '', type: 'uint64' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
]
|
||||
|
||||
async function main() {
|
||||
console.log('\n=== 验证当前借款状态 ===\n')
|
||||
console.log('用户:', USER)
|
||||
console.log('Lending 合约:', LENDING_PROXY)
|
||||
console.log()
|
||||
|
||||
// 获取账户余额
|
||||
const balance = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: LENDING_ABI,
|
||||
functionName: 'getBalance',
|
||||
args: [USER]
|
||||
})
|
||||
|
||||
// 获取借款余额
|
||||
const borrowBalance = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: LENDING_ABI,
|
||||
functionName: 'borrowBalanceOf',
|
||||
args: [USER]
|
||||
})
|
||||
|
||||
// 获取借款利率
|
||||
const borrowRate = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: LENDING_ABI,
|
||||
functionName: 'getBorrowRate'
|
||||
})
|
||||
|
||||
console.log('=== 账户状态 ===')
|
||||
console.log()
|
||||
console.log('getBalance() 返回值:', balance.toString())
|
||||
if (balance > 0) {
|
||||
console.log(' → 用户有存款:', Number(balance) / 1e6, 'USDC')
|
||||
} else if (balance < 0) {
|
||||
console.log(' → 用户有负余额(债务):', Number(-balance) / 1e6, 'USDC')
|
||||
} else {
|
||||
console.log(' → 用户余额为 0')
|
||||
}
|
||||
console.log()
|
||||
|
||||
console.log('borrowBalanceOf() 返回值:', borrowBalance.toString())
|
||||
console.log(' → 借款金额:', Number(borrowBalance) / 1e6, 'USDC')
|
||||
console.log()
|
||||
|
||||
console.log('=== 利息信息 ===')
|
||||
console.log()
|
||||
console.log('借款年化利率 (APY):', (Number(borrowRate) / 1e18 * 100).toFixed(2), '%')
|
||||
console.log()
|
||||
|
||||
// 分析结果
|
||||
console.log('=== 分析 ===')
|
||||
console.log()
|
||||
|
||||
if (borrowBalance > 0n) {
|
||||
console.log('✓ 用户确实有借款!')
|
||||
console.log()
|
||||
console.log('借款金额:', Number(borrowBalance) / 1e6, 'USDC')
|
||||
console.log()
|
||||
|
||||
if (balance === 0n) {
|
||||
console.log('余额状态: balance = 0,这意味着:')
|
||||
console.log(' - 用户之前可能有存款')
|
||||
console.log(' - withdraw 金额超过了存款')
|
||||
console.log(' - 超出部分形成了债务')
|
||||
console.log()
|
||||
console.log('这正是 Compound V3 的设计:')
|
||||
console.log(' withdraw(amount) 会:')
|
||||
console.log(' 1. 优先从存款中扣除')
|
||||
console.log(' 2. 存款不足时,自动创建债务')
|
||||
}
|
||||
|
||||
console.log()
|
||||
console.log('用户需要归还的总额:', Number(borrowBalance) / 1e6, 'USDC')
|
||||
console.log('(注意:每秒都在计息,实际金额会略高)')
|
||||
} else {
|
||||
console.log('✗ 用户当前没有借款')
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user