Files
Heyue_test/frontend/scripts/verify-apy-calculation.js
Sofio 5cb64f881e 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>
2026-01-26 23:32:29 +08:00

54 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 验证 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()