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:
122
frontend/scripts/check-interest-rates.js
Normal file
122
frontend/scripts/check-interest-rates.js
Normal file
@@ -0,0 +1,122 @@
|
||||
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 LENDING_ABI = [
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getBorrowRate',
|
||||
outputs: [{ internalType: 'uint64', name: '', type: 'uint64' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getSupplyRate',
|
||||
outputs: [{ internalType: 'uint64', name: '', type: 'uint64' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getUtilization',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
]
|
||||
|
||||
async function main() {
|
||||
console.log('\n检查利率和使用率...\n')
|
||||
|
||||
try {
|
||||
// 1. 获取借款利率
|
||||
const borrowRate = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: LENDING_ABI,
|
||||
functionName: 'getBorrowRate'
|
||||
})
|
||||
console.log('=== getBorrowRate ===')
|
||||
console.log('原始值:', borrowRate.toString())
|
||||
console.log('类型: uint64')
|
||||
console.log()
|
||||
|
||||
// Compound V3 利率通常是每秒利率,精度 1e18
|
||||
// APY = (1 + ratePerSecond)^(365*24*60*60) - 1
|
||||
// 简化近似:APY ≈ ratePerSecond * secondsPerYear * 100%
|
||||
const secondsPerYear = 365 * 24 * 60 * 60
|
||||
|
||||
// 如果是 1e18 精度的每秒利率
|
||||
if (borrowRate > 0n) {
|
||||
const apyE18 = Number(borrowRate) * secondsPerYear / 1e18
|
||||
console.log('假设精度 1e18 (每秒利率):')
|
||||
console.log(' 每秒利率:', Number(borrowRate) / 1e18)
|
||||
console.log(' 年化利率 (APY):', apyE18.toFixed(2), '%')
|
||||
console.log()
|
||||
|
||||
// 如果是 1e16 精度(百分比形式)
|
||||
const apyE16 = Number(borrowRate) * secondsPerYear / 1e16
|
||||
console.log('假设精度 1e16:')
|
||||
console.log(' 年化利率 (APY):', apyE16.toFixed(2), '%')
|
||||
console.log()
|
||||
|
||||
// 如果是 1e4 精度(basis points)
|
||||
const apyE4 = Number(borrowRate) / 1e4
|
||||
console.log('假设精度 1e4 (basis points):')
|
||||
console.log(' 年化利率 (APY):', apyE4.toFixed(2), '%')
|
||||
console.log()
|
||||
}
|
||||
|
||||
// 2. 获取存款利率
|
||||
const supplyRate = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: LENDING_ABI,
|
||||
functionName: 'getSupplyRate'
|
||||
})
|
||||
console.log('=== getSupplyRate ===')
|
||||
console.log('原始值:', supplyRate.toString())
|
||||
console.log()
|
||||
|
||||
if (supplyRate > 0n) {
|
||||
const apyE18 = Number(supplyRate) * secondsPerYear / 1e18
|
||||
console.log('假设精度 1e18 (每秒利率):')
|
||||
console.log(' 年化利率 (APY):', apyE18.toFixed(2), '%')
|
||||
console.log()
|
||||
}
|
||||
|
||||
// 3. 获取使用率
|
||||
const utilization = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: LENDING_ABI,
|
||||
functionName: 'getUtilization'
|
||||
})
|
||||
console.log('=== getUtilization ===')
|
||||
console.log('原始值:', utilization.toString())
|
||||
console.log()
|
||||
|
||||
if (utilization > 0n) {
|
||||
// Compound V3 使用率通常是 1e18 精度
|
||||
const utilizationPercent = Number(utilization) / 1e18 * 100
|
||||
console.log('假设精度 1e18:')
|
||||
console.log(' 使用率:', utilizationPercent.toFixed(2), '%')
|
||||
console.log()
|
||||
|
||||
// 如果是 1e4 精度
|
||||
const utilizationE4 = Number(utilization) / 1e4
|
||||
console.log('假设精度 1e4:')
|
||||
console.log(' 使用率:', utilizationE4.toFixed(2), '%')
|
||||
console.log()
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('查询失败:', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user