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:
53
frontend/scripts/verify-apy-calculation.js
Normal file
53
frontend/scripts/verify-apy-calculation.js
Normal file
@@ -0,0 +1,53 @@
|
||||
// 验证 APY 计算逻辑
|
||||
|
||||
const borrowRatePerSecond = 14999999976144000n
|
||||
const secondsPerYear = BigInt(365 * 24 * 60 * 60) // 31536000
|
||||
|
||||
console.log('\n=== APY 计算验证 ===\n')
|
||||
|
||||
console.log('原始数据:')
|
||||
console.log(' borrowRatePerSecond:', borrowRatePerSecond.toString())
|
||||
console.log(' secondsPerYear:', secondsPerYear.toString())
|
||||
console.log()
|
||||
|
||||
// 方法1:错误的计算(之前的方式)
|
||||
const wrongAPY = Number(borrowRatePerSecond) / 10000
|
||||
console.log('❌ 错误计算(除以10000):')
|
||||
console.log(' APY:', wrongAPY.toFixed(2), '%')
|
||||
console.log(' = 1,499,999,997,614.40 %(明显错误)')
|
||||
console.log()
|
||||
|
||||
// 方法2:正确的计算
|
||||
// APY% = (ratePerSecond / 1e18) × secondsPerYear × 100
|
||||
const borrowAPY = (borrowRatePerSecond * secondsPerYear * BigInt(100)) / BigInt(10 ** 18)
|
||||
console.log('✅ 正确计算(Compound V3 格式):')
|
||||
console.log(' 每秒利率:', Number(borrowRatePerSecond) / 1e18)
|
||||
console.log(' 年化倍数 (1 + rate)^seconds ≈ rate × seconds:')
|
||||
console.log(' ', Number(borrowRatePerSecond) / 1e18, '× 31,536,000 =', Number(borrowRatePerSecond) * 31536000 / 1e18)
|
||||
console.log(' APY:', Number(borrowAPY).toFixed(2), '%')
|
||||
console.log()
|
||||
|
||||
// 详细计算步骤
|
||||
console.log('计算步骤:')
|
||||
console.log(' 1. borrowRatePerSecond × secondsPerYear × 100')
|
||||
console.log(' =', borrowRatePerSecond.toString(), '×', secondsPerYear.toString(), '× 100')
|
||||
const step1 = borrowRatePerSecond * secondsPerYear * BigInt(100)
|
||||
console.log(' =', step1.toString())
|
||||
console.log()
|
||||
console.log(' 2. 结果 ÷ 10^18')
|
||||
console.log(' =', step1.toString(), '÷ 1000000000000000000')
|
||||
console.log(' =', borrowAPY.toString())
|
||||
console.log()
|
||||
|
||||
console.log('最终结果: ', Number(borrowAPY).toFixed(2), '%')
|
||||
console.log()
|
||||
|
||||
// 验证使用率计算
|
||||
console.log('=== 使用率计算验证 ===\n')
|
||||
console.log('如果 utilizationRate = 0(当前没有借款)')
|
||||
const utilizationRate = 0n
|
||||
const utilizationPercent = utilizationRate > 0n
|
||||
? (utilizationRate * BigInt(100)) / BigInt(10 ** 18)
|
||||
: 0n
|
||||
console.log(' 使用率:', Number(utilizationPercent).toFixed(2), '%')
|
||||
console.log()
|
||||
Reference in New Issue
Block a user