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()