Skip to content

Commit 9f22e9b

Browse files
Add proxy implementation address to Contract Metadata
1 parent 76489e9 commit 9f22e9b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

safe_eth/eth/clients/contract_metadata.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ class ContractMetadata:
77
name: Optional[str]
88
abi: List[Dict[str, Any]]
99
partial_match: bool
10+
implementation: Optional[str] = None

safe_eth/eth/clients/etherscan_client.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,16 @@ def _process_contract_metadata(
359359
) -> Optional[ContractMetadata]:
360360
contract_name = contract_data["ContractName"]
361361
contract_abi = contract_data["ABI"]
362+
contract_proxy_implementation_address = (
363+
contract_data.get("Implementation") or None
364+
)
362365
if contract_abi:
363-
return ContractMetadata(contract_name, contract_abi, False)
366+
return ContractMetadata(
367+
contract_name,
368+
contract_abi,
369+
False,
370+
contract_proxy_implementation_address,
371+
)
364372
return None
365373

366374
def get_contract_metadata(

safe_eth/eth/tests/clients/test_etherscan_client_v2.py

+16
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,29 @@ def test_etherscan_get_abi(self):
3636
)
3737
self.assertEqual(contract_metadata.name, "GnosisSafe")
3838
self.assertEqual(contract_metadata.abi, safe_master_copy_abi)
39+
self.assertIsNone(contract_metadata.implementation)
3940

4041
random_address = "0xaE32496491b53841efb51829d6f886387708F99a"
4142
self.assertIsNone(etherscan_api.get_contract_abi(random_address))
4243
self.assertIsNone(etherscan_api.get_contract_metadata(random_address))
4344
except EtherscanRateLimitError:
4445
self.skipTest("Etherscan rate limit reached")
4546

47+
def test_etherscan_get_contract_metadata(self):
48+
try:
49+
etherscan_api = self.get_etherscan_api(EthereumNetwork.MAINNET)
50+
proxy_address = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
51+
52+
contract_metadata = etherscan_api.get_contract_metadata(proxy_address)
53+
self.assertEqual(contract_metadata.name, "FiatTokenProxy")
54+
self.assertEqual(
55+
contract_metadata.implementation,
56+
"0x43506849d7c04f9138d1a2050bbf3a0c054402dd",
57+
)
58+
59+
except EtherscanRateLimitError:
60+
self.skipTest("Etherscan rate limit reached")
61+
4662
def test_is_supported_network(self):
4763
try:
4864
self.assertTrue(

0 commit comments

Comments
 (0)