Files
Heyue_test/frontend/scripts/check-usdc-supply-history.js
Sofio 5cb64f881e 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>
2026-01-26 23:32:29 +08:00

159 lines
5.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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_PROXY = getAddress('0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D')
const USDC = getAddress('0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d')
const USER = getAddress('0xa013422A5918CD099C63c8CC35283EACa99a705d')
const TRANSFER_EVENT = {
type: 'event',
name: 'Transfer',
inputs: [
{ indexed: true, name: 'from', type: 'address' },
{ indexed: true, name: 'to', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' }
]
}
async function main() {
console.log('\n检查 USDC 供应/提取历史...\n')
console.log('用户:', USER)
console.log('Lending 合约:', LENDING_PROXY)
console.log()
const latestBlock = await client.getBlockNumber()
console.log('最新区块:', latestBlock)
console.log('查询范围: 最近 10000 个区块\n')
try {
// 1. 检查用户转入 Lending 的 USDCsupply 操作)
console.log('=== 1. USDC 转入 Lending 合约Supply===')
const logsToLending = await client.getLogs({
address: USDC,
event: TRANSFER_EVENT,
args: {
from: USER,
to: LENDING_PROXY
},
fromBlock: latestBlock - 10000n,
toBlock: latestBlock
})
if (logsToLending.length > 0) {
console.log(`找到 ${logsToLending.length} 笔转入记录:\n`)
let totalSupplied = 0n
logsToLending.forEach((log, i) => {
const { value } = log.args
totalSupplied += value
console.log(`${i + 1}. 区块 ${log.blockNumber}`)
console.log(` 交易: ${log.transactionHash}`)
console.log(` 数量: ${Number(value) / 1e6} USDC`)
console.log()
})
console.log(`总存入: ${Number(totalSupplied) / 1e6} USDC\n`)
} else {
console.log('未找到转入记录\n')
}
// 2. 检查 Lending 转给用户的 USDCwithdraw 操作)
console.log('=== 2. USDC 从 Lending 转出Withdraw===')
const logsFromLending = await client.getLogs({
address: USDC,
event: TRANSFER_EVENT,
args: {
from: LENDING_PROXY,
to: USER
},
fromBlock: latestBlock - 10000n,
toBlock: latestBlock
})
if (logsFromLending.length > 0) {
console.log(`找到 ${logsFromLending.length} 笔转出记录:\n`)
let totalWithdrawn = 0n
logsFromLending.forEach((log, i) => {
const { value } = log.args
totalWithdrawn += value
console.log(`${i + 1}. 区块 ${log.blockNumber}`)
console.log(` 交易: ${log.transactionHash}`)
console.log(` 数量: ${Number(value) / 1e6} USDC`)
console.log()
})
console.log(`总提取: ${Number(totalWithdrawn) / 1e6} USDC\n`)
} else {
console.log('未找到转出记录\n')
}
// 3. 获取当前余额
console.log('=== 3. 当前状态 ===')
const LENDING_ABI = [
{
inputs: [{ name: 'account', type: 'address' }],
name: 'getBalance',
outputs: [{ name: '', type: 'int256' }],
stateMutability: 'view',
type: 'function'
},
{
inputs: [{ name: 'account', type: 'address' }],
name: 'borrowBalanceOf',
outputs: [{ name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
}
]
const balance = await client.readContract({
address: LENDING_PROXY,
abi: LENDING_ABI,
functionName: 'getBalance',
args: [USER]
})
const borrowBalance = await client.readContract({
address: LENDING_PROXY,
abi: LENDING_ABI,
functionName: 'borrowBalanceOf',
args: [USER]
})
console.log('USDC 余额(在 Lending 中):', Number(balance) / 1e6, 'USDC')
console.log(' 原始值:', balance.toString())
console.log(' 正数 = 存款,负数 = 借款')
console.log()
console.log('借款余额:', Number(borrowBalance) / 1e6, 'USDC')
console.log()
// 4. 分析
console.log('=== 分析 ===')
if (balance > 0) {
console.log('⚠️ 你当前有存款!')
console.log(` 存款金额: ${Number(balance) / 1e6} USDC`)
console.log()
console.log('这意味着:')
console.log(` - 如果你借款 ≤ ${Number(balance) / 1e6} USDC只是提取存款`)
console.log(` - 只有借款 > ${Number(balance) / 1e6} USDC才会产生债务`)
console.log()
console.log('建议:')
console.log(' 1. 如果要真正借款,请借款金额大于当前存款')
console.log(` 例如:借款 ${Number(balance) / 1e6 + 100} USDC`)
console.log(' 2. 或者先提取所有存款,再借款')
} else if (balance < 0) {
console.log('✓ 你有借款!')
console.log(` 借款金额: ${-Number(balance) / 1e6} USDC`)
} else {
console.log('✓ 你没有存款也没有借款')
}
} catch (error) {
console.error('查询失败:', error.message)
}
}
main()