Commit 294f883a by lei

1

parent d6989f0b
import time
import json
import redis
import random
import aiohttp
import requests
import datetime
import numpy as np
from aredis import StrictRedis, ConnectionPool
uni256Max = 2 ** 256
......@@ -147,22 +143,6 @@ class RedisCon:
print("Redis lrem error:", e)
@staticmethod
def ex_data(key, v_time, value):
"""
redis setex
:param key:
:param v_time:
:param value:
:return:
"""
redis_con = redis.Redis(connection_pool=RedisConnSingleton())
try:
redis_con.setex(key, v_time, value)
except Exception as e:
print("Redis setex error:", e)
@staticmethod
def get_task_num(key):
"""
redis llen
......@@ -294,719 +274,6 @@ class Helper:
except Exception as e:
print("Redis lpop error:", e)
@staticmethod
async def save_hash_data(redis_key, key, value):
"""
aredis hset
:param redis_key:
:param key:
:param value:
:return:
"""
redis_con = StrictRedis(connection_pool=RedisConnectionPoolSingleton())
try:
await redis_con.hset(redis_key, key, value)
except Exception as e:
print("Redis hset error", e)
@staticmethod
async def del_hash_data(redis_key, key):
"""
aredis hdel
:param redis_key:
:param key:
:return:
"""
redis_con = StrictRedis(connection_pool=RedisConnectionPoolSingleton())
try:
await redis_con.hdel(redis_key, key)
except Exception as e:
print("Redis hdel error", e)
@staticmethod
async def get_string_value(name):
"""
aredis get
:param name:
:return:
"""
redis_con = StrictRedis(connection_pool=RedisConnectionPoolSingleton())
try:
data = await redis_con.get(name)
return data
except Exception as e:
print("Redis get error", e)
@staticmethod
async def ex_data(key, time, value):
"""
aredis setex
:param key:
:param time:
:param value:
:return:
"""
redis_con = StrictRedis(connection_pool=RedisConnectionPoolSingleton())
try:
await redis_con.setex(key, time, value)
except Exception as e:
print("Redis setex error", e)
@staticmethod
async def get_token_decimals(token, web_async):
"""
web3 decimals
:param token:
:param web_async:
:return:
"""
fn_abi = {'inputs': [], 'name': 'decimals', 'outputs': [{'internalType': 'uint8', 'name': '', 'type': 'uint8'}],
'stateMutability': 'view', 'type': 'function'}
transaction = {'to': f'{token}', 'data': '0x313ce567'}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("decimals", function)
return function
@staticmethod
async def get_token_name(token, web_async):
"""
web3 name
:param token:
:param web_async:
:return:
"""
fn_abi = {'inputs': [], 'name': 'name', 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}],
'stateMutability': 'view', 'type': 'function'}
transaction = {'to': f'{token}', 'data': '0x06fdde03'}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("name", function)
return function
@staticmethod
async def get_token_supply(token, web_async):
"""
web3 supply
:param token:
:param web_async:
:return:
"""
fn_abi = {'inputs': [], 'name': 'totalSupply',
'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'stateMutability': 'view',
'type': 'function'}
transaction = {'to': f'{token}', 'data': '0x18160ddd'}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("total supply", function)
return function
@staticmethod
async def get_token_symbol(token, web_async):
"""
web3 symbol
:param token:
:param web_async:
:return:
"""
fn_abi = {'inputs': [], 'name': 'symbol', 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}],
'stateMutability': 'view', 'type': 'function'}
transaction = {'to': f'{token}', 'data': '0x95d89b41'}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("symbol", function)
return function
@staticmethod
async def get_token_balance(token, address, web_async):
"""
web3 balanceOf
:param token:
:param address:
:param web_async:
:return:
"""
fn_abi = {'inputs': [{'internalType': 'address', 'name': '', 'type': 'address'}], 'name': 'balanceOf',
'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'stateMutability': 'view',
'type': 'function'}
address = '0x70a08231000000000000000000000000' + (address.lower()[2:])
transaction = {'to': f'{token}', 'data': address}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("token balance", function)
return function
@staticmethod
def trans_address_n0x(address):
"""
address type change
:param address:
:return:
"""
address = address[2:]
while len(address) < 64:
address = '0' + address
return address.lower()
@staticmethod
async def get_amounts_out_op(token0, token1, web_async, Router, token0_d):
"""
get price rate - op
:param token0:
:param token1:
:param web_async:
:param Router:
:param token0_d:
:return:
"""
fn_abi = {'inputs': [{'internalType': 'uint256', 'name': 'amountIn', 'type': 'uint256'},
{'internalType': 'address[]', 'name': 'path', 'type': 'address[]'}],
'name': 'getAmountsOut',
'outputs': [{'internalType': 'uint256[]', 'name': 'amounts', 'type': 'uint256[]'}],
'stateMutability': 'view', 'type': 'function'}
str_0 = '0x9881fcb4'
str_1 = Helper.trans_address_n0x(web_async.toHex(1 * (10 ** token0_d)))
str_2 = '00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001'
str_3 = Helper.trans_address_n0x(token0)
str_4 = Helper.trans_address_n0x(token1)
str_5 = "0000000000000000000000000000000000000000000000000000000000000001"
data_str = str_0 + str_1 + str_2 + str_3 + str_4 + str_5
transaction = {'to': f'{Router}', 'data': data_str}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("token amount", function)
return function
@staticmethod
async def get_amounts_out(token0, token1, web_async, Router, token0_d):
"""
get price rate
:param token0:
:param token1:
:param web_async:
:param Router:
:param token0_d:
:return:
"""
fn_abi = {'inputs': [{'internalType': 'uint256', 'name': 'amountIn', 'type': 'uint256'},
{'internalType': 'address[]', 'name': 'path', 'type': 'address[]'}],
'name': 'getAmountsOut',
'outputs': [{'internalType': 'uint256[]', 'name': 'amounts', 'type': 'uint256[]'}],
'stateMutability': 'view', 'type': 'function'}
str_0 = '0xd06ca61f'
str_1 = Helper.trans_address_n0x(web_async.toHex(1 * (10 ** token0_d)))
str_2 = '00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002'
str_3 = Helper.trans_address_n0x(token0)
str_4 = Helper.trans_address_n0x(token1)
data_str = str_0 + str_1 + str_2 + str_3 + str_4
transaction = {'to': f'{Router}', 'data': data_str}
function = await Helper.get_functions_(fn_abi, transaction, web_async)
# print("token amount", function)
return function
@staticmethod
async def redis_data(data, info, ts_, redisKey, public_token, chainId, stable, search_table, web_async):
"""
taos save insert task list
:param data:
:param info:
:param ts_:
:param redisKey:
:param public_token:
:param chainId:
:param stable:
:param search_table:
:param web_async:
:return:
"""
token = data['token']
if info is None:
try:
supply = await Helper.get_token_supply(token, web_async) / (10 ** data['token_decimals'])
symbol = await Helper.get_token_symbol(token, web_async)
name = await Helper.get_token_name(token, web_async)
except:
da = await Helper.get_token_detail_web(token, chainId)
name = da['token_name'] if "token_name" in da else ""
symbol = da['token_symbol'] if "token_symbol" in da else ""
supply = da['total_supply'] if "total_supply" in da else ""
redis_token = {
'name': name,
'symbol': symbol,
'supply': supply,
'decimals': data['token_decimals'],
'token': token
}
await Helper.save_hash_data(f'{redisKey}:tokens', token, json.dumps(redis_token))
else:
name = info['name']
symbol = info['symbol']
supply = info['supply']
basic_info = {
'name': name,
'symbol': symbol,
'supply': supply,
}
chainInfo = {
'stable': stable,
'search_table': search_table,
'chain_id': chainId,
'redis_key': redisKey
}
if chainId == 1 or chainId == 56:
token_info = dict(**data, **basic_info)
await Helper.task_list(f"{redisKey}:taos:tokens", json.dumps(token_info))
else:
token_info = dict(**data, **basic_info, **chainInfo)
await Helper.task_list("taos:insert:tokens", json.dumps(token_info))
@staticmethod
def get_swap_amount(amount):
"""
uniSwap v2 tx amount
:param amount:
:return:
"""
if amount[0:2] == "0x":
amount0In = eval('0x' + amount[2:66])
amount1In = eval('0x' + amount[66:130])
else:
amount0In = eval('0x' + amount[0:64])
amount1In = eval('0x' + amount[64:128])
amount0Out = eval('0x' + amount[-128:-64])
amount1Out = eval('0x' + amount[-64:])
swap_info = {
'0In': amount0In,
'1In': amount1In,
'0Out': amount0Out,
'1Out': amount1Out
}
return swap_info
@staticmethod
def getUniswapV3Amount(amount):
"""
uniSwap v3 tx amount
:param amount:
:return:
"""
amount0 = eval('0x' + amount[2:66])
amount1 = eval('0x' + amount[66:130])
if amount0 > amount1:
amount0 = -(uni256Max - amount0)
else:
amount1 = -(uni256Max - amount1)
swapinfo = {
"amount0": amount0,
"amount1": amount1
}
return swapinfo
@staticmethod
def getBalancerAmount(amount):
"""
balancer tx amount
:param amount:
:return:
"""
amountIn = eval('0x' + amount[2:66])
amountOut = eval('0x' + amount[66:130])
return amountIn, amountOut
@staticmethod
async def redisSaveList(pool, dataProcess, redisKey, public_token, chainId, stable, search_table, web_async):
"""
redis task list
:param pool
:param dataProcess
:param redisKey
:param public_token
:param chainId
:param stable
:param search_table
:param web_async
"""
data = dataProcess['data']
token_detail = dataProcess['info']
ts_ = Helper.get_time_stamp(data['time'])
if 'p' in pool['r']:
pass
else:
new = await Helper.query_hash(f'{redisKey}:open:recent', data['pool_address'])
if new:
new = json.loads(new)
if 'time' in new:
ts = Helper.get_time_stamp(new['time'])
if ts_ - ts <= 86400:
data['new_token'] = 1
else:
data['new_token'] = 0
else:
data['new_token'] = 1
new['time'] = data['time']
await Helper.save_hash_data(f'{redisKey}:open:recent', data['pool_address'], json.dumps(new))
else:
data['new_token'] = 0
data['is100'] = 0
holder_info = await Helper.query_hash(f'{redisKey}:holder:100', data['token'])
data_ = {
'chain': redisKey,
'token': data['token']
}
if holder_info is not None:
holder_info = json.loads(holder_info)
holder_list = holder_info['holder_100']
time_ = holder_info['date']
stamp = Helper.get_time_stamp(time_)
if ts_ - stamp <= 3600:
if (data['swap_address']).lower() in holder_list:
data['is100'] = 1
else:
await Helper.task_list('chain:holderQueue', json.dumps(data_))
else:
await Helper.task_list('chain:holderQueue', json.dumps(data_))
await Helper.redis_data(data, token_detail, ts_, redisKey, public_token, chainId, stable, search_table,
web_async)
@staticmethod
def get_time():
"""
get millisecond time
:return:
"""
ct = time.time()
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - np.compat.long(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp
@staticmethod
def get_time_add(s):
"""
recent time add millisecond time
:param s:
:return:
"""
ct = (Helper.get_stamp(Helper.get_time()) + s) / 1000
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - np.compat.long(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp
@staticmethod
def get_time_add_old(ts, s):
"""
ts add millisecond time
:param ts:
:param s:
:return:
"""
ct = (int(ts) + s) / 1000
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - np.compat.long(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp
@staticmethod
def get_stamp(timeStr):
"""
get millisecond timestamp
:param timeStr:
:return:
"""
try:
datetime_obj = datetime.datetime.strptime(timeStr, "%Y-%m-%d %H:%M:%S.%f")
except ValueError:
datetime_obj = datetime.datetime.strptime(timeStr, "%Y-%m-%d %H:%M:%S")
obj_stamp = int(time.mktime(datetime_obj.timetuple()) * 1000.0 + datetime_obj.microsecond / 1000.0)
return obj_stamp
@staticmethod
def get_time_stamp(date):
"""
get seconds timestamp
:param date:
:return:
"""
try:
d = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f")
except:
d = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
t = d.timetuple()
time_stamp = int(time.mktime(t))
return time_stamp
@staticmethod
def get_all_proxy():
"""
get rola all type proxy
:return:
"""
proxies_address = requests.get(
'http://list.rola.info:8088/user_get_ip_list?token=JyJu6trbF4LguQxA1656402892061&type=datacenter&qty=1&time=5&country=&format=txt&protocol=http&filter=1').text
async_proxy = f"http://{proxies_address}"
proxy = {
'https': f"http://{proxies_address}",
'http': f"http://{proxies_address}",
}
return {
"proxy": proxy,
"async_proxy": async_proxy
}
@staticmethod
def all_proxy_pool():
"""
get random all type proxy
:return:
"""
proxy_lst = Helper.getProxyList()
index = random.randint(0, 999)
proxies_address = proxy_lst[index]
async_proxy = f"http://{proxies_address}"
proxy = {
'https': f"http://{proxies_address}",
'http': f"http://{proxies_address}",
}
return {
"proxy": proxy,
"async_proxy": async_proxy
}
@staticmethod
def aiohttp_proxy_pool():
"""
get aiohttp proxy
:return:
"""
proxy_lst = Helper.getProxyList()
index = random.randint(0, 999)
proxy = proxy_lst[index]
proxies = f"http://{proxy}"
return proxies
@staticmethod
def requests_proxy_pool():
"""
get http proxy
:return:
"""
proxy_lst = Helper.getProxyList()
index = random.randint(0, 999)
proxy = proxy_lst[index]
proxies = {
'https': f"http://{proxy}",
'http': f"http://{proxy}",
}
return proxies
@staticmethod
def get_radio(radio):
"""
get radio
:param radio:
:return:
"""
fen = "%.2f%%" % (radio * 100)
return fen
@staticmethod
def getHeaders():
"""
get http headers
:return:
"""
ua = UserAgent()
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-language': 'zh-CN,zh;q=0.9',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'iframe',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': ua.chrome
}
return headers
@staticmethod
async def request_page(url, proxy):
"""
aiohttp get page
:param url:
:param proxy:
:return:
"""
# headers = Helper.getHeaders()
async with aiohttp.ClientSession() as session:
# response = await session.get(url, headers=headers, proxy=proxy, timeout=20)
response = await session.get(url, proxy=proxy, timeout=20)
return await response.text()
@staticmethod
async def getTroops(chain, token):
"""
get bsc/eth troops info
:param chain:
:param token:
:return:
"""
if chain == 56:
url = f'https://aywt3wreda.execute-api.eu-west-1.amazonaws.com/default/IsHoneypot?chain=bsc2&token={token}'
else:
url = f'https://aywt3wreda.execute-api.eu-west-1.amazonaws.com/default/IsHoneypot?chain=eth&token={token}'
troops = dict()
for i in range(5):
try:
proxy = Helper.aiohttp_proxy_pool()
res = await Helper.request_page(url, proxy)
troops = json.loads(res)
break
except Exception as e:
print("get troops error!", e)
return troops
@staticmethod
def bscPoolType(token):
"""
bsc public token
:param token:
:return:
"""
if token == 'WBNB':
return '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
elif token == 'BUSD':
return '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'
elif token == 'USDT':
return '0x55d398326f99059fF775485246999027B3197955'
elif token == 'USDC':
return '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d'
elif token == 'BTCB':
return '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c'
elif token == 'DAI':
return '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3'
elif token == 'ETH':
return '0x2170Ed0880ac9A755fd29B2688956BD959F933F8'
elif token == 'FIST':
return '0xC9882dEF23bc42D53895b8361D0b1EDC7570Bc6A'
elif token == 'DOGE':
return '0xbA2aE424d960c26247Dd6c32edC70B295c744C43'
elif token == 'Cake':
return '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82'
@staticmethod
def bscPoolDecimal(token):
"""
bsc pool decimals
:param token:
:return:
"""
if token == 'WBNB':
return 18
elif token == 'BUSD':
return 18
elif token == 'USDT':
return 18
elif token == 'USDC':
return 18
elif token == 'BTCB':
return 18
elif token == 'DAI':
return 18
elif token == 'ETH':
return 18
elif token == 'FIST':
return 6
elif token == 'DOGE':
return 8
elif token == 'Cake':
return 18
@staticmethod
def ethPoolType(token):
"""
eth public token
:param token:
:return:
"""
if token == 'WETH':
return '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
elif token == 'USDT':
return '0xdAC17F958D2ee523a2206206994597C13D831ec7'
elif token == 'USDC':
return '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
elif token == 'BUSD':
return '0x4Fabb145d64652a948d72533023f6E7A623C7C53'
elif token == 'WBTC':
return '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'
elif token == 'DAI':
return '0x6B175474E89094C44Da98b954EedeAC495271d0F'
elif token == 'BNB':
return '0xB8c77482e45F1F44dE1745F52C74426C631bDD52'
@staticmethod
def ethPoolDecimal(token):
"""
eth pool decimals
:param token:
:return:
"""
if token == 'WETH':
return 18
elif token == 'USDT':
return 6
elif token == 'USDC':
return 6
elif token == 'BUSD':
return 18
elif token == 'WBTC':
return 8
elif token == 'DAI':
return 18
elif token == 'BNB':
return 18
if __name__ == '__main__':
# a = Helper.updateProxyLst()
# if a[0] == 0:
# print("代理未过期!")
# else:
# proxyLst = a[1]
# print(proxyLst)
print(Helper.getProxyLst())
......@@ -7,7 +7,7 @@ import requests
import re
import openai
from loguru import logger
from Helper import RedisCon, Helper
from Helper import RedisCon
# key
api_key = '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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment