- 新增 ARB Sepolia + BNB Testnet 多链支持 - 添加 LendingPanel 借贷系统组件 - 添加 LendingAdminPanel 管理面板 - 添加 USDCPanel USDC 操作组件 - 添加 HoldersPanel 持有人信息组件 - 添加 AutoTestPanel 自动化测试组件 - 重构 LP 组件为模块化结构 (LP/) - 添加多个调试和测试脚本 - 修复 USDC 精度动态配置 - 优化合约配置支持多链切换 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
118 lines
3.6 KiB
JavaScript
118 lines
3.6 KiB
JavaScript
import { createPublicClient, http, parseEther } 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_PROXY = '0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D'
|
|
const YT_A = '0x97204190B35D9895a7a47aa7BaC61ac08De3cF05'
|
|
const USDC = '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d'
|
|
const USER = '0xa013422A5918CD099C63c8CC35283EACa99a705d'
|
|
|
|
const LENDING_ABI = [
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'asset', type: 'address' },
|
|
{ internalType: 'uint256', name: 'amount', type: 'uint256' }
|
|
],
|
|
name: 'supplyCollateral',
|
|
outputs: [],
|
|
stateMutability: 'nonpayable',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'asset', type: 'address' }
|
|
],
|
|
name: 'getAssetInfo',
|
|
outputs: [
|
|
{ internalType: 'uint8', name: 'offset', type: 'uint8' },
|
|
{ internalType: 'address', name: 'priceFeed', type: 'address' },
|
|
{ internalType: 'uint64', name: 'scale', type: 'uint64' },
|
|
{ internalType: 'uint64', name: 'borrowCollateralFactor', type: 'uint64' },
|
|
{ internalType: 'uint64', name: 'liquidateCollateralFactor', type: 'uint64' },
|
|
{ internalType: 'uint64', name: 'liquidationFactor', type: 'uint64' },
|
|
{ internalType: 'uint128', name: 'supplyCap', type: 'uint128' }
|
|
],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'baseToken',
|
|
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
}
|
|
]
|
|
|
|
async function main() {
|
|
console.log('\n模拟 supplyCollateral 调用...\n')
|
|
|
|
try {
|
|
// 先检查 Lending 合约能否读取到配置
|
|
console.log('=== 检查 Lending 合约状态 ===')
|
|
|
|
const baseToken = await client.readContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'baseToken'
|
|
})
|
|
|
|
console.log('Lending.baseToken:', baseToken)
|
|
console.log('是否为 USDC:', baseToken.toLowerCase() === USDC.toLowerCase() ? '✓' : '✗')
|
|
|
|
// 检查资产信息
|
|
try {
|
|
const assetInfo = await client.readContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'getAssetInfo',
|
|
args: [YT_A]
|
|
})
|
|
|
|
console.log('\nLending.getAssetInfo(YT-A):')
|
|
console.log(' borrowCollateralFactor:', assetInfo[3].toString())
|
|
console.log(' liquidateCollateralFactor:', assetInfo[4].toString())
|
|
console.log(' supplyCap:', assetInfo[6].toString())
|
|
} catch (e) {
|
|
console.log('\n✗ getAssetInfo 失败:', e.shortMessage || e.message)
|
|
}
|
|
|
|
// 尝试模拟调用
|
|
console.log('\n=== 模拟 supplyCollateral 调用 ===')
|
|
const amount = parseEther('10')
|
|
|
|
try {
|
|
await client.simulateContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'supplyCollateral',
|
|
args: [YT_A, amount],
|
|
account: USER
|
|
})
|
|
console.log('✓ 模拟成功!理论上应该可以执行')
|
|
} catch (error) {
|
|
console.log('✗ 模拟失败:')
|
|
console.log(' 错误类型:', error.name)
|
|
console.log(' 错误信息:', error.shortMessage || error.message)
|
|
|
|
if (error.cause) {
|
|
console.log('\n详细错误:')
|
|
console.log(' ', error.cause.message || error.cause)
|
|
}
|
|
|
|
if (error.data) {
|
|
console.log('\n错误数据:', error.data)
|
|
}
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('\n意外错误:', error.message)
|
|
}
|
|
}
|
|
|
|
main()
|