-
Notifications
You must be signed in to change notification settings - Fork 356
/
runner.py
215 lines (179 loc) · 7.56 KB
/
runner.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
from config import WALLETS, STR_DONE, STR_CANCEL
from setting import RANDOMIZER, CHECK_GWEI, TG_BOT_SEND, IS_SLEEP, DELAY_SLEEP, RETRY, WALLETS_IN_BATCH, TRACK
from modules.utils.helpers import list_send, wait_gas, send_msg, async_sleeping, is_private_key
from modules.utils.manager_async import Web3ManagerAsync
from modules import *
from loguru import logger
import random
import asyncio
MODULES = {
1: ("balance_checker", EvmBalanceChecker),
2: ("starknet_balance_checker", StarknetBalanceChecker),
3: ("debank_checker", DeBank),
4: ("exchange_withdraw", ExchangeWithdraw),
5: ("okx_withdraw", OkxWithdraw),
6: ("transfer", Transfer),
7: ("0x_swap", ZeroXswap),
8: ("orbiter_bridge", OrbiterBridge),
9: ("woofi_bridge", WoofiBridge),
10: ("woofi_swap", WoofiSwap),
11: ("sushiswap", SushiSwap),
12: ("bungee_refuel", BungeeRefuel),
13: ("tx_checker", TxChecker),
14: ("1inch_swap", InchSwap),
15: ("zerius_refuel", ZeriusRefuel),
16: ("nft_checker", NFTChecker),
17: ("zerius_onft", Zerius),
18: ("starknet_bridge", Starkgate),
19: ("base_bridge", BaseBridge),
20: ("arbitrum_bridge", ArbitrumBridge),
21: ("zora_bridge", ZoraBridge),
22: ("zksync_bridge", ZkSyncBridge),
23: ("rocketsam", RocketSam),
}
def get_module(module):
module_info = MODULES.get(module)
if module_info:
module_name, func = module_info
# cprint(f'\nstart : {module_name}', 'white')
return func, module_name
else:
raise ValueError(f"Unsupported module: {module}")
async def worker(func, key, number, retry=0):
func_instance = func(key, number)
await func_instance.setup()
module_info = func_instance.module_str
contract_txn = await func_instance.get_txn()
if not contract_txn:
logger.error(f'{module_info} | error getting contract_txn')
return await retry_worker(func, key, number, retry, module_info)
status, tx_link = await func_instance.manager.send_tx(contract_txn)
if status == 1:
logger.success(f'{module_info} | {tx_link}')
list_send.append(f'{STR_DONE}{module_info}')
return True
elif status == 0:
logger.error(f'{module_info} | tx is failed | {tx_link}')
return await retry_worker(func, key, number, retry, module_info)
else:
return await retry_worker(func, key, number, retry, module_info)
async def retry_worker(func, key, number, retry, info):
if retry < RETRY:
logger.info(f'try again in 10 sec.')
await asyncio.sleep(10)
return await worker(func, key, number, retry+1)
else:
list_send.append(f'{STR_CANCEL}{info}')
return False
async def process_exchanges(func, wallets):
for key in wallets:
exchange = func(key)
res = await exchange.start()
if (TG_BOT_SEND and len(list_send) > 0):
send_msg()
list_send.clear()
if IS_SLEEP and res:
time_sleep = random.randint(*DELAY_SLEEP)
logger.info(f'sleep for {time_sleep} sec.')
await asyncio.sleep(time_sleep)
async def process_batches(func, wallets, module):
batches = [wallets[i:i + WALLETS_IN_BATCH] for i in range(0, len(wallets), WALLETS_IN_BATCH)]
number = 0
for batch in batches:
if CHECK_GWEI:
await wait_gas()
tasks = []
for key in batch:
number += 1
if is_private_key(key):
if module == 23: # RocketSam
tasks.append(asyncio.create_task(func(key, f'[{number}/{len(wallets)}]').main()))
else:
tasks.append(asyncio.create_task(worker(func, key, f'[{number}/{len(wallets)}]')))
else:
logger.error(f"{key} isn't private key")
res = await asyncio.gather(*tasks)
if (TG_BOT_SEND and len(list_send) > 0):
send_msg()
list_send.clear()
if IS_SLEEP and any(res):
await async_sleeping(*DELAY_SLEEP)
async def worker_tracks(key, number):
for params in TRACK:
if params['module_name'] == 'wait_balance':
manager = Web3ManagerAsync(key, params['params']['chain'])
await manager.wait_balance(number, params['params']['min_balance'], params['params']['token'])
elif params['module_name'] == 'sleeping':
time_sleep = random.randint(int(params['params']['from']), int(params['params']['to']))
logger.info(f'sleep for {time_sleep} sec.')
await asyncio.sleep(time_sleep)
else:
attempts = 0
while attempts <= RETRY:
func, module_name = get_module(int(params['module_number']))
if module_name in ["exchange_withdraw", "okx_withdraw"]:
exchange = func(key, params['params'])
await exchange.start()
break
else:
func_instance = func(key, number, params['params'])
await func_instance.setup()
logger.debug(f'{func_instance.module_str} : {module_name}')
contract_txn = await func_instance.get_txn()
if contract_txn:
status, tx_link = await func_instance.manager.send_tx(contract_txn)
if not status:
list_send.append(f'{STR_CANCEL}{func_instance.module_str}')
break
elif status == 1:
logger.success(f'{func_instance.module_str} | {tx_link}')
list_send.append(f'{STR_DONE}{func_instance.module_str}')
break
else:
logger.error(f'{func_instance.module_str} | tx is failed | {tx_link}')
attempts += 1
logger.info('sleep for 10 sec.')
await asyncio.sleep(10)
else:
attempts += 1
logger.error(f'{func_instance.module_str} | error getting contract_txn')
logger.info('sleep for 3 sec.')
await asyncio.sleep(3)
else:
logger.error(f'{func_instance.module_str} | module is not success, cycle broken')
list_send.append(f'{STR_CANCEL}{func_instance.module_str}')
break
async def main_tracks():
if RANDOMIZER:
random.shuffle(WALLETS)
batches = [WALLETS[i:i + WALLETS_IN_BATCH] for i in range(0, len(WALLETS), WALLETS_IN_BATCH)]
number = 0
for batch in batches:
if CHECK_GWEI:
await wait_gas()
tasks = []
for key in batch:
if is_private_key(key):
number += 1
tasks.append(asyncio.create_task(worker_tracks(key, f'[{number}/{len(WALLETS)}]')))
else:
logger.error(f"{key} isn't private key")
res = await asyncio.gather(*tasks)
if (TG_BOT_SEND and len(list_send) > 0):
send_msg()
list_send.clear()
if IS_SLEEP and any(res):
await async_sleeping(*DELAY_SLEEP)
async def main(module):
func, module_name = get_module(module)
if RANDOMIZER:
random.shuffle(WALLETS)
if module in [1, 2, 3, 13, 16]:
await func().start()
elif module == 17:
await func()
else:
if module in [4, 5]:
await process_exchanges(func, WALLETS)
else:
await process_batches(func, WALLETS, module)