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>
This commit is contained in:
119
frontend/scripts/check-compound-v3-storage.js
Normal file
119
frontend/scripts/check-compound-v3-storage.js
Normal file
@@ -0,0 +1,119 @@
|
||||
import { createPublicClient, http, getAddress, keccak256, toHex, pad, concat } 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 USER = getAddress('0xa013422A5918CD099C63c8CC35283EACa99a705d')
|
||||
const YT_A = getAddress('0x97204190B35D9895a7a47aa7BaC61ac08De3cF05')
|
||||
|
||||
// Compound V3 使用的公开状态变量
|
||||
const COMET_ABI = [
|
||||
{
|
||||
inputs: [
|
||||
{ name: 'account', type: 'address' },
|
||||
{ name: 'asset', type: 'address' }
|
||||
],
|
||||
name: 'userCollateral',
|
||||
outputs: [
|
||||
{
|
||||
components: [
|
||||
{ name: 'balance', type: 'uint128' },
|
||||
{ name: '_reserved', type: 'uint128' }
|
||||
],
|
||||
name: '',
|
||||
type: 'tuple'
|
||||
}
|
||||
],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ name: 'account', type: 'address' }],
|
||||
name: 'balanceOf',
|
||||
outputs: [{ name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ name: 'account', type: 'address' }],
|
||||
name: 'borrowBalanceOf',
|
||||
outputs: [{ name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ name: 'account', type: 'address' },
|
||||
{ name: 'asset', type: 'address' }
|
||||
],
|
||||
name: 'collateralBalanceOf',
|
||||
outputs: [{ name: '', type: 'uint128' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
]
|
||||
|
||||
async function main() {
|
||||
console.log('\n检查 Compound V3 存储结构\n')
|
||||
console.log('合约:', LENDING_PROXY)
|
||||
console.log('用户:', USER)
|
||||
console.log('抵押品:', YT_A)
|
||||
console.log()
|
||||
|
||||
// 测试 Compound V3 原生函数
|
||||
for (const func of COMET_ABI) {
|
||||
console.log(`--- ${func.name} ---`)
|
||||
try {
|
||||
let result
|
||||
if (func.name === 'userCollateral') {
|
||||
result = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [func],
|
||||
functionName: func.name,
|
||||
args: [USER, YT_A]
|
||||
})
|
||||
console.log('✓ 成功!')
|
||||
console.log(' balance:', result.balance.toString(), '(', Number(result.balance) / 1e18, 'YT-A )')
|
||||
console.log(' _reserved:', result._reserved.toString())
|
||||
} else if (func.name === 'collateralBalanceOf') {
|
||||
result = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [func],
|
||||
functionName: func.name,
|
||||
args: [USER, YT_A]
|
||||
})
|
||||
console.log('✓ 成功:', result.toString(), '(', Number(result) / 1e18, 'YT-A )')
|
||||
} else if (func.name === 'balanceOf') {
|
||||
result = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [func],
|
||||
functionName: func.name,
|
||||
args: [USER]
|
||||
})
|
||||
console.log('✓ 成功:', result.toString(), '(', Number(result) / 1e6, 'USDC )')
|
||||
} else {
|
||||
result = await client.readContract({
|
||||
address: LENDING_PROXY,
|
||||
abi: [func],
|
||||
functionName: func.name,
|
||||
args: [USER]
|
||||
})
|
||||
console.log('✓ 成功:', result.toString())
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('✗ 失败:', error.message.split('\n')[0])
|
||||
}
|
||||
console.log()
|
||||
}
|
||||
|
||||
console.log('=== 结论 ===')
|
||||
console.log('如果上面的 Compound V3 原生函数能工作,')
|
||||
console.log('说明合约使用了 Compound V3 的数据结构,')
|
||||
console.log('前端应该调用这些函数而不是自定义的 getUserCollateral 等。\n')
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user