-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtgBuyBot.js
More file actions
1549 lines (1365 loc) Β· 84 KB
/
tgBuyBot.js
File metadata and controls
1549 lines (1365 loc) Β· 84 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
import { Telegraf, session } from "telegraf"
import { Connection, Keypair, PublicKey, Transaction, SystemProgram, LAMPORTS_PER_SOL, sendAndConfirmTransaction } from '@solana/web3.js';
import { VolumeByToken, ChainInfo, UserInfo, OpenMonitors, InfoByAmmId, createUser, deleteUser, getUserInfoByTgid, doesUserExist, findOneAndUpdateUserInfo, userinfoSchema, chainInfoSchema, openMonitorsSchema } from "./schemas.js";
//import { getHiddenData, getMenuMessageId, ifAdmin } from "./tgSystem.js"
// Import the utility functions from the module
import { getHiddenData, ifAdmin, getMenuMessageId, deleteMessage, getUserId, getUserInfoOrCreate } from './tgSystem.js';
// Adjust the import path as per your file structure
import { stringTg, customToFixed, getTokenInfo, getDividerByDecimals, verifyUserMonitors, getProviderByChain, getCoinBalances, getGasPrice, getAmountOut, getWrappedCoinByChain, getCoinNameByChain, getRouterAddressByChain, getExplorerByChain, getAmountIn, editTokenBuyMenu, getBalance, getAddressFromPrivatekey, getSolanaTokenInfo, editSolanaTokenBuyMenu, getRaydiumAmountOut, swapRaydiumExactIn } from "./blockchainSystem.js";
import _ from "lodash";
import mongoose from "mongoose"
import { ethers } from "ethers"
import contractABI from "./abi/contractABI.json" assert { type: "json" }
import BigNumber from "bignumber.js/bignumber.js";
import delugerouter from "./abi/delugerouter.json" assert { type: "json" }
import { base58 } from "ethers/lib/utils.js";
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const token = '6570174976:AAFKv6aT3ouXs46s69mJpXo847ymT3BzT1U';
const bot = new Telegraf(token);
// Connection string with username and password
mongoose.connect(`mongodb://mvt:mvt2023password@162.254.37.46:27017/admin`);
bot.use(session());
// Listen for the /start command
bot.start((ctx) => {
const chatId = ctx.chat.id;
const welcomeMessage = `
π Welcome to SolanaBuyBot!
Solana's fastest bot to trade any coin (SPL token), and Delight's official Telegram trading bot..
Feel free to explore and use the available commands. If you are just starting out, just type /panel to be able to create and manage multiple wallets.
Your private key and wallet address is provided to you on wallet creation, once you send funds you can clivk refresh to see your current balance and other useful data.
To buy a token just enter a token address
Happy chatting!`;
// Send the welcome message to the user
ctx.reply(welcomeMessage);
});
async function buySolToken(ctxToAnswer, messageWithInfo, value, usertgid, messageIdWithInfoToChange, numberofwallets) {
try {
const userinfo = await userinfoSchema.findOne({ tgid: usertgid })
const splittedMessage = messageWithInfo.text.split(`
`)
const chain = getHiddenData(messageWithInfo, 0)
const pairwith = getHiddenData(messageWithInfo, 1)
const tokendecimals = getHiddenData(messageWithInfo, 2)
const pair = getHiddenData(messageWithInfo, 3)
const tokenSymbol = getHiddenData(messageWithInfo, 4).toUpperCase()
const balance1 = getHiddenData(messageWithInfo, 5)
const balance2 = getHiddenData(messageWithInfo, 6)
const balance3 = getHiddenData(messageWithInfo, 7)
const balance4 = getHiddenData(messageWithInfo, 8)
const balance5 = getHiddenData(messageWithInfo, 9)
const balances = [balance1, balance2, balance3, balance4, balance5]
const coinbalances = await getCoinBalances(userinfo.solanaprivatekeys, 'sol')
let walletsToBuy = []
for (let x = 0; x < coinbalances.length && walletsToBuy.length != numberofwallets; x++) {
console.log(new BigNumber(coinbalances[x]).toFixed(), new BigNumber(String(ethers.utils.parseUnits(value, 10))).plus(String(ethers.utils.parseUnits('0.008', 10))).toFixed())
if (new BigNumber(coinbalances[x]).gt(new BigNumber(String(ethers.utils.parseUnits(value, 10))).plus(String(ethers.utils.parseUnits('0.008', 10))))) {
walletsToBuy.push({ privatekey: userinfo.solanaprivatekeys[x], balance: coinbalances[x] })
}
}
const wrappedCoin = new PublicKey('So11111111111111111111111111111111111111112')
if (walletsToBuy.length !== 0) {
if (walletsToBuy.length < numberofwallets) {
await ctxToAnswer.reply(`βΉοΈ You have only ${walletsToBuy.length}/${numberofwallets} wallets with enough balance to buy, buying from ${walletsToBuy.length} wallets...`).catch()
}
for (let i = 0; i < walletsToBuy.length; i++) {
const walletToBuy = walletsToBuy[i]
const amountOut = await getRaydiumAmountOut(wrappedCoin, splittedMessage[2], String(ethers.utils.parseUnits(value, 9)))
const amountOutMin = new BigNumber(amountOut).dividedBy(100).multipliedBy((100 - Number(userinfo.buyslippage))).toFixed(0)
const normAmountOutMin = stringTg(customToFixed(new BigNumber(amountOutMin).dividedBy(getDividerByDecimals(tokendecimals)).toFixed()).toLocaleString())
const signature = await swapRaydiumExactIn(splittedMessage[2], new PublicKey(wrappedCoin), new PublicKey(splittedMessage[1]), String(ethers.utils.parseUnits(value, 9)), amountOutMin, Keypair.fromSecretKey(base58.decode(walletToBuy.privatekey)))
const message = await ctxToAnswer.reply(`π‘ Your transaction sent:
*Swap ${stringTg(value)} ${getCoinNameByChain(chain)} for at least ${normAmountOutMin} ${stringTg(tokenSymbol)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${signature}`)}`, {
parse_mode: 'MarkdownV2'
}).catch()
try {
connection.confirmTransaction({ signature: signature }, 'confirmed').then(async () => {
try {
await bot.telegram.editMessageText(ctxToAnswer.chat.id, message.message_id, 0, `π’ Your transaction succeed:
*Swap ${stringTg(value)} ${getCoinNameByChain(chain)} for at least ${normAmountOutMin} ${stringTg(tokenSymbol)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${signature}`)}`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: `OK`, callback_data: 'closemenu' }]
]
}
}).catch()
} catch { }
if (i == walletsToBuy.length - 1) {
try {
const { address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith } = await getSolanaTokenInfo(splittedMessage[1], userinfo.solanaprivatekeys)
editSolanaTokenBuyMenu(message.chat.id, message.message_id, address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith, undefined)
await ctx.answerCbQuery('Monitor Successfully Refreshed.')
} catch { }
}
})
} catch {
try {
await bot.telegram.editMessageText(ctxToAnswer.chat.id, message.message_id, 0, `π΄ Your transaction failed:
*Swap ${stringTg(value)} ${getCoinNameByChain(chain)} for at least ${normAmountOutMin} ${stringTg(tokenSymbol)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: `OK`, callback_data: 'closemenu' }]
]
}
}).catch()
if (i == walletsToBuy.length - 1) {
try {
const { address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith } = await getSolanaTokenInfo(splittedMessage[1], userinfo.solanaprivatekeys)
editSolanaTokenBuyMenu(message.chat.id, message.message_id, address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith, undefined)
await ctx.answerCbQuery('Monitor Successfully Refreshed.')
} catch { }
}
} catch { }
}
try {
if (ctxToAnswer.callbackQuery) {
await ctxToAnswer.answerCbQuery()
}
} catch { }
}
} else {
await ctxToAnswer.reply(`βΉοΈ 0 of your wallets have enough ${getCoinNameByChain(chain)} to buy and pay gas fees!`).catch()
const message = await ctxToAnswer.reply(`πΆ Loading your wallets...`).catch()
return editWalletsSettings(ctxToAnswer, message.message_id)
}
} catch (e) { console.log(e) }
}
async function buyToken(ctxToAnswer, messageWithInfo, value, usertgid, messageIdWithInfoToChange, numberofwallets) {
try {
const userinfo = await getUserInfo(usertgid);
const { chain, buyGas, sellGas, buyFee, sellFee, pairwith, tokendecimals, pair, isv3pair, fee, tokenSymbol, maxBuy, maxSell, balances } = parseMessageInfo(messageWithInfo);
const chainInfo = await getChainInfo(chain);
const coinbalances = await getCoinBalances(userinfo.privatekeys, getProviderByChain(chain));
const buyGasPrice = getGasPrice(buyGas, chainInfo.gwei + userinfo.buygwei);
if (buyFee > userinfo.maxbuytax || sellFee > userinfo.maxselltax) {
await handleMaxTaxExceeded(ctxToAnswer);
return await editBuySettings(ctxToAnswer, messageIdWithInfoToChange);
}
const walletsToBuy = selectWalletsToBuy(coinbalances, value, buyGasPrice, numberofwallets);
for (let i = 0; i < walletsToBuy.length; i++) {
const walletToBuy = walletsToBuy[i];
const tx = await executeTransaction(walletToBuy, chain, pairwith, pair, isv3pair, fee, value, tokendecimals, tokenSymbol, buyFee, userinfo);
await handleTransactionResult(ctxToAnswer, tx, value, tokenSymbol, chainInfo, messageIdWithInfoToChange, i === walletsToBuy.length - 1);
}
} catch (error) {
console.error('Error in buyToken function:', error);
await handleTransactionError(ctxToAnswer);
}
}
async function buyExactToken(ctxToAnswer, messageWithInfo, out, usertgid, messageIdWithInfoToChange, numberofwallets) {
try {
const userinfo = await getUserInfo(usertgid);
const { chain, buyGas, sellGas, buyFee, sellFee, pairwith, tokendecimals, pair, isv3pair, fee, tokenSymbol, maxBuy, maxSell, balances } = parseMessageInfo(messageWithInfo);
const chainInfo = await getChainInfo(chain);
const provider = getProviderByChain(chain);
const coinbalances = await getCoinBalances(userinfo.privatekeys, provider);
const buyGasPrice = getGasPrice(buyGas, chainInfo.gwei + userinfo.buygwei);
if (buyFee > userinfo.maxbuytax || sellFee > userinfo.maxselltax) {
await handleMaxTaxExceeded(ctxToAnswer);
return await editBuySettings(ctxToAnswer, messageIdWithInfoToChange);
}
const wrappedCoin = getWrappedCoinByChain(chain);
let path, fee1, fee2;
if (pairwith !== '0x0000000000000000000000000000000000000000') {
path = [wrappedCoin, pairwith, messageWithInfo[1]];
fee1 = 500;
fee2 = fee;
} else {
path = [wrappedCoin, messageWithInfo[1]];
fee1 = fee;
fee2 = 500;
}
const amountIn = await getAmountIn(path, out, isv3pair, fee, chain);
const amountInMax = new BigNumber(amountIn).times(1 + buyFee + Number(userinfo.buyslippage)).toFixed(0);
let walletsToBuy = [];
for (let x = 0; x < coinbalances.length && walletsToBuy.length != numberofwallets; x++) {
if (new BigNumber(coinbalances[x]).gt(new BigNumber(amountInMax).plus(buyGasPrice / 10 * 12))) {
walletsToBuy.push({ privatekey: userinfo.privatekeys[x], balance: coinbalances[x] });
}
}
if (walletsToBuy.length !== 0) {
if (walletsToBuy.length < numberofwallets) {
await ctxToAnswer.reply(`βΉοΈ You have only ${walletsToBuy.length}/${numberofwallets} wallets with enough balance to buy, buying from ${walletsToBuy.length} wallets...`).catch();
}
for (let i = 0; i < walletsToBuy.length; i++) {
const walletToBuy = walletsToBuy[i];
const normAmountInMax = stringTg(customToFixed(new BigNumber(amountInMax).dividedBy(getDividerByDecimals(18)).toFixed()).toLocaleString());
const normAmountOut = stringTg(customToFixed(new BigNumber(out).dividedBy(getDividerByDecimals(tokendecimals)).toFixed()).toLocaleString());
const tx = await executeBuyExactTokenTransaction(walletToBuy, chain, pairwith, pair, isv3pair, fee, out, tokenSymbol, buyFee, userinfo, buyGasPrice, path, fee1, fee2, amountInMax);
await handleTransactionResult(ctxToAnswer, tx, out, tokenSymbol, chainInfo, messageIdWithInfoToChange, i === walletsToBuy.length - 1);
}
await refreshMonitor(ctxToAnswer, splittedMessage[1], userinfo);
} else {
await handleInsufficientFunds(ctxToAnswer, chain);
}
} catch (error) {
console.error('Error in buyExactToken function:', error);
await handleTransactionError(ctxToAnswer);
}
}
async function editWalletsSettings(ctx, messageid) {
try {
const id = getUserId(ctx);
// Use the UserInfo model with the userinfoSchema
const userinfo = await userinfoSchema.findOneAndUpdate({ tgid: id }, { $set: { lastseen: Date.now() } }, { upsert: true, new: true });
let explorer = 'etherscan.io';
let explorername = 'Etherscan';
let refreshbutton = [{ text: 'π’ Refresh', callback_data: 'switchtoeth' }];
let switchbutton = [{ text: 'π Switch To BNB Chain', callback_data: 'switchtobnb' }];
if (userinfo.menuchain === 'bnb') {
explorer = 'bscscan.com';
explorername = 'Bscscan';
refreshbutton = [{ text: 'π’ Refresh', callback_data: 'switchtobnb' }];
switchbutton = [{ text: 'π Switch To SOL Chain', callback_data: 'switchtosol' }];
} else if (userinfo.menuchain === 'sol') {
explorer = 'solscan.io';
explorername = 'Solscan';
refreshbutton = [{ text: 'π’ Refresh', callback_data: 'switchtosol' }];
switchbutton = [{ text: 'π Switch To ETH Chain', callback_data: 'switchtoeth' }];
}
} catch (error) {
console.error('Error editing user settings:', error);
}
}
async function generateWalletsMarkup(userinfo, explorer, explorername) {
let wallets = 'π« No wallets found.';
let firstline = [], secondline = [], thirdline = [];
for (let i = 0; i < userinfo.privatekeys.length; i++) {
const address = getAddressFromPrivatekey(userinfo.privatekeys[i], userinfo.menuchain);
const balance = await getBalance(address, userinfo.menuchain);
wallets += `\nπ³ ${i + 1} - Balance: ${stringTg(balance)} ${userinfo.coinsymbol} | [${explorername}](https://${explorer}/address/${address})\n\`${address}\`\n`;
if (i === 0) {
switchbutton.unshift({ text: `π§ Transfer ${userinfo.coinsymbol}`, callback_data: 'transfereth' });
}
const deleteButton = { text: `π Delete Wallet ${i + 1}`, callback_data: `isdeletewallet${i + 1}` };
if (i <= 1) {
firstline.push(deleteButton);
} else if (i > 1 && i <= 3) {
secondline.push(deleteButton);
} else if (i > 2 && i <= 5) {
thirdline.push(deleteButton);
}
}
const inline_keyboard = [
firstline, secondline, thirdline, [],
[{ text: 'π₯ Import New Wallet', callback_data: 'importwallet' }, { text: 'β Generate New Wallet', callback_data: 'generatewallet' }],
[{ text: 'π Back', callback_data: 'edittopanel' }]
];
inline_keyboard.push(switchbutton, refreshbutton);
return `π *All added wallets:*\n\n${wallets}`;
}
async function editBuySettings(ctx, messageid) {
try {
let userId;
if (ctx.chat.type === 'private') {
userId = ctx.callbackQuery ? ctx.callbackQuery.from.id : ctx.message.from.id;
} else {
throw new Error('This command is only available in private chats.');
}
const userInfo = await getUserInfo(userId);
const messageText = generateSettingsMessage(userInfo);
const inlineKeyboard = generateSettingsKeyboard(userInfo);
await bot.telegram.editMessageText(ctx.chat.id, messageid, undefined, messageText, {
parse_mode: 'MarkdownV2',
reply_markup: {
inline_keyboard: inlineKeyboard
},
disable_web_page_preview: true
});
} catch (error) {
console.log("Error:", error.message);
}
}
async function getUserInfo(userId) {
let user = { tgid: userId };
if (!(await userinfoSchema.exists(user))) {
await userinfoSchema.create(user);
}
return await userinfoSchema.findOne(user);
}
function generateSettingsMessage(userInfo) {
return `βοΈ *Your Settings:*
βΉοΈ *Slippage* - Edit the percentage by which you are willing to receive less tokens because of the price increase (if you are buying) / decrease (if you are selling) during the processing period of your transaction in blockchain.
\`Default Number Of Wallets: ${userInfo.defaultnumberofwallets}\` \| Each buy menu will open initially with that number of wallets
Buy Gwei: Default + ${userInfo.buygwei} \| Use it to speed up your buys
Sell Gwei: Default + ${userInfo.sellgwei} \| Use it to speed up your sells
Approve Gwei: Default + ${userInfo.approvegwei} \| Use it to speed up your approves after buys
Buy Slippage: ${userInfo.buyslippage}%
Sell Slippage: ${userInfo.sellslippage}%
Max Buy Tax: ${userInfo.maxbuytax}% \| Use this to avoid buying when buy taxes are too high
Max Sell Tax: ${userInfo.maxselltax}% \| Use this to avoid selling when sell taxes are too high`;
}
function generateSettingsKeyboard(userInfo) {
return [
[{ text: `π³ Default Number Of Wallets: ${userInfo.defaultnumberofwallets}`, callback_data: 'editdefaultnumberofwallets' }],
[{ text: `β½οΈ Buy Gwei: +${userInfo.buygwei} Gwei`, callback_data: 'editbuygwei' }, { text: `β½οΈ Sell Gwei: +${userInfo.sellgwei} Gwei`, callback_data: 'editsellgwei' }],
[{ text: `β½οΈ Approve Gwei: Default + ${userInfo.approvegwei} Gwei`, callback_data: 'editapprovegwei' }],
[{ text: `π Max Buy Tax: ${userInfo.maxbuytax}%`, callback_data: 'editmaxbuytax' }, { text: `π Max Sell Tax: ${userInfo.maxselltax}%`, callback_data: 'editmaxselltax' }],
[{ text: `π§ Buy Slippage: ${userInfo.buyslippage}%`, callback_data: 'editbuyslippage' }, { text: `π§ Sell Slippage: ${userInfo.sellslippage}%`, callback_data: 'editsellslippage' }],
[{ text: `π Back`, callback_data: 'edittopanel' }]
];
}
async function editPanelSettings(ctx, messageid) {
try {
let id
try {
if (ctx.chat.type === 'private') {
id = { tgid: ctx.callbackQuery.from.id }
}
}
catch {
if (ctx.chat.type === 'private') {
id = { tgid: ctx.message.from.id }
}
}
if (!await userinfoSchema.exists(id)) {
await userinfoSchema.create(id)
}
if (messageid) {
await bot.telegram.editMessageText(ctx.chat.id, messageid, null, `π₯οΈ *Your Settings:*`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: 'βοΈ Tx Settings', callback_data: 'edittobuysettings' }],
[{ text: 'πΌ Manage Wallets', callback_data: 'edittomanagewallets' }]
]
}, disable_web_page_preview: true
}).catch()
} else {
await ctx.editMessageText(`π₯οΈ *Your Settings:*`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: 'βοΈ Tx Settings', callback_data: 'edittobuysettings' }],
[{ text: 'πΌ Manage Wallets', callback_data: 'edittomanagewallets' }]
]
}, disable_web_page_preview: true
}).catch()
}
} catch { }
}
// Edit Menu Actions
bot.action('edittopanel', async (ctx) => {
try {
editPanelSettings(ctx)
} catch { }
}).catch()
bot.action('switchtobnb', async (ctx) => {
try {
let id
if (ctx.chat.type === 'private') {
id = { tgid: ctx.callbackQuery.from.id }
}
const userinfo = await userinfoSchema.findOneAndUpdate(id, { menuchain: 'bnb' })
await userinfoSchema.findOneAndUpdate(id, { menuchain: 'bnb' })
if (userinfo.menuchain == 'bnb') {
editWalletsSettings(ctx)
await ctx.answerCbQuery('Refreshed')
} else {
editWalletsSettings(ctx)
}
} catch (e) { console.log(e) }
}).catch()
bot.action('switchtoeth', async (ctx) => {
try {
let id
if (ctx.chat.type === 'private') {
id = { tgid: ctx.callbackQuery.from.id }
}
const userinfo =await userinfoSchema.findOneAndUpdate(id, { menuchain: 'eth' })
if (userinfo.menuchain == 'eth') {
editWalletsSettings(ctx)
await ctx.answerCbQuery('Refreshed')
} else {
editWalletsSettings(ctx)
}
} catch (e) { }
}).catch()
bot.action('switchtosol', async (ctx) => {
try {
let id
if (ctx.chat.type === 'private') {
id = { tgid: ctx.callbackQuery.from.id }
}
const userinfo = await userinfoSchema.findOneAndUpdate(id, { menuchain: 'sol' })
if (userinfo.menuchain == 'sol') {
editWalletsSettings(ctx)
await ctx.answerCbQuery('Refreshed')
} else {
editWalletsSettings(ctx)
}
} catch (e) { console.log(e)}
}).catch()
bot.action('switchtosell', async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const message = ctx.callbackQuery.message
const chain = getHiddenData(message, 0)
if (chain !== 'sol') {
if (!userinfo.solanaprivatekeys) {
await ctx.reply('βοΈ You need to add at least 1 wallet to buy tokens.').catch()
}
const splittedMessage = message.text.split(`
`)
const { address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee } = await getTokenInfo(splittedMessage[1], userinfo.privatekeys)
editTokenBuyMenu(message.chat.id, message.message_id, address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee, true)
} else {
if (!userinfo.privatekeys) {
await ctx.reply('βοΈ You need to add at least 1 wallet to buy tokens.').catch()
}
const splittedMessage = message.text.split(`
`)
const { address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith } = await getSolanaTokenInfo(splittedMessage[1], userinfo.solanaprivatekeys)
editSolanaTokenBuyMenu(message.chat.id, message.message_id, address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith, true)
}
await ctx.answerCbQuery('Monitor Successfully Refreshed.')
} catch (e) { console.log(e) }
}).catch()
bot.action('switchtobuy', async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const message = ctx.callbackQuery.message
const chain = getHiddenData(message, 0)
if (chain !== 'sol') {
if (!userinfo.solanaprivatekeys) {
await ctx.reply('βοΈ You need to add at least 1 wallet to buy tokens.').catch()
}
const splittedMessage = message.text.split(`
`)
const { address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee } = await getTokenInfo(splittedMessage[1], userinfo.privatekeys)
editTokenBuyMenu(message.chat.id, message.message_id, address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee, false)
} else {
if (!userinfo.privatekeys) {
await ctx.reply('βοΈ You need to add at least 1 wallet to buy tokens.').catch()
}
const splittedMessage = message.text.split(`
`)
const { address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith } = await getSolanaTokenInfo(splittedMessage[1], userinfo.solanaprivatekeys)
editSolanaTokenBuyMenu(message.chat.id, message.message_id, address, pair, name, symbol, balances, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, pairwith, false)
}
await ctx.answerCbQuery('Monitor Successfully Refreshed.')
} catch (e) { console.log(e) }
}).catch()
bot.action('changenumberofwallets', async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberOfWallets = Number(text.substring(text.length - 1))
let newNumberOfWallets
if (userinfo.privatekeys.length > numberOfWallets) {
newNumberOfWallets = numberOfWallets + 1
} else {
newNumberOfWallets = 1
}
let keyboard = ctx.callbackQuery.message.reply_markup.inline_keyboard
keyboard.shift()
keyboard.unshift([{ text: `π³ Wallets To Buy: ${newNumberOfWallets}`, callback_data: 'changenumberofwallets' }])
await ctx.editMessageReplyMarkup({ inline_keyboard: keyboard })
} catch (e) { console.log(e) }
}).catch()
bot.action('editdefaultnumberofwallets', async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberOfWallets = Number(text.substring(text.length - 1))
let newNumberOfWallets
if (userinfo.privatekeys.length > numberOfWallets) {
newNumberOfWallets = numberOfWallets + 1
} else {
newNumberOfWallets = 1
}
await userinfoSchema.findOneAndUpdate({ tgid: ctx.callbackQuery.from.id }, { defaultnumberofwallets: newNumberOfWallets })
editBuySettings(ctx)
} catch (e) { console.log(e) }
}).catch()
bot.action('edittomanagewallets', async (ctx) => {
try {
editWalletsSettings(ctx)
} catch { }
}).catch()
bot.action('edittobuysettings', async (ctx) => {
try {
editBuySettings(ctx)
} catch { }
}).catch()
bot.action('editwalletssettings', async (ctx) => {
try {
editWalletsSettings(ctx)
} catch { }
}).catch()
const soldata3 = [{ name: `buysoltoken1`, value: '0.01' }, { name: `buysoltoken2`, value: '0.5' }, { name: `buysoltoken3`, value: '1' }, { name: `buysoltoken4`, value: '2' }, { name: `buysoltoken5`, value: '5' }, { name: `buysoltoken6`, value: '10' }]
for (let i = 0; i < soldata3.length; i++) {
bot.action(soldata3[i].name, async (ctx) => {
try {
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberOfWallets = Number(text.substring(text.length - 1))
buySolToken(ctx, ctx.callbackQuery.message, soldata3[i].value, ctx.callbackQuery.from.id, ctx.callbackQuery.message.message_id, Number(numberOfWallets))
} catch (e) { console.log(e) }
})
}
const data3 = [{ name: `buytoken1`, value: '0.05' }, { name: `buytoken2`, value: '0.1' }, { name: `buytoken3`, value: '0.3' }, { name: `buytoken4`, value: '0.5' }, { name: `buytoken5`, value: '1' }, { name: `buytoken6`, value: '3' }]
for (let i = 0; i < data3.length; i++) {
bot.action(data3[i].name, async (ctx) => {
try {
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberOfWallets = Number(text.substring(text.length - 1))
buyToken(ctx, ctx.callbackQuery.message, data3[i].value, ctx.callbackQuery.from.id, ctx.callbackQuery.message.message_id, Number(numberOfWallets))
} catch (e) { console.log(e) }
})
}
bot.action(`buyxeth`, async (ctx) => {
try {
const splittedMessage = ctx.callbackQuery.message.text.split(`
`)
const chain = getHiddenData(ctx.callbackQuery.message, 0)
const buyGas = getHiddenData(ctx.callbackQuery.message, 1)
const sellGas = getHiddenData(ctx.callbackQuery.message, 2)
const buyFee = getHiddenData(ctx.callbackQuery.message, 3)
const sellFee = getHiddenData(ctx.callbackQuery.message, 4)
const pairwith = getHiddenData(ctx.callbackQuery.message, 5)
const tokendecimals = getHiddenData(ctx.callbackQuery.message, 6)
const pair = getHiddenData(ctx.callbackQuery.message, 7)
const isv3pair = getHiddenData(ctx.callbackQuery.message, 8)
const fee = getHiddenData(ctx.callbackQuery.message, 9)
const tokenSymbol = getHiddenData(ctx.callbackQuery.message, 10)
const maxBuy = getHiddenData(ctx.callbackQuery.message, 11)
const maxSell = getHiddenData(ctx.callbackQuery.message, 12)
const balance1 = getHiddenData(ctx.callbackQuery.message, 13)
const balance2 = getHiddenData(ctx.callbackQuery.message, 14)
const balance3 = getHiddenData(ctx.callbackQuery.message, 15)
const balance4 = getHiddenData(ctx.callbackQuery.message, 16)
const balance5 = getHiddenData(ctx.callbackQuery.message, 17)
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberofwallets = Number(text.substring(text.length - 1))
await ctx.reply(`[β](https://${chain}.com/)[β](https://${buyGas}.com/)[β](https://${sellGas}.com/)[β](https://${buyFee}.com/)[β](https://${sellFee}.com/)[β](https://${pairwith}.com/)[β](https://${tokendecimals}.com/)[β](https://${pair}.com/)[β](https://${isv3pair}.com/)[β](https://${fee}.com/)[β](https://${tokenSymbol}.com/)[β](https://${maxBuy}.com/)[β](https://${maxSell}.com/)[β](https://${balance1}.com/)[β](https://${balance2}.com/)[β](https://${balance3}.com/)[β](https://${balance4}.com/)[β](https://${balance5}.com/)[β](https://${ctx.callbackQuery.message.message_id}.com/)[β](https://${numberofwallets}.com/)βοΈ *Buy Exact ETH\\/BNB\ With ${numberofwallets} Wallet*
\`${splittedMessage[1]}\
To proceed, enter the amount of ETH\\/BNB will be spent on the buy\\.`, {
parse_mode: 'MarkdownV2', reply_markup: {
force_reply: true
}, disable_web_page_preview: true
}).catch()
await ctx.answerCbQuery().catch()
} catch (e) { console.log(e) }
})
bot.action(`buymax`, async (ctx) => {
try {
const maxBuy = getHiddenData(ctx.callbackQuery.message, 11)
const tokendecimals = getHiddenData(ctx.callbackQuery.message, 6)
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberofwallets = Number(text.substring(text.length - 1))
const out = new BigNumber(maxBuy).multipliedBy(getDividerByDecimals(tokendecimals)).minus(1).toFixed(0)
buyExactToken(ctx, ctx.callbackQuery.message, out, ctx.callbackQuery.from.id, ctx.callbackQuery.message.message_id, Number(numberofwallets))
await ctx.answerCbQuery().catch()
} catch (e) { console.log(e) }
})
bot.action(`buyxtokens`, async (ctx) => {
try {
const splittedMessage = ctx.callbackQuery.message.text.split(`
`)
const chain = getHiddenData(ctx.callbackQuery.message, 0)
const buyGas = getHiddenData(ctx.callbackQuery.message, 1)
const sellGas = getHiddenData(ctx.callbackQuery.message, 2)
const buyFee = getHiddenData(ctx.callbackQuery.message, 3)
const sellFee = getHiddenData(ctx.callbackQuery.message, 4)
const pairwith = getHiddenData(ctx.callbackQuery.message, 5)
const tokendecimals = getHiddenData(ctx.callbackQuery.message, 6)
const pair = getHiddenData(ctx.callbackQuery.message, 7)
const isv3pair = getHiddenData(ctx.callbackQuery.message, 8)
const fee = getHiddenData(ctx.callbackQuery.message, 9)
const tokenSymbol = getHiddenData(ctx.callbackQuery.message, 10)
const maxBuy = getHiddenData(ctx.callbackQuery.message, 11)
const maxSell = getHiddenData(ctx.callbackQuery.message, 12)
const balance1 = getHiddenData(ctx.callbackQuery.message, 13)
const balance2 = getHiddenData(ctx.callbackQuery.message, 14)
const balance3 = getHiddenData(ctx.callbackQuery.message, 15)
const balance4 = getHiddenData(ctx.callbackQuery.message, 16)
const balance5 = getHiddenData(ctx.callbackQuery.message, 17)
const text = ctx.callbackQuery.message.reply_markup.inline_keyboard[0][0].text
const numberofwallets = Number(text.substring(text.length - 1))
await ctx.reply(`[β](https://${chain}.com/)[β](https://${buyGas}.com/)[β](https://${sellGas}.com/)[β](https://${buyFee}.com/)[β](https://${sellFee}.com/)[β](https://${pairwith}.com/)[β](https://${tokendecimals}.com/)[β](https://${pair}.com/)[β](https://${isv3pair}.com/)[β](https://${fee}.com/)[β](https://${tokenSymbol}.com/)[β](https://${maxBuy}.com/)[β](https://${maxSell}.com/)[β](https://${balance1}.com/)[β](https://${balance2}.com/)[β](https://${balance3}.com/)[β](https://${balance4}.com/)[β](https://${balance5}.com/)[β](https://${ctx.callbackQuery.message.message_id}.com/)[β](https://${numberofwallets}.com/)βοΈ *Buy Exact Tokens With ${numberofwallets} Wallet*
\`${splittedMessage[1]}\`
To proceed, enter the number of tokens you intend to buy \\(can be in \\% of supply\\)\\.`, {
parse_mode: 'MarkdownV2', reply_markup: {
force_reply: true
}, disable_web_page_preview: true
}).catch()
await ctx.answerCbQuery().catch()
} catch (e) { console.log(e) }
})
const data4 = [{ name: `sellwallet125`, wallet: 0, percent: 25 }, { name: `sellwallet150`, wallet: 0, percent: 50 }, { name: `sellwallet175`, wallet: 0, percent: 75 }, { name: `sellwallet1100`, wallet: 0, percent: 100 },
{ name: `sellwallet225`, wallet: 1, percent: 25 }, { name: `sellwallet250`, wallet: 1, percent: 50 }, { name: `sellwallet275`, wallet: 1, percent: 75 }, { name: `sellwallet2100`, wallet: 1, percent: 100 },
{ name: `sellwallet325`, wallet: 2, percent: 25 }, { name: `sellwallet350`, wallet: 2, percent: 50 }, { name: `sellwallet375`, wallet: 2, percent: 75 }, { name: `sellwallet3100`, wallet: 2, percent: 100 },
{ name: `sellwallet425`, wallet: 3, percent: 25 }, { name: `sellwallet450`, wallet: 3, percent: 50 }, { name: `sellwallet475`, wallet: 3, percent: 75 }, { name: `sellwallet4100`, wallet: 3, percent: 100 },
{ name: `sellwallet525`, wallet: 4, percent: 25 }, { name: `sellwallet550`, wallet: 4, percent: 50 }, { name: `sellwallet575`, wallet: 4, percent: 75 }, { name: `sellwallet5100`, wallet: 4, percent: 100 },]
for (let i = 0; i < data4.length; i++) {
bot.action(data4[i].name, async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const splittedMessage = ctx.callbackQuery.message.text.split(`
`)
const chain = getHiddenData(ctx.callbackQuery.message, 0)
const buyGas = getHiddenData(ctx.callbackQuery.message, 1)
const sellGas = getHiddenData(ctx.callbackQuery.message, 2)
const buyFee = getHiddenData(ctx.callbackQuery.message, 3)
const sellFee = getHiddenData(ctx.callbackQuery.message, 4)
const pairwith = getHiddenData(ctx.callbackQuery.message, 5)
const tokendecimals = getHiddenData(ctx.callbackQuery.message, 6)
const pair = getHiddenData(ctx.callbackQuery.message, 7)
const isv3pair = getHiddenData(ctx.callbackQuery.message, 8)
const fee = getHiddenData(ctx.callbackQuery.message, 9)
const tokenSymbol = getHiddenData(ctx.callbackQuery.message, 10)
const maxBuy = getHiddenData(ctx.callbackQuery.message, 11)
const maxSell = getHiddenData(ctx.callbackQuery.message, 12)
const balance1 = getHiddenData(ctx.callbackQuery.message, 13)
const balance2 = getHiddenData(ctx.callbackQuery.message, 14)
const balance3 = getHiddenData(ctx.callbackQuery.message, 15)
const balance4 = getHiddenData(ctx.callbackQuery.message, 16)
const balance5 = getHiddenData(ctx.callbackQuery.message, 17)
const balances = [balance1, balance2, balance3, balance4, balance5]
const tokensToSell = new BigNumber(balances[data4[i].wallet]).dividedBy(100).multipliedBy(data4[i].percent).toFixed(0)
const chainInfo = await chainInfoSchema.findOne({ chain: chain })
const provider = getProviderByChain(chain)
if (buyFee > userinfo.maxbuytax || sellFee > userinfo.maxselltax) {
await ctx.reply(`βΉοΈ According to your settings, your max tax is less than the token tax at the moment. Did you missclicked?`).catch()
const message = await ctx.reply(`πΆ Loading your settings...`).catch()
return editBuySettings(ctx, message.message_id)
}
let walletToSell = { privatekey: userinfo.privatekeys[data4[i].wallet], balance: 0 }
let signerWallet = new ethers.Wallet(walletToSell.privatekey, getProviderByChain(chain))
walletToSell.balance = Number(String(await provider.getBalance(signerWallet.address)))
const gwei = chainInfo.gwei
const sellGasPrice = getGasPrice(sellGas, gwei + userinfo.sellgwei)
if (new BigNumber(walletToSell.balance).gt(Number(sellGasPrice) / 10 * 12)) {
let tx
let path
let fee1
let fee2
const wrappedCoin = getWrappedCoinByChain(chain)
if (pairwith !== '0x0000000000000000000000000000000000000000') {
path = [splittedMessage[1], pairwith, wrappedCoin]
fee1 = 500
fee2 = fee
} else {
path = [splittedMessage[1], wrappedCoin]
fee1 = fee
fee2 = 500
}
const amountOut = await getAmountOut(path, tokensToSell, isv3pair, fee, chain)
const amountOutMin = new BigNumber(amountOut).dividedBy(100).multipliedBy((100 - sellFee - Number(userinfo.sellslippage))).toFixed(0)
const normAmountOutMin = stringTg(customToFixed(new BigNumber(amountOutMin).dividedBy(getDividerByDecimals(18)).toFixed()).toLocaleString())
const normAmountIn = stringTg(customToFixed(new BigNumber(tokensToSell).dividedBy(getDividerByDecimals(tokendecimals)).toFixed()).toLocaleString())
const signerdelugeRouter = new ethers.Contract(getRouterAddressByChain(chain), delugerouter, signerWallet)
if (isv3pair !== 'false') {
const estimate = String(await signerdelugeRouter.estimateGas.tradeV3(fee1, fee2, tokensToSell, amountOutMin, path, 0))
if (new BigNumber(getGasPrice(Number(Number(estimate) / 10 * 12).toFixed(0), Number(chainInfo.gwei + userinfo.buygwei).toFixed(0))).gt(walletToSell.balance)) {
return await ctxToAnswer.reply(`π΄ Not enough funds on your wallet #${i + 1} to send the buy transaction, please top up your wallet and try again.`).catch()
}
tx = await signerdelugeRouter.tradeV3(fee1, fee2, tokensToSell, amountOutMin, path, 0, { gasLimit: Number(Number(estimate) / 10 * 12).toFixed(0), gasPrice: Number((chainInfo.gwei + userinfo.sellgwei) * 1000000000).toFixed(0) })
} else {
const estimate = String(await signerdelugeRouter.estimateGas.tradeV2(splittedMessage[1], wrappedCoin, tokensToSell, amountOutMin, pairwith, 0))
if (new BigNumber(getGasPrice(Number(Number(estimate) / 10 * 12).toFixed(0), Number(chainInfo.gwei + userinfo.sellgwei).toFixed(0))).gt(walletToSell.balance)) {
return await ctx.reply(`π΄ Not enough funds on your wallet #${data4[i].wallet + 1} to send the sell transaction, please top up your wallet and try again.`).catch()
}
tx = await signerdelugeRouter.tradeV2(splittedMessage[1], wrappedCoin, tokensToSell, amountOutMin, pairwith, 0, { gasLimit: Number(Number(estimate) / 10 * 12).toFixed(0), gasPrice: Number((chainInfo.gwei + userinfo.sellgwei) * 1000000000).toFixed(0) })
}
const message = await ctx.reply(`π‘ Your transaction sent:
*Swap ${normAmountIn} ${stringTg(tokenSymbol)} for at least ${normAmountOutMin} ${getCoinNameByChain(chain)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2'
}).catch()
try {
tx.wait().then(async () => {
try {
await bot.telegram.editMessageText(ctx.chat.id, message.message_id, 0, `π’ Your transaction succeed:
*Swap ${normAmountIn} ${stringTg(tokenSymbol)} for at least ${normAmountOutMin} ${getCoinNameByChain(chain)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: `OK`, callback_data: 'closemenu' }]
]
}
}).catch()
const { address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee } = await getTokenInfo(splittedMessage[1], userinfo.privatekeys)
editTokenBuyMenu(ctx.callbackQuery.message.chat.id, ctx.callbackQuery.message.message_id, address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee, undefined)
await ctx.answerCbQuery('Monitor Successfully Refreshed.')
} catch { }
})
} catch {
try {
await bot.telegram.editMessageText(ctx.chat.id, message.message_id, 0, `π΄ Your transaction failed:
*Swap ${normAmountIn} ${stringTg(tokenSymbol)} for at least ${normAmountOutMin} ${getCoinNameByChain(chain)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: `OK`, callback_data: 'closemenu' }]
]
}
}).catch()
} catch { }
}
await ctx.answerCbQuery().catch()
} else {
await ctx.reply(`βΉοΈ Your wallets don't have enough to pay gas fee!`).catch()
const message = await ctx.reply(`πΆ Loading your wallets...`).catch()
return editWalletsSettings(ctx, message.message_id)
}
} catch (e) { console.log(e) }
})
}
bot.action(`sellallwallets`, async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const splittedMessage = ctx.callbackQuery.message.text.split(`
`)
const chain = getHiddenData(ctx.callbackQuery.message, 0)
const buyGas = getHiddenData(ctx.callbackQuery.message, 1)
const sellGas = getHiddenData(ctx.callbackQuery.message, 2)
const buyFee = getHiddenData(ctx.callbackQuery.message, 3)
const sellFee = getHiddenData(ctx.callbackQuery.message, 4)
const pairwith = getHiddenData(ctx.callbackQuery.message, 5)
const tokendecimals = getHiddenData(ctx.callbackQuery.message, 6)
const pair = getHiddenData(ctx.callbackQuery.message, 7)
const isv3pair = getHiddenData(ctx.callbackQuery.message, 8)
const fee = getHiddenData(ctx.callbackQuery.message, 9)
const tokenSymbol = getHiddenData(ctx.callbackQuery.message, 10)
const maxBuy = getHiddenData(ctx.callbackQuery.message, 11)
const maxSell = getHiddenData(ctx.callbackQuery.message, 12)
const balance1 = getHiddenData(ctx.callbackQuery.message, 13)
const balance2 = getHiddenData(ctx.callbackQuery.message, 14)
const balance3 = getHiddenData(ctx.callbackQuery.message, 15)
const balance4 = getHiddenData(ctx.callbackQuery.message, 16)
const balance5 = getHiddenData(ctx.callbackQuery.message, 17)
const balances = [balance1, balance2, balance3, balance4, balance5]
const chainInfo = await chainInfoSchema.findOne({ chain: chain })
const provider = getProviderByChain(chain)
if (buyFee > userinfo.maxbuytax || sellFee > userinfo.maxselltax) {
await ctx.reply(`βΉοΈ According to your settings, your max tax is less than the token tax at the moment. Did you missclicked?`).catch()
const message = await ctx.reply(`πΆ Loading your settings...`).catch()
return editBuySettings(ctx, message.message_id)
}
const gwei = chainInfo.gwei
const sellGasPrice = Number(getGasPrice(sellGas, gwei + userinfo.sellgwei)) / 10 * 12
const coinName = getCoinNameByChain(chain)
let walletsToCheckBalance = userinfo.privatekeys
let walletsToSell = []
for (let i = 0; i < walletsToCheckBalance.length; i++) {
if (balances[i] == 0) continue
let signerWallet = new ethers.Wallet(walletsToCheckBalance[i], getProviderByChain(chain))
const balance = Number(String(await provider.getBalance(signerWallet.address)))
if (balance > sellGasPrice) {
walletsToSell.push({ balance: balance, privatekey: walletsToCheckBalance[i], toSell: balances[i] })
} else {
const dif = new BigNumber(balance).minus(sellGasPrice).plus(1000000000000000).toFixed(0)
const topup = ethers.utils.parseUnits(dif, 'wei')
await ctx.reply(`Your wallet #${i + 1} has not enough ${coinName} balance to send transaction, please top it up with ${topup} ${coinName} to be sure it is enough to pay gas fees.`).catch()
}
}
for (let i = 0; i < walletsToSell.length; i++) {
const signerWallet = new ethers.Wallet(walletsToSell[i].privatekey, getProviderByChain(chain))
const tokensToSell = walletsToSell[i].toSell
let tx
let path
let fee1
let fee2
const wrappedCoin = getWrappedCoinByChain(chain)
if (pairwith !== '0x0000000000000000000000000000000000000000') {
path = [splittedMessage[1], pairwith, wrappedCoin]
fee1 = 500
fee2 = fee
} else {
path = [splittedMessage[1], wrappedCoin]
fee1 = fee
fee2 = 500
}
const amountOut = await getAmountOut(path, tokensToSell, isv3pair, fee, chain)
const amountOutMin = new BigNumber(amountOut).dividedBy(100).multipliedBy((100 - sellFee - Number(userinfo.sellslippage))).toFixed(0)
const normAmountOutMin = stringTg(customToFixed(new BigNumber(amountOutMin).dividedBy(getDividerByDecimals(18)).toFixed()).toLocaleString())
const normAmountIn = stringTg(customToFixed(new BigNumber(tokensToSell).dividedBy(getDividerByDecimals(tokendecimals)).toFixed()).toLocaleString())
const signerdelugeRouter = new ethers.Contract(getRouterAddressByChain(chain), delugerouter, signerWallet)
if (isv3pair !== 'false') {
const estimate = String(await signerdelugeRouter.estimateGas.tradeV3(fee1, fee2, tokensToSell, amountOutMin, path, 0))
if (new BigNumber(getGasPrice(Number(Number(estimate) / 10 * 12).toFixed(0), Number(chainInfo.gwei + userinfo.buygwei).toFixed(0))).gt(walletsToSell[i].balance)) {
return await ctxToAnswer.reply(`π΄ Not enough funds on your wallet #${i + 1} to send the buy transaction, please top up your wallet and try again.`).catch()
}
tx = await signerdelugeRouter.tradeV3(fee1, fee2, tokensToSell, amountOutMin, path, 0, { gasLimit: Number(Number(estimate) / 10 * 12).toFixed(0), gasPrice: Number((chainInfo.gwei + userinfo.sellgwei) * 1000000000).toFixed(0) })
} else {
const estimate = String(await signerdelugeRouter.estimateGas.tradeV2(splittedMessage[1], wrappedCoin, tokensToSell, amountOutMin, pairwith, 0))
if (new BigNumber(getGasPrice(Number(Number(estimate) / 10 * 12).toFixed(0), Number(chainInfo.gwei + userinfo.sellgwei).toFixed(0))).gt(walletsToSell[i].balance)) {
return await ctx.reply(`π΄ Not enough funds on your wallet #${data4[i].wallet + 1} to send the sell transaction, please top up your wallet and try again.`).catch()
}
tx = await signerdelugeRouter.tradeV2(splittedMessage[1], wrappedCoin, tokensToSell, amountOutMin, pairwith, 0, { gasLimit: Number(Number(estimate) / 10 * 12).toFixed(0), gasPrice: Number((chainInfo.gwei + userinfo.sellgwei) * 1000000000).toFixed(0) })
}
const message = await ctx.reply(`π‘ Your transaction sent:
*Swap ${normAmountIn} ${stringTg(tokenSymbol)} for at least ${normAmountOutMin} ${getCoinNameByChain(chain)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2'
}).catch()
try {
tx.wait().then(async () => {
try {
await bot.telegram.editMessageText(ctx.chat.id, message.message_id, 0, `π’ Your transaction succeed:
*Swap ${normAmountIn} ${stringTg(tokenSymbol)} for at least ${normAmountOutMin} ${getCoinNameByChain(chain)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: `OK`, callback_data: 'closemenu' }]
]
}
}).catch()
const { address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee } = await getTokenInfo(splittedMessage[1], userinfo.privatekeys)
editTokenBuyMenu(ctx.callbackQuery.message.chat.id, ctx.callbackQuery.message.message_id, address, pair, name, symbol, balances, contractBalance, price, coinprice, tokendecimals, coindecimals, coinsymbol, explorer, chart, totalSupply, maxBuy, maxSell, buyFee, sellFee, buyGas, sellGas, gwei, pairwith, isv3pair, fee, undefined)
await ctx.answerCbQuery('Monitor Successfully Refreshed.')
} catch { }
})
} catch {
try {
await bot.telegram.editMessageText(ctx.chat.id, message.message_id, 0, `π΄ Your transaction failed:
*Swap ${normAmountIn} ${stringTg(tokenSymbol)} for at least ${normAmountOutMin} ${getCoinNameByChain(chain)}\\.*
${stringTg(`https://${getExplorerByChain(chain)}/tx/${tx.hash}`)}`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: `OK`, callback_data: 'closemenu' }]
]
}
}).catch()
} catch { }
}
}
await ctx.answerCbQuery().catch()
} catch (e) { console.log(e) }
})
for (let i = 0; i < 5; i++) {
bot.action(`sellwallet${i + 1}`, async (ctx) => {
try {
await ctx.editMessageReplyMarkup({
inline_keyboard: [
[{ text: `Sell 25% Of Wallet`, callback_data: `sellwallet${i + 1}25` }, { text: `Sell 50% Of Wallet`, callback_data: `sellwallet${i + 1}50` }],
[{ text: `Sell 75% Of Wallet`, callback_data: `sellwallet${i + 1}75` }, { text: `Sell 100% Of Wallet`, callback_data: `sellwallet${i + 1}100` }],
[{ text: `π Back`, callback_data: `switchtosell` }]
]
}).catch()
} catch { }
})
}
for (let i = 0; i < 5; i++) {
bot.action(`deletewallet${i + 1}`, async (ctx) => {
try {
const chain = getHiddenData(ctx.callbackQuery.message, 0)
if (chain == 'sol') {
let id = { tgid: ctx.callbackQuery.from.id }
const wallets = await userinfoSchema.findOne(id)
wallets.solanaprivatekeys.splice(i, 1)
await wallets.save()
} else {
let id = { tgid: ctx.callbackQuery.from.id }
const wallets = await userinfoSchema.findOne(id)
wallets.privatekeys.splice(i, 1)
await wallets.save()
}
editWalletsSettings(ctx)
} catch { }
})
}
for (let i = 0; i < 5; i++) {
bot.action(`isdeletewallet${i + 1}`, async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
let chainstext
if (userinfo.menuchain == 'sol') {
chainstext = 'SOL'
}
else if (userinfo.menuchain == 'eth') {
chainstext = 'ETH\\(and BNB\\)'
} else if (userinfo.menuchain == 'bnb') {
chainstext = 'BNB\\(and ETH\\)'
}
await ctx.editMessageText(`[β](https://${userinfo.menuchain}.com/)π Are you sure you want to delete *Wallet \\#${i}* on *${chainstext}* chain\\?
βΉοΈ Don\\'t delete wallet if you haven\\'t saved all private keys or you have money in some wallet in bot\\.`, {
parse_mode: 'MarkdownV2', reply_markup: {
inline_keyboard: [
[{ text: 'π Yes, I\'m Sure', callback_data: `deletewallet${i + 1}` }, { text: `π Back`, callback_data: 'editwalletssettings' }]
]
}
}).catch()
} catch { }
})
}
for (let i = 0; i < 5; i++) {
bot.action(`fromwallet${i + 1}`, async (ctx) => {
try {
const userinfo = await userinfoSchema.findOne({ tgid: ctx.callbackQuery.from.id })
const chain = getHiddenData(ctx.callbackQuery.message, 0)
let coinsymbol = getCoinNameByChain(chain)
let firstline = []
let secondline = []
let thirdline = []
let fourthline = []
let fifthline = []
let privatekeys = userinfo.privatekeys
if (chain == 'sol') {