- 新增 ARB Sepolia + BNB Testnet 多链支持 - 添加 LendingPanel 借贷系统组件 - 添加 LendingAdminPanel 管理面板 - 添加 USDCPanel USDC 操作组件 - 添加 HoldersPanel 持有人信息组件 - 添加 AutoTestPanel 自动化测试组件 - 重构 LP 组件为模块化结构 (LP/) - 添加多个调试和测试脚本 - 修复 USDC 精度动态配置 - 优化合约配置支持多链切换 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
170 lines
4.8 KiB
JavaScript
170 lines
4.8 KiB
JavaScript
import { createPublicClient, http, parseUnits, 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_PROXY = getAddress('0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D')
|
|
const YT_A = getAddress('0x97204190B35D9895a7a47aa7BaC61ac08De3cF05')
|
|
const USDC = getAddress('0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d')
|
|
const USER = getAddress('0xa013422A5918CD099c63c8CC35283EACa99a705d')
|
|
|
|
const LENDING_ABI = [
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'account', type: 'address' }
|
|
],
|
|
name: 'borrowBalanceOf',
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'account', type: 'address' }
|
|
],
|
|
name: 'balanceOf',
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'account', type: 'address' },
|
|
{ internalType: 'address', name: 'asset', type: 'address' }
|
|
],
|
|
name: 'collateralBalanceOf',
|
|
outputs: [{ internalType: 'uint128', name: '', type: 'uint128' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'baseToken',
|
|
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'baseMinForRewards',
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'baseBorrowMin',
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
}
|
|
]
|
|
|
|
const ERC20_ABI = [
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'account', type: 'address' }
|
|
],
|
|
name: 'balanceOf',
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
},
|
|
{
|
|
inputs: [
|
|
{ internalType: 'address', name: 'owner', type: 'address' },
|
|
{ internalType: 'address', name: 'spender', type: 'address' }
|
|
],
|
|
name: 'allowance',
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
stateMutability: 'view',
|
|
type: 'function'
|
|
}
|
|
]
|
|
|
|
async function main() {
|
|
console.log('\n检查用户账户状态...\n')
|
|
console.log('用户地址:', USER)
|
|
|
|
try {
|
|
// 检查 YT-A 余额和授权
|
|
const ytBalance = await client.readContract({
|
|
address: YT_A,
|
|
abi: ERC20_ABI,
|
|
functionName: 'balanceOf',
|
|
args: [USER]
|
|
})
|
|
|
|
const ytAllowance = await client.readContract({
|
|
address: YT_A,
|
|
abi: ERC20_ABI,
|
|
functionName: 'allowance',
|
|
args: [USER, LENDING_PROXY]
|
|
})
|
|
|
|
console.log('\n=== YT-A 代币状态 ===')
|
|
console.log('钱包余额:', Number(ytBalance) / 1e18, 'YT-A')
|
|
console.log('授权额度:', Number(ytAllowance) / 1e18, 'YT-A')
|
|
console.log('想要存入:', 10, 'YT-A')
|
|
console.log('余额足够:', Number(ytBalance) >= 10e18 ? '✓' : '✗')
|
|
console.log('授权足够:', Number(ytAllowance) >= 10e18 ? '✓' : '✗')
|
|
|
|
// 检查 USDC 余额
|
|
const usdcBalance = await client.readContract({
|
|
address: USDC,
|
|
abi: ERC20_ABI,
|
|
functionName: 'balanceOf',
|
|
args: [USER]
|
|
})
|
|
|
|
console.log('\n=== USDC 代币状态 ===')
|
|
console.log('USDC 余额:', Number(usdcBalance) / 1e6, 'USDC')
|
|
|
|
// 检查 Lending 账户状态
|
|
const baseBalance = await client.readContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'balanceOf',
|
|
args: [USER]
|
|
})
|
|
|
|
const borrowBalance = await client.readContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'borrowBalanceOf',
|
|
args: [USER]
|
|
})
|
|
|
|
const collateralBalance = await client.readContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'collateralBalanceOf',
|
|
args: [USER, YT_A]
|
|
})
|
|
|
|
console.log('\n=== Lending 账户状态 ===')
|
|
console.log('供应余额 (USDC):', Number(baseBalance) / 1e6, 'USDC')
|
|
console.log('借款余额 (USDC):', Number(borrowBalance) / 1e6, 'USDC')
|
|
console.log('抵押品余额 (YT-A):', Number(collateralBalance) / 1e18, 'YT-A')
|
|
|
|
// 检查合约参数
|
|
const baseBorrowMin = await client.readContract({
|
|
address: LENDING_PROXY,
|
|
abi: LENDING_ABI,
|
|
functionName: 'baseBorrowMin'
|
|
})
|
|
|
|
console.log('\n=== 合约参数 ===')
|
|
console.log('最小借款额:', Number(baseBorrowMin) / 1e6, 'USDC')
|
|
|
|
} catch (error) {
|
|
console.error('✗ 检查失败:', error.message)
|
|
console.error('详细错误:', error)
|
|
}
|
|
}
|
|
|
|
main()
|