56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
|
|
import { createPublicClient, http } from 'viem'
|
|||
|
|
import { arbitrumSepolia } from 'viem/chains'
|
|||
|
|
|
|||
|
|
const client = createPublicClient({
|
|||
|
|
chain: arbitrumSepolia,
|
|||
|
|
transport: http('https://api.zan.top/node/v1/arb/sepolia/baf84c429d284bb5b676cb8c9ca21c07')
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
const PRICE_FEED = '0xE82c7cB9CfA42D6eb7e443956b78f8290249c316'
|
|||
|
|
const YT_A = '0x97204190B35D9895a7a47aa7BaC61ac08De3cF05'
|
|||
|
|
|
|||
|
|
const PRICE_FEED_ABI = [
|
|||
|
|
{
|
|||
|
|
inputs: [
|
|||
|
|
{ internalType: 'address', name: 'asset', type: 'address' }
|
|||
|
|
],
|
|||
|
|
name: 'getPrice',
|
|||
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|||
|
|
stateMutability: 'view',
|
|||
|
|
type: 'function'
|
|||
|
|
}
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
async function main() {
|
|||
|
|
console.log('\n检查价格源...\n')
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const price = await client.readContract({
|
|||
|
|
address: PRICE_FEED,
|
|||
|
|
abi: PRICE_FEED_ABI,
|
|||
|
|
functionName: 'getPrice',
|
|||
|
|
args: [YT_A]
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
console.log('YT-A 地址:', YT_A)
|
|||
|
|
console.log('价格 (原始值):', price.toString())
|
|||
|
|
console.log('价格 (格式化):', Number(price) / 1e8, 'USD')
|
|||
|
|
|
|||
|
|
if (price === 0n) {
|
|||
|
|
console.log('\n✗ 错误: 价格为 0!')
|
|||
|
|
console.log(' 这会导致存入失败,因为合约无法计算抵押品价值')
|
|||
|
|
} else {
|
|||
|
|
console.log('\n✓ 价格正常')
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('\n✗ 读取价格失败:', error.message)
|
|||
|
|
console.log('\n可能的原因:')
|
|||
|
|
console.log(' 1. 价格源合约没有设置 YT-A 的价格')
|
|||
|
|
console.log(' 2. getPrice 函数不存在或签名不匹配')
|
|||
|
|
console.log(' 3. YT-A 地址在价格源中未注册')
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
main()
|