-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbot7.py
More file actions
1426 lines (1222 loc) · 65.9 KB
/
bot7.py
File metadata and controls
1426 lines (1222 loc) · 65.9 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from web3 import Web3
from web3.exceptions import TransactionNotFound
from eth_account import Account
from eth_abi.abi import encode
from aiohttp import ClientResponseError, ClientSession, ClientTimeout, BasicAuth
from aiohttp_socks import ProxyConnector
from datetime import datetime
from colorama import *
import asyncio, random, time, json, re, os, pytz
wib = pytz.timezone('Asia/Jakarta')
class Zenith:
def __init__(self) -> None:
self.RPC_URL = "https://testnet.dplabs-internal.com/"
self.WPHRS_CONTRACT_ADDRESS = "0x76aaaDA469D23216bE5f7C596fA25F282Ff9b364"
self.USDC_CONTRACT_ADDRESS = "0x72df0bcd7276f2dFbAc900D1CE63c272C4BCcCED"
self.USDT_CONTRACT_ADDRESS = "0xD4071393f8716661958F766DF660033b3d35fD29"
self.SWAP_ROUTER_ADDRESS = "0x1A4DE519154Ae51200b0Ad7c90F7faC75547888a"
self.POSITION_ROUTER_ADDRESS = "0xF8a1D4FF0f9b9Af7CE58E1fc1833688F3BFd6115"
self.QUOTER_ROUTER_ADDRESS = "0x00f2f47d1ed593Cf0AF0074173E9DF95afb0206C"
self.ERC20_CONTRACT_ABI = json.loads('''[
{"type":"function","name":"balanceOf","stateMutability":"view","inputs":[{"name":"address","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},
{"type":"function","name":"decimals","stateMutability":"view","inputs":[],"outputs":[{"name":"","type":"uint8"}]},
{"type":"function","name":"allowance","stateMutability":"view","inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},
{"type":"function","name":"approve","stateMutability":"nonpayable","inputs":[{"name":"spender","type":"address"},{"name":"amount","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]},
{"type":"function","name":"deposit","stateMutability":"payable","inputs":[],"outputs":[]},
{"type":"function","name":"withdraw","stateMutability":"nonpayable","inputs":[{"name":"wad","type":"uint256"}],"outputs":[]},
{"type":"function","name":"multicall","stateMutability":"nonpayable","inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"outputs":[{"internalType":"bytes[]","name":"","type":"bytes[]"}]}
]''')
self.QUOTER_CONTRACT_ABI = [
{
"type": "function",
"name": "quoteExactInput",
"stateMutability": "nonpayable",
"inputs": [
{ "internalType": "bytes", "name": "path", "type": "bytes" },
{ "internalType": "uint256", "name": "amountIn", "type": "uint256" }
],
"outputs": [
{ "internalType": "uint256", "name": "amountOut", "type": "uint256" }
]
}
]
self.SWAP_CONTRACT_ABI = [
{
"type": "function",
"name": "multicall",
"stateMutability": "payable",
"inputs": [
{ "internalType": "uint256", "name": "deadline", "type": "uint256" },
{ "internalType": "bytes[]", "name": "data", "type": "bytes[]" }
],
"outputs": [
{ "internalType": "bytes[]", "name": "", "type": "bytes[]" }
]
}
]
self.LIQUIDITY_CONTRACT_ABI = [
{
"type": "function",
"name": "multicall",
"stateMutability": "payable",
"inputs": [
{ "internalType": "bytes[]", "name": "data", "type": "bytes[]" }
],
"outputs": [
{ "internalType": "bytes[]", "name": "results", "type": "bytes[]" }
]
},
{
"type": "function",
"name": "mint",
"stateMutability": "nonpayable",
"inputs": [
{
"type": "tuple",
"name": "params",
"internalType": "struct INonfungiblePositionManager.MintParams",
"components": [
{ "internalType": "address", "name": "token0", "type": "address" },
{ "internalType": "address", "name": "token1", "type": "address" },
{ "internalType": "uint24", "name": "fee", "type": "uint24" },
{ "internalType": "int24", "name": "tickLower", "type": "int24" },
{ "internalType": "int24", "name": "tickUpper", "type": "int24" },
{ "internalType": "uint256", "name": "amount0Desired", "type": "uint256" },
{ "internalType": "uint256", "name": "amount1Desired", "type": "uint256" },
{ "internalType": "uint256", "name": "amount0Min", "type": "uint256" },
{ "internalType": "uint256", "name": "amount1Min", "type": "uint256" },
{ "internalType": "address", "name": "recipient", "type": "address" },
{ "internalType": "uint256", "name": "deadline", "type": "uint256" }
]
}
],
"outputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" },
{ "internalType": "uint128", "name": "liquidity", "type": "uint128" },
{ "internalType": "uint256", "name": "amount0", "type": "uint256" },
{ "internalType": "uint256", "name": "amount1", "type": "uint256" }
]
}
]
self.proxies = []
self.proxy_index = 0
self.account_proxies = {}
self.used_nonce = {}
self.wrap_option = 0
self.wrap_amount = 0
self.swap_count = 0
self.phrs_swap_amount = 0
self.wphrs_swap_amount = 0
self.usdc_swap_amount = 0
self.usdt_swap_amount = 0
self.liquidity_count = 0
self.phrs_liquidity_amount = 0
self.wphrs_liquidity_amount = 0
self.usdt_liquidity_amount = 0
self.min_delay = 0
self.max_delay = 0
def clear_terminal(self):
os.system('cls' if os.name == 'nt' else 'clear')
def log(self, message):
print(
f"{Fore.CYAN + Style.BRIGHT}[ {datetime.now().astimezone(wib).strftime('%x %X %Z')} ]{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} | {Style.RESET_ALL}{message}",
flush=True
)
def welcome(self, project_name="Zenith Swap"):
border = "═" * 58 # Solid elite border
print(Fore.LIGHTBLUE_EX + Style.BRIGHT + border)
print(Fore.LIGHTYELLOW_EX + Style.BRIGHT + " 👑 YetiDAO PRIME Automation BOT 👑")
print(Fore.LIGHTMAGENTA_EX + Style.BRIGHT + " ─────────────────────────────────────")
print(Fore.LIGHTCYAN_EX + Style.BRIGHT + f" 🧠 Project : Zenith Swap - PRIME Bot")
print(Fore.LIGHTCYAN_EX + Style.BRIGHT + " 💻 Author : YetiDAO")
print(Fore.LIGHTCYAN_EX + Style.BRIGHT + " 🌐 Status : Active & Privately Monitored 🔒")
print(Fore.LIGHTCYAN_EX + Style.BRIGHT + " 🚀 Mode : PRIME Access (VIP Only)")
print(Fore.LIGHTMAGENTA_EX + Style.BRIGHT + " ─────────────────────────────────────")
print(Fore.LIGHTYELLOW_EX + Style.BRIGHT + " 💎 Powered by Cryptodai3 × YetiDAO | Prime Engine v1.0 ⚙️")
print(Fore.LIGHTBLUE_EX + Style.BRIGHT + border)
def format_seconds(self, seconds):
hours, remainder = divmod(seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"
async def load_proxies(self):
filename = "proxy.txt"
try:
if not os.path.exists(filename):
self.log(f"{Fore.RED + Style.BRIGHT}File {filename} Not Found.{Style.RESET_ALL}")
return
with open(filename, 'r') as f:
self.proxies = [line.strip() for line in f.read().splitlines() if line.strip()]
if not self.proxies:
self.log(f"{Fore.RED + Style.BRIGHT}No Proxies Found.{Style.RESET_ALL}")
return
self.log(
f"{Fore.GREEN + Style.BRIGHT}Proxies Total : {Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT}{len(self.proxies)}{Style.RESET_ALL}"
)
except Exception as e:
self.log(f"{Fore.RED + Style.BRIGHT}Failed To Load Proxies: {e}{Style.RESET_ALL}")
self.proxies = []
def check_proxy_schemes(self, proxies):
schemes = ["http://", "https://", "socks4://", "socks5://"]
if any(proxies.startswith(scheme) for scheme in schemes):
return proxies
return f"http://{proxies}"
def get_next_proxy_for_account(self, token):
if token not in self.account_proxies:
if not self.proxies:
return None
proxy = self.check_proxy_schemes(self.proxies[self.proxy_index])
self.account_proxies[token] = proxy
self.proxy_index = (self.proxy_index + 1) % len(self.proxies)
return self.account_proxies[token]
def rotate_proxy_for_account(self, token):
if not self.proxies:
return None
proxy = self.check_proxy_schemes(self.proxies[self.proxy_index])
self.account_proxies[token] = proxy
self.proxy_index = (self.proxy_index + 1) % len(self.proxies)
return proxy
def build_proxy_config(self, proxy=None):
if not proxy:
return None, None, None
if proxy.startswith("socks"):
connector = ProxyConnector.from_url(proxy)
return connector, None, None
elif proxy.startswith("http"):
match = re.match(r"http://(.*?):(.*?)@(.*)", proxy)
if match:
username, password, host_port = match.groups()
clean_url = f"http://{host_port}"
auth = BasicAuth(username, password)
return None, clean_url, auth
else:
return None, proxy, None
raise Exception("Unsupported Proxy Type.")
def generate_address(self, account: str):
try:
account = Account.from_key(account)
address = account.address
return address
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT}Status :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} Generate Address Failed {Style.RESET_ALL}"
f"{Fore.MAGENTA+Style.BRIGHT}-{Style.RESET_ALL}"
f"{Fore.YELLOW+Style.BRIGHT} {str(e)} {Style.RESET_ALL} "
)
return None
def mask_account(self, account):
try:
mask_account = account[:6] + '*' * 6 + account[-6:]
return mask_account
except Exception as e:
return None
def generate_swap_option(self):
token_data = {
"PHRS": (self.WPHRS_CONTRACT_ADDRESS, self.phrs_swap_amount),
"WPHRS": (self.WPHRS_CONTRACT_ADDRESS, self.wphrs_swap_amount),
"USDC": (self.USDC_CONTRACT_ADDRESS, self.usdc_swap_amount),
"USDT": (self.USDT_CONTRACT_ADDRESS, self.usdt_swap_amount)
}
tickers = list(token_data.keys())
while True:
from_ticker = random.choice(tickers)
to_ticker = random.choice(tickers)
if from_ticker == to_ticker:
continue
if (from_ticker == "PHRS" and to_ticker == "WPHRS") or (from_ticker == "WPHRS" and to_ticker == "PHRS"):
continue
if from_ticker == "PHRS":
swap_type = "native to erc20"
elif to_ticker == "PHRS":
swap_type = "erc20 to native"
else:
swap_type = "erc20 to erc20"
from_token, amount_in = token_data[from_ticker]
to_token, _ = token_data[to_ticker]
return swap_type, from_ticker, to_ticker, from_token, to_token, amount_in
def generate_liquidity_option(self):
swap_options = [
("native_erc20", "PHRS", "USDT", self.WPHRS_CONTRACT_ADDRESS, self.USDT_CONTRACT_ADDRESS, self.phrs_liquidity_amount),
("erc20_native", "USDC", "PHRS", self.USDC_CONTRACT_ADDRESS, self.WPHRS_CONTRACT_ADDRESS, self.usdc_liquidity_amount),
("erc20_erc20", "WPHRS", "USDT", self.WPHRS_CONTRACT_ADDRESS, self.USDT_CONTRACT_ADDRESS, self.wphrs_liquidity_amount),
("erc20_erc20", "USDC", "WPHRS", self.USDC_CONTRACT_ADDRESS, self.WPHRS_CONTRACT_ADDRESS, self.usdc_liquidity_amount),
("erc20_erc20", "USDC", "USDT", self.USDC_CONTRACT_ADDRESS, self.USDT_CONTRACT_ADDRESS, self.usdc_liquidity_amount),
]
token_type, ticker0, ticker1, token0, token1, amount0 = random.choice(swap_options)
liquidity_option = f"{ticker0}/{ticker1}"
decimals0 = 6 if ticker0 == "USDC" else 18
decimals1 = 6 if ticker1 == "USDT" else 18
amount0_desired = int(amount0 * (10 ** decimals0))
return liquidity_option, token_type, ticker0, ticker1, token0, token1, amount0_desired, decimals0, decimals1
async def get_web3_with_check(self, address: str, use_proxy: bool, retries=3, timeout=60):
request_kwargs = {"timeout": timeout}
proxy = self.get_next_proxy_for_account(address) if use_proxy else None
if use_proxy and proxy:
request_kwargs["proxies"] = {"http": proxy, "https": proxy}
for attempt in range(retries):
try:
web3 = Web3(Web3.HTTPProvider(self.RPC_URL, request_kwargs=request_kwargs))
web3.eth.get_block_number()
return web3
except Exception as e:
if attempt < retries - 1:
await asyncio.sleep(3)
continue
raise Exception(f"Failed to Connect to RPC: {str(e)}")
async def send_raw_transaction_with_retries(self, account, web3, tx, retries=5):
for attempt in range(retries):
try:
signed_tx = web3.eth.account.sign_transaction(tx, account)
raw_tx = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_hash = web3.to_hex(raw_tx)
return tx_hash
except TransactionNotFound:
pass
except Exception as e:
self.log(
f"{Fore.CYAN + Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.YELLOW + Style.BRIGHT} [Attempt {attempt + 1}] Send TX Error: {str(e)} {Style.RESET_ALL}"
)
await asyncio.sleep(2 ** attempt)
raise Exception("Transaction Hash Not Found After Maximum Retries")
async def wait_for_receipt_with_retries(self, web3, tx_hash, retries=5):
for attempt in range(retries):
try:
receipt = await asyncio.to_thread(web3.eth.wait_for_transaction_receipt, tx_hash, timeout=300)
return receipt
except TransactionNotFound:
pass
except Exception as e:
self.log(
f"{Fore.CYAN + Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.YELLOW + Style.BRIGHT} [Attempt {attempt + 1}] Wait for Receipt Error: {str(e)} {Style.RESET_ALL}"
)
await asyncio.sleep(2 ** attempt)
raise Exception("Transaction Receipt Not Found After Maximum Retries")
async def get_token_balance(self, address: str, contract_address: str, use_proxy: bool, retries=5):
for attempt in range(retries):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
if contract_address == "PHRS":
balance = web3.eth.get_balance(address)
decimals = 18
else:
token_contract = web3.eth.contract(address=web3.to_checksum_address(contract_address), abi=self.ERC20_CONTRACT_ABI)
balance = token_contract.functions.balanceOf(address).call()
decimals = token_contract.functions.decimals().call()
token_balance = balance / (10 ** decimals)
return token_balance
except Exception as e:
if attempt < retries - 1:
await asyncio.sleep(3)
continue
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None
async def perform_wrapped(self, account: str, address: str, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
contract_address = web3.to_checksum_address(self.WPHRS_CONTRACT_ADDRESS)
token_contract = web3.eth.contract(address=contract_address, abi=self.ERC20_CONTRACT_ABI)
amount_to_wei = web3.to_wei(self.wrap_amount, "ether")
wrap_data = token_contract.functions.deposit()
estimated_gas = wrap_data.estimate_gas({"from":address, "value":amount_to_wei})
max_priority_fee = web3.to_wei(1, "gwei")
max_fee = max_priority_fee
wrap_tx = wrap_data.build_transaction({
"from": address,
"value": amount_to_wei,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id,
})
tx_hash = await self.send_raw_transaction_with_retries(account, web3, wrap_tx)
receipt = await self.wait_for_receipt_with_retries(web3, tx_hash)
block_number = receipt.blockNumber
self.used_nonce[address] += 1
return tx_hash, block_number
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None, None
async def perform_unwrapped(self, account: str, address: str, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
contract_address = web3.to_checksum_address(self.WPHRS_CONTRACT_ADDRESS)
token_contract = web3.eth.contract(address=contract_address, abi=self.ERC20_CONTRACT_ABI)
amount_to_wei = web3.to_wei(self.wrap_amount, "ether")
unwrap_data = token_contract.functions.withdraw(amount_to_wei)
estimated_gas = unwrap_data.estimate_gas({"from":address})
max_priority_fee = web3.to_wei(1, "gwei")
max_fee = max_priority_fee
unwrap_tx = unwrap_data.build_transaction({
"from": address,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id,
})
tx_hash = await self.send_raw_transaction_with_retries(account, web3, unwrap_tx)
receipt = await self.wait_for_receipt_with_retries(web3, tx_hash)
block_number = receipt.blockNumber
self.used_nonce[address] += 1
return tx_hash, block_number
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None, None
async def get_amount_out_min(self, address: str, path: str, amount_in_wei: int, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
contract = web3.eth.contract(address=web3.to_checksum_address(self.QUOTER_ROUTER_ADDRESS), abi=self.QUOTER_CONTRACT_ABI)
amount_out = contract.functions.quoteExactInput(path, amount_in_wei).call()
return amount_out
except Exception as e:
return None
async def approving_token(self, account: str, address: str, router_address: str, asset_address: str, amount_to_wei: int, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
spender = web3.to_checksum_address(router_address)
token_contract = web3.eth.contract(address=web3.to_checksum_address(asset_address), abi=self.ERC20_CONTRACT_ABI)
allowance = token_contract.functions.allowance(address, spender).call()
if allowance < amount_to_wei:
approve_data = token_contract.functions.approve(spender, 2**256 - 1)
estimated_gas = approve_data.estimate_gas({"from": address})
max_priority_fee = web3.to_wei(1, "gwei")
max_fee = max_priority_fee
approve_tx = approve_data.build_transaction({
"from": address,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id,
})
tx_hash = await self.send_raw_transaction_with_retries(account, web3, approve_tx)
receipt = await self.wait_for_receipt_with_retries(web3, tx_hash)
block_number = receipt.blockNumber
self.used_nonce[address] += 1
explorer = f"https://testnet.pharosscan.xyz/tx/{tx_hash}"
self.log(
f"{Fore.CYAN+Style.BRIGHT} Approve :{Style.RESET_ALL}"
f"{Fore.GREEN+Style.BRIGHT} Success {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Block :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {block_number} {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Tx Hash :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {tx_hash} {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Explorer :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {explorer} {Style.RESET_ALL}"
)
await self.print_timer()
return True
except Exception as e:
raise Exception(f"Approving Token Contract Failed: {str(e)}")
def generate_multicall_bytes_data(self, address: str, swap_type: str, fee: int, from_token: str, to_token: str, amount_in_wei: int, amount_out_min_wei: int):
try:
if swap_type in ["native to erc20", "erc20 to erc20"]:
exact_input_single_prefix = bytes.fromhex('04e45aaf')
exact_input_single_bytes = encode(
['address', 'address', 'uint24', 'address', 'uint256', 'uint256', 'uint160'],
[
from_token,
to_token,
fee,
address,
amount_in_wei,
amount_out_min_wei,
0
]
)
data_bytes = [exact_input_single_prefix + exact_input_single_bytes]
elif swap_type == "erc20 to native":
exact_input_single_prefix = bytes.fromhex('04e45aaf')
exact_input_single_bytes = encode(
['address', 'address', 'uint24', 'address', 'uint256', 'uint256', 'uint160'],
[
from_token,
to_token,
fee,
"0x0000000000000000000000000000000000000002",
amount_in_wei,
amount_out_min_wei,
0
]
)
unwrap_weth_9_prefix = bytes.fromhex('49404b7c')
unwrap_weth_9_bytes = encode(
['uint256', 'address'],
[
amount_out_min_wei,
address
]
)
data_bytes = [exact_input_single_prefix + exact_input_single_bytes, unwrap_weth_9_prefix +unwrap_weth_9_bytes ]
return data_bytes
except Exception as e:
raise Exception(f"Generate Multicall Bytes Data Failed: {str(e)}")
async def perform_swap(self, account: str, address: str, swap_type: str, from_token: str, to_token: str, amount_in: float, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
assets_contract = web3.eth.contract(address=web3.to_checksum_address(from_token), abi=self.ERC20_CONTRACT_ABI)
decimals = assets_contract.functions.decimals().call()
amount_in_wei = int(amount_in * 10**decimals)
exceptions = [
(self.USDC_CONTRACT_ADDRESS, self.USDT_CONTRACT_ADDRESS)
]
fee = 10000 if (from_token, to_token) in exceptions else 500
if swap_type != "native to erc20":
await self.approving_token(account, address, self.SWAP_ROUTER_ADDRESS, from_token, amount_in_wei, use_proxy)
path = bytes.fromhex(from_token[2:]) + (fee).to_bytes(3, "big") + bytes.fromhex(to_token[2:])
amount_out_wei = await self.get_amount_out_min(address, path, amount_in_wei, use_proxy)
if not amount_out_wei:
raise Exception("Fetch Amount Out Min Failed")
amount_out_min_wei = (amount_out_wei * (10000 - 500)) // 10000
deadline = int(time.time()) + 600
data_bytes = self.generate_multicall_bytes_data(address, swap_type, fee, from_token, to_token, amount_in_wei, amount_out_min_wei)
max_priority_fee = web3.to_wei(1, "gwei")
max_fee = max_priority_fee
if swap_type == "native to erc20":
token_contract = web3.eth.contract(address=web3.to_checksum_address(self.SWAP_ROUTER_ADDRESS), abi=self.SWAP_CONTRACT_ABI)
swap_data = token_contract.functions.multicall(deadline, data_bytes)
estimated_gas = swap_data.estimate_gas({"from": address, "value":amount_in_wei})
swap_tx = swap_data.build_transaction({
"from": address,
"value": amount_in_wei,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id
})
else:
token_contract = web3.eth.contract(address=web3.to_checksum_address(self.SWAP_ROUTER_ADDRESS), abi=self.ERC20_CONTRACT_ABI)
swap_data = token_contract.functions.multicall(deadline, data_bytes)
estimated_gas = swap_data.estimate_gas({"from": address})
swap_tx = swap_data.build_transaction({
"from": address,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id
})
tx_hash = await self.send_raw_transaction_with_retries(account, web3, swap_tx)
receipt = await self.wait_for_receipt_with_retries(web3, tx_hash)
block_number = receipt.blockNumber
self.used_nonce[address] += 1
return tx_hash, block_number
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None, None
def generate_liquidity_calldata(self, address: str, token_type: str, token0: str, token1: str, amount0_desired: int, amount1_desired: int):
try:
amount0_min = (amount0_desired * (10000 - 500)) // 10000
amount1_min = (amount1_desired * (10000 - 500)) // 10000
deadline = int(time.time()) + 600
if token_type == "erc20_erc20":
calldata = (
token0, token1, 500, -887220, 887220, amount0_desired,
amount1_desired, amount0_min, amount1_min, address, deadline
)
else:
mint_prefix = bytes.fromhex("88316456")
mint_params = encode(
[
'address', 'address', 'uint24', 'int24', 'int24', 'uint256',
'uint256', 'uint256', 'uint256', 'address', 'uint256'
],
[
token0, token1, 500, -887220, 887220, amount0_desired,
amount1_desired, amount0_min, amount1_min, address, deadline
]
)
refund_eth_prefix = bytes.fromhex("12210e8a")
calldata = [mint_prefix + mint_params, refund_eth_prefix]
return calldata
except Exception as e:
raise Exception(f"Generate Liquidity Calldata Failed: {str(e)}")
async def perform_liquidity(self, account: str, address: str, token_type: str, token0: str, token1: str, amount0_desired: int, amount1_desired: int, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
if token_type == "native_erc20":
await self.approving_token(account, address, self.POSITION_ROUTER_ADDRESS, token1, amount1_desired, use_proxy)
elif token_type == "erc20_native":
await self.approving_token(account, address, self.POSITION_ROUTER_ADDRESS, token0, amount0_desired, use_proxy)
elif token_type == "erc20_erc20":
await self.approving_token(account, address, self.POSITION_ROUTER_ADDRESS, token0, amount0_desired, use_proxy)
await self.approving_token(account, address, self.POSITION_ROUTER_ADDRESS, token1, amount1_desired, use_proxy)
token_contract = web3.eth.contract(address=web3.to_checksum_address(self.POSITION_ROUTER_ADDRESS), abi=self.LIQUIDITY_CONTRACT_ABI)
calldata = self.generate_liquidity_calldata(address, token_type, token0, token1, amount0_desired, amount1_desired)
max_priority_fee = web3.to_wei(1, "gwei")
max_fee = max_priority_fee
if token_type in ["native_erc20", "erc20_native"]:
liquidity_data = token_contract.functions.multicall(calldata)
value = amount0_desired if token_type == "native_erc20" else amount1_desired
estimated_gas = liquidity_data.estimate_gas({"from": address, "value":value})
liquidity_tx = liquidity_data.build_transaction({
"from": address,
"value": value,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id
})
else:
liquidity_data = token_contract.functions.mint(calldata)
estimated_gas = liquidity_data.estimate_gas({"from": address})
liquidity_tx = liquidity_data.build_transaction({
"from": address,
"gas": int(estimated_gas * 1.2),
"maxFeePerGas": int(max_fee),
"maxPriorityFeePerGas": int(max_priority_fee),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id
})
tx_hash = await self.send_raw_transaction_with_retries(account, web3, liquidity_tx)
receipt = await self.wait_for_receipt_with_retries(web3, tx_hash)
block_number = receipt.blockNumber
self.used_nonce[address] += 1
return tx_hash, block_number
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None, None
def print_wrap_question(self):
while True:
try:
wrap_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter PHRS Amount -> {Style.RESET_ALL}").strip())
if wrap_amount > 0:
self.wrap_amount = wrap_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}PHRS Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
def print_unwrap_question(self):
while True:
try:
wrap_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter WPHRS Amount -> {Style.RESET_ALL}").strip())
if wrap_amount > 0:
self.wrap_amount = wrap_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}WPHRS Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
def print_wrap_or_unwarp_option(self):
while True:
try:
print(f"{Fore.GREEN + Style.BRIGHT}Select Option:{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}1. Wrap PHRS{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}2. Unwrap WPHRS{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}3. Skipped{Style.RESET_ALL}")
wrap_option = int(input(f"{Fore.BLUE + Style.BRIGHT}Choose [1/2/3] -> {Style.RESET_ALL}").strip())
if wrap_option in [1, 2, 3]:
wrap_type = (
"Wrap PHRS" if wrap_option == 1 else
"Unwrap WPHRS" if wrap_option == 2 else
"Skipped"
)
print(f"{Fore.GREEN + Style.BRIGHT}{wrap_type} Selected.{Style.RESET_ALL}")
self.wrap_option = wrap_option
if self.wrap_option == 1:
self.print_wrap_question()
elif self.wrap_option == 2:
self.print_unwrap_question()
break
else:
print(f"{Fore.RED + Style.BRIGHT}Please enter either 1 or 2.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number (1 or 2).{Style.RESET_ALL}")
def print_swap_question(self):
while True:
try:
swap_count = int(input(f"{Fore.YELLOW + Style.BRIGHT}Swap Count For Each Wallet -> {Style.RESET_ALL}").strip())
if swap_count > 0:
self.swap_count = swap_count
break
else:
print(f"{Fore.RED + Style.BRIGHT}Swap Count must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
while True:
try:
phrs_swap_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter PHRS Swap Amount -> {Style.RESET_ALL}").strip())
if phrs_swap_amount > 0:
self.phrs_swap_amount = phrs_swap_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}PHRS Swap Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
wphrs_swap_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter WPHRS Swap Amount -> {Style.RESET_ALL}").strip())
if wphrs_swap_amount > 0:
self.wphrs_swap_amount = wphrs_swap_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}WPHRS Swap Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
usdc_swap_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter USDC Swap Amount -> {Style.RESET_ALL}").strip())
if usdc_swap_amount > 0:
self.usdc_swap_amount = usdc_swap_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}USDC Swap Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
usdt_swap_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter USDT Swap Amount -> {Style.RESET_ALL}").strip())
if usdt_swap_amount > 0:
self.usdt_swap_amount = usdt_swap_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}USDT Swap Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
def print_liquidity_question(self):
while True:
try:
liquidity_count = int(input(f"{Fore.YELLOW + Style.BRIGHT}Add Liquidity Count For Each Wallet -> {Style.RESET_ALL}").strip())
if liquidity_count > 0:
self.liquidity_count = liquidity_count
break
else:
print(f"{Fore.RED + Style.BRIGHT}Add Liquidity Count must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
while True:
try:
phrs_liquidity_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter PHRS Liquidity Amount -> {Style.RESET_ALL}").strip())
if phrs_liquidity_amount > 0:
self.phrs_liquidity_amount = phrs_liquidity_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}PHRS Liquidity Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
wphrs_liquidity_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter WPHRS Liquidity Amount -> {Style.RESET_ALL}").strip())
if wphrs_liquidity_amount > 0:
self.wphrs_liquidity_amount = wphrs_liquidity_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}WPHRS Liquidity Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
usdc_liquidity_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter USDC Liquidity Amount -> {Style.RESET_ALL}").strip())
if usdc_liquidity_amount > 0:
self.usdc_liquidity_amount = usdc_liquidity_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}USDC Liquidity Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
def print_delay_question(self):
while True:
try:
min_delay = int(input(f"{Fore.YELLOW + Style.BRIGHT}Min Delay For Each Tx -> {Style.RESET_ALL}").strip())
if min_delay >= 0:
self.min_delay = min_delay
break
else:
print(f"{Fore.RED + Style.BRIGHT}Min Delay must be >= 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
while True:
try:
max_delay = int(input(f"{Fore.YELLOW + Style.BRIGHT}Max Delay For Each Tx -> {Style.RESET_ALL}").strip())
if max_delay >= min_delay:
self.max_delay = max_delay
break
else:
print(f"{Fore.RED + Style.BRIGHT}Max Delay must be >= Min Delay.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
async def print_timer(self):
for remaining in range(random.randint(self.min_delay, self.max_delay), 0, -1):
print(
f"{Fore.CYAN + Style.BRIGHT}[ {datetime.now().astimezone(wib).strftime('%x %X %Z')} ]{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} | {Style.RESET_ALL}"
f"{Fore.BLUE + Style.BRIGHT}Wait For{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} {remaining} {Style.RESET_ALL}"
f"{Fore.BLUE + Style.BRIGHT}Seconds For Next Tx...{Style.RESET_ALL}",
end="\r",
flush=True
)
await asyncio.sleep(1)
def print_question(self):
while True:
try:
print(f"{Fore.GREEN + Style.BRIGHT}Select Option:{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}1. Wrap PHRS{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}2. Unwrap WPHRS{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}3. Random Swap{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}4. Add Liquidity{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}5. Run All Features{Style.RESET_ALL}")
option = int(input(f"{Fore.BLUE + Style.BRIGHT}Choose [1/2/3/4/5] -> {Style.RESET_ALL}").strip())
if option in [1, 2, 3, 4, 5]:
option_type = (
"Wrap PHRS" if option == 1 else
"Unwrap WPHRS" if option == 2 else
"Random Swap" if option == 3 else
"Add Liquidity" if option == 4 else
"Run All Features"
)
print(f"{Fore.GREEN + Style.BRIGHT}{option_type} Selected.{Style.RESET_ALL}")
break
else:
print(f"{Fore.RED + Style.BRIGHT}Please enter either 1, 2, 3, 4, or 5.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number (1, 2, 3, 4, or 5).{Style.RESET_ALL}")
if option == 1:
self.print_wrap_question()
self.print_delay_question()
elif option == 2:
self.print_unwrap_question()
self.print_delay_question()
elif option == 3:
self.print_swap_question()
self.print_delay_question()
elif option == 4:
self.print_liquidity_question()
self.print_delay_question()
elif option == 5:
self.print_wrap_or_unwarp_option()
self.print_swap_question()
self.print_liquidity_question()
self.print_delay_question()
while True:
try:
print(f"{Fore.WHITE + Style.BRIGHT}1. Run With Proxy{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}2. Run Without Proxy{Style.RESET_ALL}")
proxy_choice = int(input(f"{Fore.BLUE + Style.BRIGHT}Choose [1/2] -> {Style.RESET_ALL}").strip())
if proxy_choice in [1, 2]:
proxy_type = (
"With" if proxy_choice == 2 else
"Without"
)
print(f"{Fore.GREEN + Style.BRIGHT}Run {proxy_type} Proxy Selected.{Style.RESET_ALL}")
break
else:
print(f"{Fore.RED + Style.BRIGHT}Please enter either 1 or 2.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number (1 or 2).{Style.RESET_ALL}")
rotate_proxy = False
if proxy_choice == 1:
while True:
rotate_proxy = input(f"{Fore.BLUE + Style.BRIGHT}Rotate Invalid Proxy? [y/n] -> {Style.RESET_ALL}").strip()
if rotate_proxy in ["y", "n"]:
rotate_proxy = rotate_proxy == "y"
break
else:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter 'y' or 'n'.{Style.RESET_ALL}")
return option, proxy_choice, rotate_proxy
async def check_connection(self, proxy_url=None):
connector, proxy, proxy_auth = self.build_proxy_config(proxy_url)
try:
async with ClientSession(connector=connector, timeout=ClientTimeout(total=10)) as session:
async with session.get(url="https://api.ipify.org?format=json", proxy=proxy, proxy_auth=proxy_auth) as response:
response.raise_for_status()
return True
except (Exception, ClientResponseError) as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT}Status :{Style.RESET_ALL}"