2727 }
2828}
2929
30+
3031def get_contract_abi (contract_address : str ) -> dict :
3132 """Get the ABI for a contract from the Chain Explorer API."""
3233 params = {"module" : "contract" , "action" : "getabi" , "address" : contract_address }
@@ -43,12 +44,14 @@ def get_contract_abi(contract_address: str) -> dict:
4344 logger .exception ("Error fetching ABI for contract" )
4445 sys .exit (1 )
4546
47+
4648def get_feed_id (category : str , feed_name : str ) -> str :
4749 """Convert a feed name to its structured encoded feed ID."""
4850 hex_feed_name = feed_name .encode ("utf-8" ).hex ()
4951 padded_hex_string = (category + hex_feed_name ).ljust (42 , "0" )
5052 return f"0x{ padded_hex_string } "
5153
54+
5255def write_data_to_file (file_path : Path , data : list [dict ]) -> None :
5356 """Write a markdown table to a file."""
5457 try :
@@ -58,6 +61,7 @@ def write_data_to_file(file_path: Path, data: list[dict]) -> None:
5861 except OSError :
5962 logger .exception ("Failed to write to %s: " , file_path )
6063
64+
6165def read_data_from_file (file_path : Path ) -> list [dict ]:
6266 """Write a markdown table to a file."""
6367 try :
@@ -71,6 +75,7 @@ def read_data_from_file(file_path: Path) -> list[dict]:
7175 else :
7276 return data
7377
78+
7479def get_coins_list (pages : list ) -> list [dict ]:
7580 """Get the top 500 coins from CoinGecko."""
7681 cg = CoinGeckoAPI ()
@@ -84,12 +89,14 @@ def get_coins_list(pages: list) -> list[dict]:
8489 else :
8590 return coins
8691
92+
8793def find_coin_by_symbol (coins : list [dict ], symbol : str ) -> dict | None :
8894 """Find a coin in the list by its symbol."""
8995 return next (
9096 (coin for coin in coins if coin ["symbol" ].lower () == symbol .lower ()), None
9197 )
9298
99+
93100def generate_feed_data (
94101 feed_names : list [str ],
95102 feed_risk : list [dict [str , int ]],
@@ -133,6 +140,7 @@ def generate_feed_data(
133140 data .append (feed_data )
134141 return data
135142
143+
136144if __name__ == "__main__" :
137145 logging .info ("Running Feed Table automation..." )
138146
0 commit comments