2024-06-07 22:00:14 +00:00
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
from loguru import logger
|
|
|
|
from typing import Any, Optional, Dict
|
|
|
|
from web3.types import ChecksumAddress
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_abi(address: ChecksumAddress, headers: Optional[Dict[str, Any]] = None,
|
2024-06-08 18:27:18 +00:00
|
|
|
params: Optional[Dict[str, Any]] = None, key: Optional[str] = None) -> Optional[Dict[str, Any]]:
|
|
|
|
url = f'https://api.etherscan.io/api?module=contract&action=getabi&address={address}&apikey={key}'
|
2024-06-07 22:00:14 +00:00
|
|
|
response = requests.get(url, headers=headers, params=params)
|
|
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
|
|
|
|
|
|
|
# Check for error in the response
|
|
|
|
if data['status'] == '0':
|
|
|
|
logger.error(f"Error fetching ABI: {data.get('result')}")
|
|
|
|
return None
|
|
|
|
|
|
|
|
return json.loads(data['result'])
|
|
|
|
|
|
|
|
|
|
|
|
def load_config(path: str) -> dict:
|
|
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
|
|
return json.loads(f.read())
|
2024-06-08 20:31:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def format_matrix_alert(token0: dict, token1: dict) -> str:
|
|
|
|
return f"""
|
|
|
|
🚨 New Uniswap Pair Alert 🚨\n
|
|
|
|
🌐 **Asset Pair:** [{token0['name']}](https://etherscan.io/token/{token0['address']}) + [{token1['name']}](https://etherscan.io/token/{token1['address']})\n
|
|
|
|
🏠 **Network:** ETH
|
|
|
|
"""
|