- 新增 ARB Sepolia + BNB Testnet 多链支持 - 添加 LendingPanel 借贷系统组件 - 添加 LendingAdminPanel 管理面板 - 添加 USDCPanel USDC 操作组件 - 添加 HoldersPanel 持有人信息组件 - 添加 AutoTestPanel 自动化测试组件 - 重构 LP 组件为模块化结构 (LP/) - 添加多个调试和测试脚本 - 修复 USDC 精度动态配置 - 优化合约配置支持多链切换 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
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')
|
|
const USDC = getAddress('0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d')
|
|
|
|
const PRICE_FEED_ABI = [
|
|
{
|
|
inputs: [{ name: 'asset', type: 'address' }],
|
|
name: 'getPrice',
|
|
outputs: [{ name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [{ name: 'asset', type: 'address' }],
|
|
name: 'getAssetPrice',
|
|
outputs: [{ name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
}
|
|
]
|
|
|
|
async function testPrice(asset, name) {
|
|
console.log(`\n=== ${name} (${asset}) ===`)
|
|
|
|
// 尝试 getPrice
|
|
try {
|
|
const price1 = await client.readContract({
|
|
address: LENDING_PRICE_FEED,
|
|
abi: PRICE_FEED_ABI,
|
|
functionName: 'getPrice',
|
|
args: [asset]
|
|
})
|
|
console.log('✓ getPrice:', price1.toString(), '(', Number(price1) / 1e8, 'USD )')
|
|
} catch (error) {
|
|
console.log('✗ getPrice 失败:', error.message.split('\n')[0])
|
|
}
|
|
|
|
// 尝试 getAssetPrice
|
|
try {
|
|
const price2 = await client.readContract({
|
|
address: LENDING_PRICE_FEED,
|
|
abi: PRICE_FEED_ABI,
|
|
functionName: 'getAssetPrice',
|
|
args: [asset]
|
|
})
|
|
console.log('✓ getAssetPrice:', price2.toString(), '(', Number(price2) / 1e8, 'USD )')
|
|
} catch (error) {
|
|
console.log('✗ getAssetPrice 失败:', error.message.split('\n')[0])
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
console.log('检查价格预言机\n')
|
|
console.log('Price Feed 地址:', LENDING_PRICE_FEED)
|
|
|
|
await testPrice(YT_A, 'YT-A')
|
|
await testPrice(USDC, 'USDC')
|
|
|
|
console.log('\n=== 诊断 ===')
|
|
console.log('如果价格查询失败,这就是为什么 getUserAccountData 会 revert')
|
|
console.log('需要:')
|
|
console.log('1. 检查价格预言机合约是否正确部署')
|
|
console.log('2. 检查是否为 YT-A 设置了价格')
|
|
console.log('3. 可能需要手动调用 setPrice() 来设置价格')
|
|
}
|
|
|
|
main()
|