Skip to content

Commit 1cf1f8d

Browse files
Fix open zeppelin proxy detection (#155)
* Fix open zeppelin proxy detection * Remove zero check in detectUsingOpenZeppelinSlot
1 parent b6629e4 commit 1cf1f8d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/nextjs/utils/abi-ninja/proxyContracts.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UsePublicClientReturnType } from "wagmi";
33

44
const EIP_1967_LOGIC_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" as const;
55
const EIP_1967_BEACON_SLOT = "0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50" as const;
6-
// const OPEN_ZEPPELIN_IMPLEMENTATION_SLOT = "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3";
6+
const OPEN_ZEPPELIN_IMPLEMENTATION_SLOT = "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3" as const;
77
const EIP_1822_LOGIC_SLOT = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7" as const;
88
const EIP_1167_BEACON_METHODS = [
99
"0x5c60da1b00000000000000000000000000000000000000000000000000000000",
@@ -89,7 +89,21 @@ export const detectProxyTarget = async (proxyAddress: Address, client: UsePublic
8989
throw new Error("Beacon method calls failed");
9090
};
9191

92-
const detectionMethods = [detectUsingBytecode, detectUsingEIP1967LogicSlot, detectUsingEIP1967BeaconSlot];
92+
const detectUsingOpenZeppelinSlot = async () => {
93+
const implementationAddr = await client.getStorageAt({
94+
address: proxyAddress,
95+
slot: OPEN_ZEPPELIN_IMPLEMENTATION_SLOT,
96+
});
97+
const resolvedAddress = readAddress(implementationAddr);
98+
return resolvedAddress;
99+
};
100+
101+
const detectionMethods = [
102+
detectUsingBytecode,
103+
detectUsingEIP1967LogicSlot,
104+
detectUsingEIP1967BeaconSlot,
105+
detectUsingOpenZeppelinSlot,
106+
];
93107

94108
try {
95109
return await Promise.any(detectionMethods.map(method => method()));

0 commit comments

Comments
 (0)