Files
Heyue_test/frontend/scripts/check-configurator-setup.js

79 lines
2.7 KiB
JavaScript
Raw Normal View History

import { createPublicClient, http, parseAbi } from 'viem';
import { arbitrumSepolia } from 'viem/chains';
const CONFIGURATOR_ADDRESS = '0x488409CE9A3Fcd8EbD373dCb7e025cF8AB96fcdc';
const LENDING_PROXY = '0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D';
// 扩展的 ABI包含可能的其他函数
const CONFIGURATOR_ABI = parseAbi([
'function owner() view returns (address)',
'function lending() view returns (address)',
'function lendingContract() view returns (address)',
'function getLending() view returns (address)',
'function setLending(address) external',
'function initialize(address) external',
'function collateralConfigs(address) view returns (bool, uint256, uint256, uint256)'
]);
const publicClient = createPublicClient({
chain: arbitrumSepolia,
transport: http('https://sepolia-rollup.arbitrum.io/rpc')
});
async function checkSetup() {
console.log('🔍 检查 Configurator 设置\n');
// 尝试读取lending地址可能有不同的函数名
const possibleGetters = ['lending', 'lendingContract', 'getLending'];
for (const getter of possibleGetters) {
try {
console.log(`尝试调用 ${getter}()...`);
const lendingAddr = await publicClient.readContract({
address: CONFIGURATOR_ADDRESS,
abi: CONFIGURATOR_ABI,
functionName: getter
});
console.log(`✅ 找到! ${getter}() = ${lendingAddr}`);
console.log(` 期望地址: ${LENDING_PROXY}`);
console.log(` 匹配: ${lendingAddr.toLowerCase() === LENDING_PROXY.toLowerCase() ? '✅' : '❌'}\n`);
if (lendingAddr.toLowerCase() !== LENDING_PROXY.toLowerCase()) {
console.log('⚠️ 警告: Lending 地址不匹配!');
console.log('💡 可能需要调用 setLending() 来设置正确的地址\n');
}
return;
} catch (error) {
console.log(`${getter}() 不存在或调用失败\n`);
}
}
console.log('💡 建议:');
console.log(' 1. Configurator 可能需要先通过 initialize() 或 setLending() 设置 Lending 合约地址');
console.log(' 2. 检查合约源码或部署脚本中的初始化步骤');
console.log(' 3. 可能需要 Lending owner 先在 Configurator 中注册\n');
// 检查是否有其他状态变量
console.log('🔍 尝试读取其他可能的状态...\n');
// 尝试直接读取存储槽
try {
// Slot 0 通常是第一个状态变量
const slot0 = await publicClient.getStorageAt({
address: CONFIGURATOR_ADDRESS,
slot: '0x0'
});
console.log('Storage Slot 0:', slot0);
if (slot0 && slot0 !== '0x' + '0'.repeat(64)) {
const addr = '0x' + slot0.slice(-40);
console.log('可能的地址值:', addr);
}
} catch (error) {
console.log('无法读取存储槽');
}
}
checkSetup();