-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsniper_bsc_kv.py
More file actions
552 lines (403 loc) · 22.4 KB
/
sniper_bsc_kv.py
File metadata and controls
552 lines (403 loc) · 22.4 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
import os, sys
from kivy.resources import resource_add_path, resource_find
from web3 import Web3
import threading
import settings
import datetime
import time
from eth_account import Account
from kivy.app import App
#from kivy.uix.stacklayout import StackLayout
from kivy.metrics import dp
#from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.gridlayout import GridLayout
# from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
# from kivy.uix.widget import Widget
# from kivy.uix.screenmanager import ScreenManager, Screen
# from kivy.properties import StringProperty
#from kivy.core.window import Window
#Window.clearcolor = (0.2, 0.3, 1, 1)
provider_url = 'https://bsc-dataseed.binance.org/'
web3 = Web3(Web3.HTTPProvider(provider_url))
#PCS_PAIRS:
pcs_bnb_pair = False
pcs_busd_pair = False
pcs_usdc_pair = False
pcs_usdt_pair = False
pcs_cake_pair = False
private_key = '0x_N0PR1V4T3_K3Y5'
# Deadline for transaction to revert
deadline = int(time.time()) + 85000
# Gas and gas price (BSC Only)
global_gas = 3000000
global_gas_price = web3.toWei(5, 'gwei') #9.69
wbnb = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
busd = '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'
usdc = '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d'
usdt = '0x55d398326f99059fF775485246999027B3197955'
cake = '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82'
# Pancakeswap Contracts
pcs_router_contract = web3.eth.contract(address = settings.PCS_router_address, abi = settings.PCS_router_abi)
pcs_factory_contract = web3.eth.contract(address = settings.PCS_factory_address, abi = settings.PCS_factory_abi)
#Apeswap Contracts
class Main_PCS(GridLayout):
def pcs_snipe_bnb(self, value, address):
print(web3.isConnected())
token_address = web3.toChecksumAddress(address.text)
buyer = Account.from_key(private_key).address
print(buyer)
spend = wbnb
# Liquidity check starts here
liquidity_address = pcs_factory_contract.functions.getPair(token_address, wbnb).call()
# Sometimes the liquidity has not been created and is not zero we need to check again
if liquidity_address == '0x0000000000000000000000000000000000000000':
print('Waiting for Liquidity Contract')
while liquidity_address == '0x0000000000000000000000000000000000000000':
liquidity_address = pcs_factory_contract.functions.getPair(token_address, wbnb).call()
liquidity_contract = web3.eth.contract(address= liquidity_address, abi= settings.PCS_pair_abi)
liquidity_supply = web3.fromWei(liquidity_contract.functions.totalSupply().call(),'ether')
if liquidity_supply == 0:
print('waiting for liquidity to be added to contract ...')
while liquidity_supply == 0:
liquidity_supply = liquidity_contract.functions.totalSupply().call()
print(f'Liquidity added : {liquidity_supply} LP-Tokens \n {datetime.datetime.now().strftime("%I:%M:%S %p")}')
# Optionally check for trading enabled'
#enabled_trading = contract.functions.tradingEnabled().call()
#if enabled_trading == False:
# print('Waiting for trading to be enabled')
# while enabled_trading == False:
# enabled_trading = dbubble_contract.functions.tradingEnabled().call()
#print('Trading enabled')
#↓↓↓↓↓↓
# HERE
#↑↑↑↑↑↑
# Buying process starts here
#nonce is required to build tx and make sure not multisending.
nonce = web3.eth.get_transaction_count(buyer)
tx = pcs_router_contract.functions.swapExactETHForTokens( #swapExactETHForTokensSupportingFeeOnTransferTokens (Optional)
0, # ∞ slippage
[spend, token_address],# Path of tx
buyer, # Address that will receive the funds we buy, in this case buyer is also receiver
deadline
).buildTransaction({
'from': buyer,
'value': web3.toWei(float(value.text), 'ether'),# BNB amount we swap for
'gas': global_gas, #it seems if you do not specify the gas, it automatically use an ideal amout of gas
'gasPrice': global_gas_price,
'nonce': nonce
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key=private_key)
tx_receipt = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print (f'Sniped: https://bscscan.com/tx/{web3.toHex(tx_receipt)} @ {datetime.datetime.now().strftime("%I:%M:%S %p")}')
def pcs_snipe_busd(self, value, address):
token_address = web3.toChecksumAddress(address.text)
buyer = Account.from_key(private_key).address
spend = wbnb
# Liquidity check starts here
liquidity_address = pcs_factory_contract.functions.getPair(token_address, busd).call()
# Sometimes the liquidity has not been created and is not zero we need to check again
if liquidity_address == '0x0000000000000000000000000000000000000000':
print('Waiting for Liquidity Contract')
while liquidity_address == '0x0000000000000000000000000000000000000000':
liquidity_address = pcs_factory_contract.functions.getPair(token_address, busd).call()
liquidity_contract = web3.eth.contract(address= liquidity_address, abi= settings.PCS_pair_abi)
liquidity_supply = web3.fromWei(liquidity_contract.functions.totalSupply().call(),'ether')
if liquidity_supply == 0:
print('waiting for liquidity to be added to contract ...')
while liquidity_supply == 0:
liquidity_supply = liquidity_contract.functions.totalSupply().call()
print(f'Liquidity added : {liquidity_supply} LP-Tokens \n {datetime.datetime.now().strftime("%I:%M:%S %p")}')
# Optionally check for trading enabled'
#enabled_trading = contract.functions.tradingEnabled().call()
#if enabled_trading == False:
# print('Waiting for trading to be enabled')
# while enabled_trading == False:
# enabled_trading = dbubble_contract.functions.tradingEnabled().call()
#print('Trading enabled')
#↓↓↓↓↓↓
# HERE
#↑↑↑↑↑↑
# Buying process starts here
#nonce is required to build tx and make sure not multisending.
nonce = web3.eth.get_transaction_count(buyer)
tx = pcs_router_contract.functions.swapExactETHForTokens( #swapExactETHForTokensSupportingFeeOnTransferTokens (Optional)
0, # ∞ slippage
[spend, busd, token_address],# Path of tx
buyer, # Address that will receive the funds we buy, in this case buyer is also receiver
deadline
).buildTransaction({
'from': buyer,
'value': web3.toWei(float(value.text), 'ether'),# BNB amount we swap for
'gas': global_gas, #it seems if you do not specify the gas, it automatically use an ideal amout of gas
'gasPrice': global_gas_price,
'nonce': nonce
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key=private_key)
tx_receipt = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print (f'Sniped: https://bscscan.com/tx/{web3.toHex(tx_receipt)} @ {datetime.datetime.now().strftime("%I:%M:%S %p")}')
def pcs_snipe_usdc(self, value, address):
token_address = web3.toChecksumAddress(address.text)
buyer = Account.from_key(private_key).address
spend = wbnb
# Liquidity check starts here
liquidity_address = pcs_factory_contract.functions.getPair(token_address, usdc).call()
# Sometimes the liquidity has not been created and is not zero we need to check again
if liquidity_address == '0x0000000000000000000000000000000000000000':
print('Waiting for Liquidity Contract')
while liquidity_address == '0x0000000000000000000000000000000000000000':
liquidity_address = pcs_factory_contract.functions.getPair(token_address, usdc).call()
liquidity_contract = web3.eth.contract(address= liquidity_address, abi= settings.PCS_pair_abi)
liquidity_supply = web3.fromWei(liquidity_contract.functions.totalSupply().call(),'ether')
if liquidity_supply == 0:
print('waiting for liquidity to be added to contract ...')
while liquidity_supply == 0:
liquidity_supply = liquidity_contract.functions.totalSupply().call()
print(f'Liquidity added : {liquidity_supply} LP-Tokens \n {datetime.datetime.now().strftime("%I:%M:%S %p")}')
# Optionally check for trading enabled'
#enabled_trading = contract.functions.tradingEnabled().call()
#if enabled_trading == False:
# print('Waiting for trading to be enabled')
# while enabled_trading == False:
# enabled_trading = dbubble_contract.functions.tradingEnabled().call()
#print('Trading enabled')
#↓↓↓↓↓↓
# HERE
#↑↑↑↑↑↑
# Buying process starts here
#nonce is required to build tx and make sure not multisending.
nonce = web3.eth.get_transaction_count(buyer)
tx = pcs_router_contract.functions.swapExactETHForTokens( #swapExactETHForTokensSupportingFeeOnTransferTokens (Optional)
0, # ∞ slippage
[spend, usdc, token_address],# Path of tx
buyer, # Address that will receive the funds we buy, in this case buyer is also receiver
deadline
).buildTransaction({
'from': buyer,
'value': web3.toWei(float(value.text), 'ether'),# BNB amount we swap for
'gas': global_gas, #it seems if you do not specify the gas, it automatically use an ideal amout of gas
'gasPrice': global_gas_price,
'nonce': nonce
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key=private_key)
tx_receipt = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print (f'Sniped: https://bscscan.com/tx/{web3.toHex(tx_receipt)} @ {datetime.datetime.now().strftime("%I:%M:%S %p")}')
def pcs_snipe_usdt(self, value, address):
token_address = web3.toChecksumAddress(address.text)
buyer = Account.from_key(private_key).address
spend = wbnb
# Liquidity check starts here
liquidity_address = pcs_factory_contract.functions.getPair(token_address, usdt).call()
# Sometimes the liquidity has not been created and is not zero we need to check again
if liquidity_address == '0x0000000000000000000000000000000000000000':
print('Waiting for Liquidity Contract')
while liquidity_address == '0x0000000000000000000000000000000000000000':
liquidity_address = pcs_factory_contract.functions.getPair(token_address, usdt).call()
liquidity_contract = web3.eth.contract(address= liquidity_address, abi= settings.PCS_pair_abi)
liquidity_supply = web3.fromWei(liquidity_contract.functions.totalSupply().call(),'ether')
if liquidity_supply == 0:
print('waiting for liquidity to be added to contract ...')
while liquidity_supply == 0:
liquidity_supply = liquidity_contract.functions.totalSupply().call()
print(f'Liquidity added : {liquidity_supply} LP-Tokens \n {datetime.datetime.now().strftime("%I:%M:%S %p")}')
# Optionally check for trading enabled'
#enabled_trading = contract.functions.tradingEnabled().call()
#if enabled_trading == False:
# print('Waiting for trading to be enabled')
# while enabled_trading == False:
# enabled_trading = dbubble_contract.functions.tradingEnabled().call()
#print('Trading enabled')
#↓↓↓↓↓↓
# HERE
#↑↑↑↑↑↑
# Buying process starts here
#nonce is required to build tx and make sure not multisending.
nonce = web3.eth.get_transaction_count(buyer)
tx = pcs_router_contract.functions.swapExactETHForTokens( #swapExactETHForTokensSupportingFeeOnTransferTokens (Optional)
0, # ∞ slippage
[spend, usdt, token_address],# Path of tx
buyer, # Address that will receive the funds we buy, in this case buyer is also receiver
deadline
).buildTransaction({
'from': buyer,
'value': web3.toWei(float(value.text), 'ether'),# BNB amount we swap for
'gas': global_gas, #it seems if you do not specify the gas, it automatically use an ideal amout of gas
'gasPrice': global_gas_price,
'nonce': nonce
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key=private_key)
tx_receipt = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print (f'Sniped: https://bscscan.com/tx/{web3.toHex(tx_receipt)} @ {datetime.datetime.now().strftime("%I:%M:%S %p")}')
def pcs_snipe_cake(self, value, address):
token_address = web3.toChecksumAddress(address.text)
buyer = Account.from_key(private_key).address
spend = wbnb
# Liquidity check starts here
liquidity_address = pcs_factory_contract.functions.getPair(token_address, cake).call()
# Sometimes the liquidity has not been created and is not zero we need to check again
if liquidity_address == '0x0000000000000000000000000000000000000000':
print('Waiting for Liquidity Contract')
while liquidity_address == '0x0000000000000000000000000000000000000000':
liquidity_address = pcs_factory_contract.functions.getPair(token_address, cake).call()
liquidity_contract = web3.eth.contract(address= liquidity_address, abi= settings.PCS_pair_abi)
liquidity_supply = web3.fromWei(liquidity_contract.functions.totalSupply().call(),'ether')
if liquidity_supply == 0:
print('waiting for liquidity to be added to contract ...')
while liquidity_supply == 0:
liquidity_supply = liquidity_contract.functions.totalSupply().call()
print(f'Liquidity added : {liquidity_supply} LP-Tokens \n {datetime.datetime.now().strftime("%I:%M:%S %p")}')
# Optionally check for trading enabled'
#enabled_trading = contract.functions.tradingEnabled().call()
#if enabled_trading == False:
# print('Waiting for trading to be enabled')
# while enabled_trading == False:
# enabled_trading = dbubble_contract.functions.tradingEnabled().call()
#print('Trading enabled')
#↓↓↓↓↓↓
# HERE
#↑↑↑↑↑↑
# Buying process starts here
#nonce is required to build tx and make sure not multisending.
nonce = web3.eth.get_transaction_count(buyer)
tx = pcs_router_contract.functions.swapExactETHForTokens( #swapExactETHForTokensSupportingFeeOnTransferTokens (Optional)
0, # ∞ slippage
[spend, cake, token_address],# Path of tx
buyer, # Address that will receive the funds we buy, in this case buyer is also receiver
deadline
).buildTransaction({
'from': buyer,
'value': web3.toWei(float(value.text), 'ether'),# BNB amount we swap for
'gas': global_gas, #it seems if you do not specify the gas, it automatically use an ideal amout of gas
'gasPrice': global_gas_price,
'nonce': nonce
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key=private_key)
tx_receipt = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print (f'Sniped: https://bscscan.com/tx/{web3.toHex(tx_receipt)} @ {datetime.datetime.now().strftime("%I:%M:%S %p")}')
def sniper(self, amount, token_address):# add value and address and all inherit from it:
if pcs_bnb_pair == True:
self.snipe_bnb(amount, token_address)
elif pcs_busd_pair == True:
self.snipe_busd(amount, token_address)
elif pcs_usdc_pair == True:
self.snipe_usdc(amount, token_address)
elif pcs_usdt_pair == True:
self.snipe_usdt(amount, token_address)
elif pcs_cake_pair == True:
self.snipe_cake(amount, token_address)
else:
print ('Select a pair . . . ')
def snipe_bnb(self, value, address):
thread = threading.Thread(target= self.pcs_snipe_bnb, args=[value, address])
thread.start()
def snipe_busd(self, value, address):
thread = threading.Thread(target= self.pcs_snipe_busd, args=[value, address])
thread.start()
def snipe_usdc(self, value, address):
thread = threading.Thread(target= self.pcs_snipe_usdc, args=[value, address])
thread.start()
def snipe_usdt(self, value, address):
thread = threading.Thread(target= self.pcs_snipe_usdt, args=[value, address])
thread.start()
def snipe_cake(self, value, address):
thread = threading.Thread(target= self.pcs_snipe_cake, args=[value, address])
thread.start()
class Main_APE(GridLayout):
def pcs_snipe(self,pk, value, address):
token_address = web3.toChecksumAddress(address.text)
buyer = Account.from_key(pk.text).address
print(buyer)
spend = wbnb
# Liquidity check starts here
liquidity_address = pcs_factory_contract.functions.getPair(token_address, wbnb).call()
# Sometimes the liquidity has not been created and is not zero we need to check again
if liquidity_address == '0x0000000000000000000000000000000000000000':
print('Waiting for Liquidity Contract')
while liquidity_address == '0x0000000000000000000000000000000000000000':
liquidity_address = pcs_factory_contract.functions.getPair(token_address, wbnb).call()
liquidity_contract = web3.eth.contract(address= liquidity_address, abi= settings.PCS_pair_abi)
liquidity_supply = web3.fromWei(liquidity_contract.functions.totalSupply().call(),'ether')
if liquidity_supply == 0:
print('waiting for liquidity to be added to contract ...')
while liquidity_supply == 0:
liquidity_supply = liquidity_contract.functions.totalSupply().call()
print(f'Liquidity added : {liquidity_supply} LP-Tokens \n {datetime.datetime.now().strftime("%I:%M:%S %p")}')
# Optionally check for trading enabled'
#enabled_trading = contract.functions.tradingEnabled().call()
#if enabled_trading == False:
# print('Waiting for trading to be enabled')
# while enabled_trading == False:
# enabled_trading = dbubble_contract.functions.tradingEnabled().call()
#print('Trading enabled')
#↓↓↓↓↓↓
# HERE
#↑↑↑↑↑↑
# Buying process starts here
#nonce is required to build tx and make sure not multisending.
nonce = web3.eth.get_transaction_count(buyer)
tx = pcs_router_contract.functions.swapExactETHForTokens( #swapExactETHForTokensSupportingFeeOnTransferTokens (Optional)
0, # ∞ slippage
[spend, token_address],# Path of tx
buyer, # Address that will receive the funds we buy, in this case buyer is also receiver
deadline
).buildTransaction({
'from': buyer,
'value': web3.toWei(float(value.text), 'ether'),# BNB amount we swap for
'gas': global_gas, #it seems if you do not specify the gas, it automatically use an ideal amout of gas
'gasPrice': global_gas_price,
'nonce': nonce
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key=pk.text)
tx_receipt = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print (f'Sniped: https://bscscan.com/tx/{web3.toHex(tx_receipt)} @ {datetime.datetime.now().strftime("%I:%M:%S %p")}')
def snipe(self, pk, value, address):
thread = threading.Thread(target= self.pcs_snipe, args=[pk, value, address])
thread.start()
class SettingPage(BoxLayout):
def set_pk(self, pk):
global private_key
private_key = pk.text
def set_provider(self, url):
global provider_url, web3
provider_url = url.text
web3 = Web3(Web3.HTTPProvider(provider_url))
class SideMenu_PCS(GridLayout):
def reset_pair_pcs(self):
global pcs_bnb_pair, pcs_busd_pair, pcs_usdc_pair, pcs_usdt_pair, pcs_cake_pair
pcs_bnb_pair = False
pcs_busd_pair = False
pcs_usdc_pair = False
pcs_usdt_pair = False
pcs_cake_pair = False
def select_pair_BNB(self, btn):
global pcs_bnb_pair
self.reset_pair_pcs()
if btn.state == 'down':
pcs_bnb_pair = True
def select_pair_BUSD(self, btn):
global pcs_busd_pair
self.reset_pair_pcs()
if btn.state == 'down':
pcs_busd_pair = True
def select_pair_USDC(self, btn):
global pcs_usdc_pair
self.reset_pair_pcs()
if btn.state == 'down':
pcs_usdc_pair = True
def select_pair_USDT(self, btn):
global pcs_usdt_pair
self.reset_pair_pcs()
if btn.state == 'down':
pcs_usdt_pair = True
def select_pair_CAKE(self, btn):
global pcs_cake_pair
self.reset_pair_pcs()
if btn.state == 'down':
pcs_cake_pair = True
class SniperApp(App):
pass
#SniperApp().run()
if __name__ == '__main__':
if hasattr(sys, '_MEIPASS'):
resource_add_path(os.path.join(sys._MEIPASS))
SniperApp().run()