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:
110
frontend/scripts/check-price-decimals.js
Normal file
110
frontend/scripts/check-price-decimals.js
Normal file
@@ -0,0 +1,110 @@
|
||||
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_PRICE_FEED = getAddress('0xE82c7cB9CfA42D6eb7e443956b78f8290249c316')
|
||||
const YT_A = getAddress('0x97204190B35D9895a7a47aa7BaC61ac08De3cF05')
|
||||
|
||||
async function main() {
|
||||
console.log('\n检查价格精度\n')
|
||||
|
||||
try {
|
||||
// 检查 decimals
|
||||
const decimals = await client.readContract({
|
||||
address: LENDING_PRICE_FEED,
|
||||
abi: [{
|
||||
inputs: [],
|
||||
name: 'decimals',
|
||||
outputs: [{ name: '', type: 'uint8' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'decimals'
|
||||
})
|
||||
console.log('✓ decimals:', decimals)
|
||||
|
||||
const price = await client.readContract({
|
||||
address: LENDING_PRICE_FEED,
|
||||
abi: [{
|
||||
inputs: [{ name: 'asset', type: 'address' }],
|
||||
name: 'getPrice',
|
||||
outputs: [{ name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'getPrice',
|
||||
args: [YT_A]
|
||||
})
|
||||
|
||||
console.log('\nYT-A 价格:')
|
||||
console.log(' 原始值:', price.toString())
|
||||
console.log(' ÷ 1e8:', Number(price) / 1e8)
|
||||
console.log(' ÷ 1e18:', Number(price) / 1e18)
|
||||
console.log(' ÷ 1e', decimals, ':', Number(price) / (10 ** Number(decimals)))
|
||||
|
||||
// 如果价格是 1e22,可能是:
|
||||
// - 错误地设置为 1e30 的固定价格(Compound V3 使用 1e30 作为基准)
|
||||
// - 或者配置了错误的精度
|
||||
|
||||
if (price > 1e20) {
|
||||
console.log('\n⚠️ 警告:价格异常高!')
|
||||
console.log('可能原因:')
|
||||
console.log('1. 价格设置错误(使用了 1e30 而不是合适的精度)')
|
||||
console.log('2. 精度配置错误')
|
||||
console.log('\n建议:')
|
||||
console.log('如果 YT-A 应该价值 $1,价格应该设置为:')
|
||||
console.log(` - 如果精度是 8: ${1e8}`)
|
||||
console.log(` - 如果精度是 18: ${1e18}`)
|
||||
console.log(` - 如果使用 Compound V3 格式: ${1e18} (价格) * ${1e18} (精度) / (资产精度)`)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('✗ 查询失败:', error.message)
|
||||
console.log('\n尝试读取价格(无 decimals):')
|
||||
|
||||
try {
|
||||
const price = await client.readContract({
|
||||
address: LENDING_PRICE_FEED,
|
||||
abi: [{
|
||||
inputs: [{ name: 'asset', type: 'address' }],
|
||||
name: 'getPrice',
|
||||
outputs: [{ name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'getPrice',
|
||||
args: [YT_A]
|
||||
})
|
||||
console.log('价格:', price.toString())
|
||||
console.log('\n如果这个值是 1e30 数量级,说明使用了 Compound V3 的价格格式')
|
||||
console.log('Compound V3 价格 = (USD价格 * 1e', await getBaseScale(), ') / (10^资产精度)')
|
||||
} catch (e2) {
|
||||
console.error('仍然失败:', e2.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getBaseScale() {
|
||||
try {
|
||||
const scale = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [{
|
||||
inputs: [],
|
||||
name: 'baseScale',
|
||||
outputs: [{ name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}],
|
||||
functionName: 'baseScale'
|
||||
})
|
||||
return scale
|
||||
} catch {
|
||||
return '?'
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user