-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsnipegenius.py
94 lines (76 loc) · 3.05 KB
/
snipegenius.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# SnipeGenius 🥞 (PancakeSwap)
# Version: 1.5.3
# Developed by Fahd El Haraka ©
# Email: fahd@web3dev.ma
# Telegram: @thisiswhosthis
# Website: https://web3dev.ma
# GitHub: https://github.com/ELHARAKA
"""
© Copyright 2023-2024
Proprietary Software by Fahd El Haraka, 2023-2024.
Unauthorized use, duplication, modification, or distribution is strictly prohibited.
Contact fahd@web3dev.ma for permissions and inquiries.
"""
import json
import time
import requests
from config import logger, file_logger
MAX_RETRIES = 3
def perform_safety_check(tokentobuy, chain_id, min_safety_score):
from config import token_sniffer_api_key
base_url = "https://tokensniffer.com/api/v2/tokens/"
query_params = (
f"apikey={token_sniffer_api_key}&"
"include_metrics=true&"
"include_tests=false&"
"block_until_ready=true"
)
tokensniffer_url = f"{base_url}{chain_id}/{tokentobuy}?{query_params}"
first_iteration = True
retries = 0
while retries < MAX_RETRIES:
if first_iteration:
logger.info(f"Token Address: {tokentobuy}")
logger.info("Performing Safety Checks...")
first_iteration = False
try:
response = requests.get(tokensniffer_url)
response.raise_for_status()
data = json.loads(response.text)
if data.get('status') == 'ready':
score = data.get('score', 'N/A')
try:
float_score = float(score)
except ValueError:
logger.error(f"Score conversion failed: {score}%")
return False
is_safe = float_score >= min_safety_score
file_logger.info(f"Token Safety Score: {score}%")
if is_safe:
logger.info(f"Token is {score}% safe. Waiting 2 mins for another check.")
# Wait for 2 minutes before proceeding with the second check
time.sleep(120)
continue # Retry the safety check
return is_safe, score
else:
file_logger.info("Token safety score is pending. Retrying in 10 seconds.")
retries += 1
time.sleep(10)
except (requests.exceptions.RequestException, json.JSONDecodeError) as e:
sanitized_error = str(e).replace(token_sniffer_api_key, 'HIDDEN')
file_logger.error(f"Request error: {sanitized_error}. Retrying.")
retries += 1
time.sleep(10)
logger.error("Max retry limit hit; operation aborted. If this issue persists, please submit an issue request on GitHub.")
return False
def check_token_safety(tokentobuy, chain_id, min_safety_score):
score = 'N/A'
try:
time.sleep(10)
is_safety_valid, score = perform_safety_check(tokentobuy, chain_id, min_safety_score)
if is_safety_valid:
return True, score
return False, score
except Exception as e:
logger.error(f"Error in check_token_safety: {e}")
return False, score