import * as Proxy from '@tevm/voltaire/Proxy';
import { eth_getStorageAt } from '@tevm/voltaire/rpc';
async function analyzeProxy(address: string) {
const [implementation, admin, beacon] = await Promise.all([
eth_getStorageAt(address, Proxy.IMPLEMENTATION_SLOT),
eth_getStorageAt(address, Proxy.ADMIN_SLOT),
eth_getStorageAt(address, Proxy.BEACON_SLOT)
]);
const hasImpl = implementation !== '0x' + '00'.repeat(32);
const hasAdmin = admin !== '0x' + '00'.repeat(32);
const hasBeacon = beacon !== '0x' + '00'.repeat(32);
if (hasImpl && hasAdmin) {
return { type: 'Transparent Proxy', implementation, admin };
} else if (hasImpl) {
return { type: 'UUPS Proxy', implementation };
} else if (hasBeacon) {
return { type: 'Beacon Proxy', beacon };
}
return { type: 'Not a proxy' };
}