-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
8147 lines (7449 loc) · 280 KB
/
index.js
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
require("dotenv").config();
const Discord = require("discord.js");
const clientCountdown = new Discord.Client();
clientCountdown.login(process.env.BOT_TOKEN_COUNTDOWN);
const BASE_APY_INF = process.env.BASE_APY_INF;
const clientGameCountdown = new Discord.Client();
clientGameCountdown.login(process.env.BOT_TOKEN_GAME_COUNTDOWN);
const clientThalesL2APR = new Discord.Client();
clientThalesL2APR.login(process.env.BOT_TOKEN_THALES_L2_APR);
const clientARBAPR = new Discord.Client();
clientARBAPR.login(process.env.BOT_TOKEN_ARB_APR);
const clientThalesOPCountdown = new Discord.Client();
clientThalesOPCountdown.login(process.env.BOT_TOKEN_OPTHALES_COUNTDOWN);
const clientRoyaleMainnetCountdown = new Discord.Client();
clientRoyaleMainnetCountdown.login(process.env.BOT_TOKEN_TROYALEM_COUNTDOWN);
const clientRoyalePingingBot = new Discord.Client();
clientRoyalePingingBot.login(process.env.BOT_TOKEN_ROYALE_PING);
const clientMATICBot = new Discord.Client();
clientMATICBot.login(process.env.BOT_TOKEN_MATIC);
const clientKWENTABot = new Discord.Client();
clientKWENTABot.login(process.env.BOT_TOKEN_KWENTA);
const clientARBPriceBot = new Discord.Client();
clientARBPriceBot.login(process.env.BOT_TOKEN_ARB_PRICE);
const clientGMXBot = new Discord.Client();
clientGMXBot.login(process.env.BOT_TOKEN_GMX);
const clientILVBot = new Discord.Client();
clientILVBot.login(process.env.BOT_TOKEN_ILV);
const clientThalesBot = new Discord.Client();
const clientMagicBot = new Discord.Client();
clientMagicBot.login(process.env.BOT_TOKEN_MAGIC);
clientThalesBot.login(process.env.BOT_TOKEN_THLS_PRICE);
const clientETHPriceBot = new Discord.Client();
clientETHPriceBot.login(process.env.BOT_TOKEN_ETH_PRICE);
const clientLiqOPOT = new Discord.Client();
clientLiqOPOT.login(process.env.BOT_TOKEN_LQ_OP_OT);
const clientLiqOPTHLS = new Discord.Client();
clientLiqOPTHLS.login(process.env.BOT_TOKEN_LQ_OP_THLS);
const clientLiqARBOT = new Discord.Client();
clientLiqARBOT.login(process.env.BOT_TOKEN_LQ_ARB_OT);
const clientLiqARBThales = new Discord.Client();
clientLiqARBThales.login(process.env.BOT_TOKEN_LQ_ARB_THLS);
const clientLiqParlayOP = new Discord.Client();
clientLiqParlayOP.login(process.env.BOT_TOKEN_LQ_PARLAY_OP);
const clientLiqParlayARB = new Discord.Client();
clientLiqParlayARB.login(process.env.BOT_TOKEN_LQ_PARLAY_ARB);
const clientLiqV2USDC = new Discord.Client();
clientLiqV2USDC.login(process.env.BOT_TOKEN_LQ_V2_USDC);
const clientLiqV2THALES = new Discord.Client();
clientLiqV2THALES.login(process.env.BOT_TOKEN_LQ_V2_THALES);
const clientLiqV2WETH = new Discord.Client();
clientLiqV2WETH.login(process.env.BOT_TOKEN_LQ_V2_WETH);
const clientTPV = new Discord.Client();
clientTPV.login(process.env.BOT_TOKEN_TPV);
const clientUsers = new Discord.Client();
clientUsers.login(process.env.BOT_TOKEN_USERS);
var fs = require("fs");
const { CCIPCollector } = require('./cc.js');
const client = new Discord.Client();
let contentRaw = fs.readFileSync("content.json");
const axios = require("axios");
let answersContent = JSON.parse(contentRaw);
let qaMaps = new Map();
let aprRAW = fs.readFileSync('contracts/apr.json');
let aprContract = JSON.parse(aprRAW);
let contractRaw = fs.readFileSync("contracts/erc20Contract.json");
let polygonRaw = fs.readFileSync('contracts/polygon.json');
const thalesData = require("thales-data");
const SYNTH_USD_MAINNET = "0x57ab1ec28d129707052df4df418d58a2d46d5f51";
const clientNewListings = new Discord.Client();
const clientETHBurned = new Discord.Client();
const clientCountdownChannel = new Discord.Client();
const clientTotalL2Trades = new Discord.Client();
clientTotalL2Trades.login(process.env.BOT_TOKEN_TOTAL_L2);
const clientOvertimeTrades = new Discord.Client();
clientOvertimeTrades.login(process.env.BOT_TOKEN_TOTAL_OT);
const clientBSCTrades = new Discord.Client();
clientBSCTrades.login(process.env.BOT_TOKEN_TOTAL_BSC);
const clientARBTrades = new Discord.Client();
clientARBTrades.login(process.env.BOT_TOKEN_TOTAL_ARB);
clientCountdownChannel.login(process.env.BOT_TOKEN_COUNTDOWN_CHANNEL);
const clientTotalPolygonTrades = new Discord.Client();
clientTotalPolygonTrades.login(process.env.BOT_TOKEN_TOTAL_POLYGON);
const triviaBot = new Discord.Client();
triviaBot.login(process.env.BOT_TOKEN_TRIVIA);
const Web3 = require("web3");
let speedMarketRaw = fs.readFileSync('contracts/speedMarket.json');
let speedMarketContract = JSON.parse(speedMarketRaw);
let speedMarketDataRaw = fs.readFileSync('contracts/speedMarketDataContract.json');
let speedMarketDataContract = JSON.parse(speedMarketDataRaw);
let contract = JSON.parse(contractRaw);
let polygonContract = JSON.parse(polygonRaw);
let burnedRaw = fs.readFileSync('contracts/burned.json');
let contractBurned = JSON.parse(burnedRaw);
const web3Polygon = new Web3(new Web3.providers.HttpProvider("https://polygon-mainnet.infura.io/v3/71f890a2441d49088e4e145b2bc23bc7"));
const web3Arbitrum = new Web3(new Web3.providers.HttpProvider("https://arbitrum-mainnet.infura.io/v3/71f890a2441d49088e4e145b2bc23bc7"));
const web3ZKSYNC = new Web3(new Web3.providers.HttpProvider("https://mainnet.era.zksync.io"));
const web3BSC = new Web3(new Web3.providers.HttpProvider("https://winter-spring-frost.bsc.discover.quiknode.pro/360e06c724df630e0a6aa4417dedfb41142a3184/"));
let bscRaw = fs.readFileSync('contracts/bsc.json');
let bscContract = JSON.parse(bscRaw);
let arbitrumRaw = fs.readFileSync('contracts/arbitrum.json');
let arbitrumContract = JSON.parse(arbitrumRaw);
const web3 = new Web3(new Web3.providers.HttpProvider(process.env.INFURA_URL));
const web3L2 = new Web3(new Web3.providers.HttpProvider(process.env.INFURA_L2_URL));
const web3Base = new Web3(new Web3.providers.HttpProvider("https://mainnet.base.org"));
const CoinGecko = require('coingecko-api');
const CoinGeckoClient = new CoinGecko();
const clientUniswap = new Discord.Client();
clientUniswap.login(process.env.BOT_TOKEN_UNISWAP);
const clientBTC = new Discord.Client();
clientBTC.login(process.env.BOT_TOKEN_BTC);
const clientLink = new Discord.Client();
clientLink.login(process.env.BOT_TOKEN_LINK);
const clientAAVE = new Discord.Client();
clientAAVE.login(process.env.BOT_TOKEN_AAVE);
const clientCURVE = new Discord.Client();
clientCURVE.login(process.env.BOT_TOKEN_CURVE);
const clientSTARGATE = new Discord.Client();
clientSTARGATE.login(process.env.BOT_TOKEN_STARGATE);
const clientLUNA = new Discord.Client();
clientLUNA.login(process.env.BOT_TOKEN_LUNA);
const clientLYRA = new Discord.Client();
clientLYRA.login(process.env.BOT_TOKEN_LYRA);
const clientOP = new Discord.Client();
clientOP.login(process.env.BOT_TOKEN_OP);
const clientOHM = new Discord.Client();
clientOHM.login(process.env.BOT_TOKEN_OHM);
const clientAPE = new Discord.Client();
clientAPE.login(process.env.BOT_TOKEN_APE);
const clientCVX = new Discord.Client();
clientCVX.login(process.env.BOT_TOKEN_CVX);
const clientPERP = new Discord.Client();
clientPERP.login(process.env.BOT_TOKEN_PERP);
const clientTotalBurnedThales = new Discord.Client();
clientTotalBurnedThales.login(process.env.BOT_TOKEN_TOTAL_BURNED_THALES);
const clientOverTimeArbTotal = new Discord.Client();
clientOverTimeArbTotal.login(process.env.BOT_TOKEN_OVERTIME_ARB);
const clientOPSTAKE = new Discord.Client();
clientOPSTAKE.login(process.env.BOT_OP_STAKE);
const clientBASESTAKE = new Discord.Client();
clientBASESTAKE.login(process.env.BOT_BASE_STAKE);
const oddslib = require('oddslib');
let contractV2OTRaw = fs.readFileSync('contracts/v2overtime.json');
let v2ContractRaw = JSON.parse(contractV2OTRaw);
let v2Contract = new web3L2.eth.Contract(v2ContractRaw,"0x2367FB44C4C2c4E5aAC62d78A55876E01F251605");
let contractV2TicketRaw = fs.readFileSync('contracts/v2overtimeTicket.json');
let v2ContractTicketRaw = JSON.parse(contractV2TicketRaw);
let v2TicketContract = new web3L2.eth.Contract(v2ContractTicketRaw,"0x71CE219942FFD9C1d8B67d6C35C39Ae04C4F647B");
let liqV2Raw = fs.readFileSync('contracts/liqV2THALES.json');
let liqV2Contract = JSON.parse(liqV2Raw);
let mapThalesTrades = new Map();
let mapThalesAsks = new Map();
let mapThalesBids = new Map();
let deckardMM = "0x71C5a24F6eDe7861A32A5f81AF5b1B70Ff250B80";
let almaMM = "0x036b8c9f7C31713c3a47863afe0031630395FaCD";
let sladeMM = "0xC0E554C1951c0193E020156F68Dce15064769937";
let nonMMordersList = new Array();
nonMMordersList.push(
"0x6eb3f5d9b8f83fef7411709e0dfb42da9d4a85da",
"0xd558914fa43581584b460bba220f25175bbcf67a",
"0xd76224d26b01e9733a0e67209929b2eadff67d36",
"0x924ef47993be036ebe72be1449d8bef627cd30a2",
"0x036b8c9f7c31713c3a47863afe0031630395facd",
"0xc0e554c1951c0193e020156f68dce15064769937",
"0x71c5a24f6ede7861a32a5f81af5b1b70ff250b80"
);
let parlayAMMList = new Array();
parlayAMMList.push(
"0x82b3634c0518507d5d817be6dab6233ebe4d68d9",
"0x2bb7d689780e7a34dd365359bd7333ab24903268",
"0x5625c3233b52206a5f23c5fc1ce16f6a7e3874dd"
);
const fetch = require("node-fetch");
const thalesGraphURL =
"https://api.thegraph.com/subgraphs/name/thales-markets/thales-markets";
const ethers = require("ethers");
const provider = ethers.getDefaultProvider();
let walletTest = new ethers.Wallet(
ethers.Wallet.createRandom().privateKey,
provider
);
const stakingThalesABI = require("./contracts/StakingThales.js");
const stakingContract = new ethers.Contract(
"0x883D651429B0829BC045A94F288f3b514021B8C1",
stakingThalesABI.stakingthales.abi,
walletTest
);
let burnedContract = new web3L2.eth.Contract(contractBurned, "0x217D47011b23BB961eB6D93cA9945B7501a5BB11");
let deadburnedContract = new web3.eth.Contract(contractBurned, "0x8947da500eb47f82df21143d0c01a29862a8c3c5");
let deadARBburnedContract = new web3Arbitrum.eth.Contract(contractBurned, "0xe85b662fe97e8562f4099d8a1d5a92d4b453bf30");
let baseburnedContract = new web3Base.eth.Contract(contractBurned, "0xf34e0cff046e154cafcae502c7541b9e5fd8c249");
const gelatoContract = require("./contracts/GelatoContract.js");
let contractRoyaleRaw = fs.readFileSync('contracts/royale.json');
let contractRoyale = JSON.parse(contractRoyaleRaw);
let royaleContract = new web3L2.eth.Contract(contractRoyale, "0x3198ab211CdF3E4d13a698E1Fb819507BcA2e579");
let contractARBThalesRaw = fs.readFileSync('contracts/thalesARB.json');
let arbThalesContractRaw = JSON.parse(contractARBThalesRaw);
let arbThalesContract = new web3Arbitrum.eth.Contract(arbThalesContractRaw,"0x160Ca569999601bca06109D42d561D85D6Bb4b57");
let contractECROWRaw = fs.readFileSync('contracts/thalesECROW.json');
let ecrowThalesContractRaw = JSON.parse(contractECROWRaw);
let ecrowThalesContract = new web3Arbitrum.eth.Contract(ecrowThalesContractRaw,"0x391a45F31c1837E3d837c23e05F42A098329D50d");
let opThalesContract = new web3L2.eth.Contract(arbThalesContractRaw,"0xC392133eEa695603B51a5d5de73655d571c2CE51");
let ecrowOPThalesContract = new web3L2.eth.Contract(ecrowThalesContractRaw,"0xa25816b9605009aa446d4d597F0AA46FD828f056");
let baseThalesContract = new web3Base.eth.Contract(arbThalesContractRaw,"0x84aB38e42D8Da33b480762cCa543eEcA6135E040");
let ecrowBASEThalesContract = new web3Base.eth.Contract(ecrowThalesContractRaw,"0x29dfc5fee05578CD913c75fF1C7A0d315595939A");
let speedMarketZKSYNCRaw = fs.readFileSync('contracts/speedMarketZKSYNC.json');
let speedMarketZKSYNCContract = JSON.parse(speedMarketZKSYNCRaw);
let speedMarketZKSYNCDataRaw = fs.readFileSync('contracts/speedMarketZKSYNCDataContract.json');
let speedMarketZKSYNCDataContract = JSON.parse(speedMarketZKSYNCDataRaw);
const speedZKSYNCContract = new web3ZKSYNC.eth.Contract(speedMarketZKSYNCContract, "0x508F31897c25C436b257E37763E157Cb53D0a6fa");
const speedDataMarketZKSYNCContract = new web3ZKSYNC.eth.Contract(speedMarketZKSYNCDataContract, "0x6356454D76642c72edb9170EF1102418D656887d");
let mapSladeMM = new Map();
let mapAlmaMM = new Map();
let mapDeckardMM = new Map();
let mapMint = new Map();
let nonMMOrdersMap = new Map();
let setConcludedTradesPastHour = new Set();
const Twitter = require('twitter-api-v2');
// Instantiate with desired auth type (here's Bearer v2 auth)
const twitterClientOvertimeAMMMarket = new Twitter.TwitterApi(
{
appKey: process.env.TWITTER_OVERTIME_AMM_CONSUMER_KEY,
appSecret: process.env.TWITTER_OVERTIME_AMM_CONSUMER_SECRET,
accessToken: process.env.TWITTER_OVERTIME_AMM_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_OVERTIME_AMM_TOKEN_SECRET,
}
);
const twitterClientAMMMarket = new Twitter.TwitterApi(
{
appKey: process.env.TWITTER_AMM_CONSUMER_KEY,
appSecret: process.env.TWITTER_AMM_CONSUMER_SECRET,
accessToken: process.env.TWITTER_AMM_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_AMM_TOKEN_SECRET,
}
);
answersContent.forEach((a) => {
qaMaps.set(a.number, a.content);
});
clientTotalBurnedThales.once("ready", () => {
console.log("updating Burned Thales on ready");
getBurnedThalesBalance();
});
clientCountdown.once("ready", () => {
console.log("updateCountdown on ready");
updateCountdown();
});
clientGameCountdown.once("ready", () => {
console.log("update Game Countdown on ready");
updateGameCountdown();
});
clientRoyaleMainnetCountdown.once("ready", () => {
console.log("update clientRoyaleMainnetCountdown on ready");
updateThalesRoyaleMainnetCountdown();
});
clientThalesOPCountdown.once("ready", () => {
console.log("update clientThalesOPCountdown Countdown on ready");
//updateThalesOPCountdown();
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
/*clientMagicBot.once("ready", () => {
setPriceBot(clientMagicBot,"magic","Magic");
});*/
clientThalesBot.once("ready", () => {
setPriceBot(clientThalesBot,"thales","Thales");
});
/*clientThalesBot.once("ready", () => {
setPriceBot(clientETHPriceBot,"ethereum","ETH");
});*/
clientILVBot.once("ready", () => {
setPriceBot(clientILVBot,"illuvium","ILV");
});
/*clientBTC.on("ready", () => {
setPriceBot(clientBTC,"bitcoin","BTC");
});*/
/*clientLink.on("ready", () => {
setPriceBot(clientLink,"chainlink","LINK");
});*/
/*clientOP.on("ready", () => {
setPriceBot(clientOP,"optimism","OP");
});*/
/*clientMATICBot.on("ready", () => {
setPriceBot(clientMATICBot,"matic-network","MATIC");
});*/
clientKWENTABot.once("ready", () => {
setPriceBot(clientKWENTABot,"kwenta","KWENTA");
});
/*clientARBPriceBot.once("ready", () => {
setPriceBot(clientARBPriceBot,"arbitrum","ARB");
});*/
/*clientGMXBot.once("ready", () => {
setPriceBot(clientGMXBot,"gmx","GMX");
});*/
setInterval(function () {
console.log("updating price bots");
/* setPriceBot(clientBTC,"bitcoin","BTC");
setPriceBot(clientThalesBot,"thales","Thales");
setPriceBot(clientETHPriceBot,"ethereum","ETH");*/
setPriceBot(clientILVBot,"illuvium","ILV");
// setPriceBot(clientLink,"chainlink","LINK");
}, 30 * 60 * 1000);
setInterval(function () {
console.log("updating price 2 bots");
/* setPriceBot(clientOP,"optimism","OP");
setPriceBot(clientMATICBot,"matic-network","MATIC");*/
setPriceBot(clientKWENTABot,"kwenta","KWENTA");
/* setPriceBot(clientARBPriceBot,"arbitrum","ARB");
setPriceBot(clientGMXBot,"gmx","GMX");
setPriceBot(clientMagicBot,"magic","Magic");*/
}, 10 * 60 * 1000);
const setPriceBot = async (clientForSetting,tokenForPrice,nameOfTheToken) => {
let data = await CoinGeckoClient.coins.fetch(tokenForPrice);
if(data.data && data.data.market_data){
clientForSetting.guilds.cache.forEach(function (value, key) {
try {
console.log("Updating "+nameOfTheToken+" Price info " + data.data.market_data.current_price.usd);
if(data.data.market_data.price_change_percentage_24h>0){
value.members.cache.get(clientForSetting.user.id).setNickname(nameOfTheToken.toUpperCase() +" $"+ data.data.market_data.current_price.usd+"(↗)");
}else{
value.members.cache.get(clientForSetting.user.id).setNickname(nameOfTheToken.toUpperCase() +" $"+ data.data.market_data.current_price.usd+"(↘)");
}
} catch (e) {
console.log(e);
}
});
if(data.data.market_data.price_change_percentage_24h>0){
clientForSetting.user.setActivity("24h:+"+Math.round(data.data.market_data.price_change_percentage_24h * 100) / 100+"%", {type: 'WATCHING'});
}else{
clientForSetting.user.setActivity("24h:"+Math.round(data.data.market_data.price_change_percentage_24h * 100) / 100+"%", {type: 'WATCHING'});
}
}
}
const round = function (num) {
var m = Number((Math.abs(num) * 100).toPrecision(15));
return Math.round(m) / 100 * Math.sign(num);
}
const updateCountdown = async () => {
let stakingContractL2= new web3L2.eth.Contract(stakingThalesABI.stakingthales.abi, "0xC392133eEa695603B51a5d5de73655d571c2CE51");
const lastPeriodTimeStamp = await stakingContractL2.methods.lastPeriodTimeStamp().call();
const durationPeriod = await stakingContractL2.methods.durationPeriod().call();
let closingDate = new Date(
lastPeriodTimeStamp * 1000.0 + durationPeriod * 1000.0
);
console.log("lastPeriodTS", lastPeriodTimeStamp);
console.log("durationPeriod", durationPeriod);
console.log("closingDate", closingDate.getTime());
if (clientCountdown) {
clientCountdown.guilds.cache.forEach(function (value, key) {
try {
value.members.cache
.get(clientCountdown.user.id)
.setNickname("Staking rewards");
} catch (e) {
console.log(e);
}
});
}
let endDateUTC = new Date(closingDate.toUTCString());
let currentDate = new Date(new Date().toUTCString());
var distance = endDateUTC.getTime() - currentDate.getTime();
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
clientCountdown.user.setActivity(days + "D:" + hours + "H:" + minutes + "M", {
type: "WATCHING",
});
};
const updateGameCountdown = async () => {
if (clientGameCountdown) {
clientGameCountdown.guilds.cache.forEach(function (value, key) {
try {
value.members.cache
.get(clientGameCountdown.user.id)
.setNickname("Tale of Thales");
} catch (e) {
console.log(e);
}
});
}
clientGameCountdown.user.setActivity("Live: https://thalesmarket.io/tale-of-thales", {
type: "WATCHING",
});
};
const updateThalesRoyaleMainnetCountdown = async () => {
if (clientRoyaleMainnetCountdown) {
clientRoyaleMainnetCountdown.guilds.cache.forEach(function (value, key) {
try {
value.members.cache
.get(clientRoyaleMainnetCountdown.user.id)
.setNickname("Thales Royale Optimism");
} catch (e) {
console.log(e);
}
});
}
let endDateUTC = new Date("May 26, 2022 16:00:00 UTC")
let currentDate = new Date(new Date().toUTCString());
let distance;
if(currentDate.getTime()>endDateUTC.getTime()){
let currentTimestamp = Math.floor(Date.now() / 1000);
const roundInASeasonStartTime = await royaleContract.methods.roundInASeasonStartTime(seasonNumber).call();
const roundChoosingLength = await royaleContract.methods.roundChoosingLength().call();
let positioningEnd = Number(roundInASeasonStartTime)+Number(roundChoosingLength);
if(currentTimestamp<positioningEnd){
distance = (Number(positioningEnd) - currentTimestamp) * 1000;
}else{
const roundLength = await royaleContract.methods.roundLength().call();
let roundEnd = Number(roundInASeasonStartTime)+Number(roundLength);
distance = (Number(roundEnd) - currentTimestamp) * 1000;
}
}
else{
distance = endDateUTC.getTime() - currentDate.getTime();
}
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
clientRoyaleMainnetCountdown.user.setActivity(days + "D:" + hours + "H:" + minutes + "M", {
type: "WATCHING",
});
};
/*const updateThalesOPCountdown = async () => {
let response = await axios.get('https://api.1inch.exchange/v3.0/10/quote?fromTokenAddress=0x217D47011b23BB961eB6D93cA9945B7501a5BB11&toTokenAddress=0x7f5c764cbc14f9669b88837ca1490cca17c31607&amount=1000000000000000000000');
let thalesOPValue= Math.round((response.data.toTokenAmount/1000000000) * 100) / 100;
if (thalesOPValue) {
clientThalesOPCountdown.guilds.cache.forEach(function (value, key) {
try {
value.members.cache
.get(clientThalesOPCountdown.user.id)
.setNickname("$"+thalesOPValue);
} catch (e) {
console.log(e);
}
});
}
clientThalesOPCountdown.user.setActivity("OpTHALES", {
type: "WATCHING",
});
};*/
setInterval(function () {
console.log("updateCountdown and eth burned");
updateCountdown();
updateThalesRoyaleMainnetCountdown();
//updateThalesOPCountdown();
updateGameCountdown();
getBurnedThalesBalance();
}, 360 * 1000);
setInterval(function () {
console.log("get L2 trades");
getL2Trades();
getBASETrades();
getPolygonTrades();
getArbitrumTrades();
getBSCTrades();
}, 2 * 60 * 1000);
client.on("guildMemberAdd", function (member) {
const exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Welcome");
exampleEmbed.addField(
"Hi, I am Thales FAQ bot. Welcome to the official Thales Discord channel!"
);
exampleEmbed.addField(
"About Thales",
"Thales platform is bringing binary options to Ethereum for users to hedge and speculate on the prices of crypto assets, commodities," +
" equities, equity indices, and proprietary crypto indices."
);
exampleEmbed.addField(
"FAQ bot",
"For any questions, please feel free to ask me and I will look through the list of FAQs I have. We get can get started if you send me a message with content ***help***" +
"\n" +
"Best, \n" +
"Thales Team"
);
member.send(exampleEmbed);
});
client.on("messageReactionAdd", (reaction, user) => {
let msg = reaction.message,
emoji = reaction.emoji;
if (emoji.name == "❌") {
if (msg.author.username.toLowerCase().includes("counselor")) {
if (!user.username.toLowerCase().includes("counselor")) {
msg.delete({ timeout: 300 /*time unitl delete in milliseconds*/ });
}
}
}
});
function doInnerQuestion(command, doReply, msg) {
let discordUserFAQ = "<@!" + msg.author.id + ">";
try {
let answer = qaMaps.get(command * 1.0);
const exampleEmbed = new Discord.MessageEmbed();
exampleEmbed.setColor(answer.color);
exampleEmbed.setTitle(answer.title);
exampleEmbed.setDescription(answer.description);
exampleEmbed.setURL(answer.url);
answer.fields.forEach(function (field) {
exampleEmbed.addField(field.title, field.value, field.inline);
});
if (answer.footer.title) {
exampleEmbed.setFooter(answer.footer.title, answer.footer.value);
}
if (answer.image) {
exampleEmbed
.attachFiles(["images/" + answer.image])
.setImage("attachment://" + answer.image);
}
if (answer.thumbnail) {
exampleEmbed
.attachFiles(["images/" + answer.thumbnail])
.setThumbnail("attachment://" + answer.thumbnail);
}
if (doReply) {
msg.reply(exampleEmbed);
} else {
msg.channel
.send(exampleEmbed)
.then(function (message) {
message.react("❌");
})
.catch(function () {
//Something
});
}
// }
} catch (e) {
if (doReply) {
msg.reply(
discordUserFAQ+ " Oops, there seems to be something wrong there. \nChoose your question with ***question questionNumber***, e.g. **question 1**\nYou can get the question number via **list**"
);
} else {
msg.reply(
discordUserFAQ+ " Oops, there seems to be something wrong there. \nChoose your question with ***!FAQ question questionNumber***, e.g. **question 1**\nYou can get the question number if you send me **list** in DM"
);
}
}
}
client.on("message", (msg) => {
if (!msg.author.username.toLowerCase().includes("counselor")) {
if (!(msg.channel.type == "dm")) {
// this is logic for channels
let discordUserFAQ = "<@!" + msg.author.id + ">";
if (msg.content.toLowerCase().trim() == "!faq") {
msg.reply(
"Hi "+discordUserFAQ +", I am Thales FAQ bot. I will be very happy to assist you, just ask me for **help** in DM."
);
} else if (msg.content.toLowerCase().trim() == "!faq help") {
msg.reply(
discordUserFAQ+" I can only answer a predefined question by its number or by alias in a channel, e.g. **question 1**, or **how do binary options work?**. \n For more commands and options send me **help** in DM"
);
} else if (
msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "")
.startsWith("!faq question")
) {
doQuestion(msg, "!faq question", false);
} else if (
msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "")
.startsWith("!faq q ")
) {
doQuestion(msg, "!faq q", false);
} else if (
msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "")
.startsWith("!faq q")
) {
const args = msg.content.slice("!faq q".length);
if (!isNaN(args)) {
doInnerQuestion(args, false, msg);
}
} else if (
msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "")
.startsWith("!faq ")
) {
let found = checkAliasMatching(false);
if (!found) {
let notFoundMessage =
discordUserFAQ+" Oops, I don't know that one. DM me ***list*** or ***aliases*** to see which questions and commands I know.";
msg.channel
.send(notFoundMessage)
.then(function (message) {
message.react("❌");
})
.catch(function () {
//Something
});
}
}
} else {
try {
// this is the logic for DM
console.log("I got sent a DM:" + msg.content);
let found = checkAliasMatching(true);
// if alias is found, just reply to it, otherwise continue
if (!found) {
if (msg.content.toLowerCase().trim() == "aliases") {
showAllAliases(true);
} else if (msg.content.toLowerCase().trim() == "help") {
doFaqHelp();
} else if (msg.content.startsWith("help ")) {
const args = msg.content.slice("help".length).split(" ");
args.shift();
const command = args.shift().trim();
if (command == "question") {
msg.reply(
"Choose your question with ***question questionNumber***, e.g. ***question 1***\nYou can get the question number via **list** command"
);
} else if (command == "category") {
msg.reply(
"Choose your category with ***category categoryName***, e.g. ***category General***\nCategory name is fetched from **categories** command"
);
} else if (command == "search") {
msg.reply(
"Search for questions with ***search searchTerm***, e.g. ***search thales protocol***"
);
} else {
msg.reply(
"I don't know that one. Try just **help** for known commands"
);
}
} else if (
msg.content.toLowerCase().trim() == "list" ||
msg.content.toLowerCase().trim() == "questions"
) {
listQuestions();
} else if (msg.content.toLowerCase().startsWith("question ")) {
console.log("question asked:" + msg.content);
doQuestion(msg, "question", true);
} else if (msg.content.toLowerCase().startsWith("q ")) {
console.log("question asked:" + msg.content);
doQuestion(msg, "q", true);
} else if (
msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "")
.startsWith("q")
) {
const args = msg.content.slice("q".length);
if (!isNaN(args)) {
doInnerQuestion(args, true, msg);
}
} else if (msg.content == "categories") {
listCategories();
} else if (msg.content.toLowerCase().startsWith("category")) {
const args = msg.content.slice("category".length).split(" ");
args.shift();
const command = args.shift();
let rawdata = fs.readFileSync("categories/categories.json");
let categories = JSON.parse(rawdata);
const exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Questions in category " + command + ":");
let found = false;
categories.forEach(function (category) {
if (category.name == command) {
found = true;
category.questions.forEach(function (question) {
exampleEmbed.addField(
question,
qaMaps.get(question).description,
false
);
});
}
});
if (!found) {
exampleEmbed.addField(
"\u200b",
"That doesn't look like a known category. Use a category name from **categories** command, e.g. **category General**"
);
} else {
exampleEmbed.addField(
"\u200b",
"Choose your question with e.g. **question 1**"
);
}
msg.reply(exampleEmbed);
} else if (msg.content.toLowerCase().startsWith("search ")) {
const args = msg.content.slice("search".length).split(" ").slice(1);
const searchWord = msg.content.substring("search".length + 1);
doSearch(searchWord, args);
} else if (
msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "")
.startsWith("show chart")
) {
let content = msg.content
.toLowerCase()
.trim()
.replace(/ +(?= )/g, "");
const args = content.slice("show chart".length).split(" ");
args.shift();
const command = args.shift().trim();
doShowChart(command, msg, true);
} else {
if (!msg.author.username.toLowerCase().includes("counselor")) {
if (msg.content.endsWith("?")) {
const args = msg.content
.substring(0, msg.content.length - 1)
.split(" ");
const searchWord = msg.content;
doCustomQuestion(searchWord, args);
} else {
msg.reply(
"Oops, I don't know that one. Try **help** to see what I do know, or if you want to ask a custom question, make sure it ends with a question mark **?**"
);
}
}
}
}
} catch (e) {
console.log(e);
msg.reply(
"Unknown error ocurred. Try **help** to see what I do know, or if you want to ask a custom question, make sure it ends with a question mark **?**"
);
}
}
}
function showAllAliases(isDM) {
let rawdata = fs.readFileSync("categories/aliases.json");
let aliases = JSON.parse(rawdata);
let questionMap = new Map();
aliases.forEach(function (alias) {
let aliasQuestion = questionMap.get(alias.number);
if (aliasQuestion) {
aliasQuestion.push(alias.alias);
questionMap.set(alias.number, aliasQuestion);
} else {
let aliasQuestion = new Array();
aliasQuestion.push(alias.alias);
questionMap.set(alias.number, aliasQuestion);
}
});
let exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Known aliases")
.setURL("https://github.com/thales-markets/community-bots");
exampleEmbed.setDescription("Hello, here are the aliases I know:");
let counter = 0;
let pagenumber = 2;
for (let [questionNumber, questions] of questionMap) {
let questionsString = "";
questions.forEach(function (q) {
questionsString += (isDM ? "" : "!faq ") + q + "\n";
});
let answer = qaMaps.get(questionNumber);
exampleEmbed.addField(
answer.title + " " + answer.description,
questionsString
);
counter++;
if (counter == 10) {
if (isDM) {
msg.reply(exampleEmbed);
} else {
msg.channel
.send(exampleEmbed)
.then(function (message) {
message.react("❌");
})
.catch(function () {
//Something
});
}
exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Known aliases page " + pagenumber)
.setURL("https://github.com/thales-markets/community-bots");
exampleEmbed.setDescription("Hello, here are the aliases I know:");
pagenumber++;
counter = 0;
}
}
if (isDM) {
msg.reply(exampleEmbed);
} else {
msg.channel
.send(exampleEmbed)
.then(function (message) {
message.react("❌");
})
.catch(function () {
//Something
});
}
}
function checkAliasMatching(doReply) {
let potentialAlias = msg.content.toLowerCase().replace("!faq", "").trim();
let rawdata = fs.readFileSync("categories/aliases.json");
let aliases = JSON.parse(rawdata);
let found = false;
aliases.forEach(function (alias) {
if (alias.alias.toLowerCase().trim() == potentialAlias) {
found = true;
msg.content = "!faq question " + alias.number;
doQuestion(msg, "!faq question", doReply);
}
});
return found;
}
function doFaqHelp() {
const exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Thales Frequently Asked Questions")
.setURL("https://docs.thales.market/getting-started/faqs");
exampleEmbed.setDescription("Hello, here is list of commands I know:");
exampleEmbed.addField("list", "Lists all known questions");
exampleEmbed.addField(
"categories",
"Lists all categories of known questions"
);
exampleEmbed.addField(
"category categoryName",
"Lists all known questions for a given category name, e.g. ** category *General* **"
);
exampleEmbed.addField(
"question questionNumber",
"Shows the answer to the question defined by its number, e.g. ** question *7* **"
);
exampleEmbed.addField(
"search searchTerm",
"Search all known questions by given search term, e.g. ** search *gas price* **"
);
exampleEmbed.addField("aliases", "List all known aliases");
exampleEmbed.addField(
"\u200b",
"*Or just ask me a question and I will do my best to find a match for you, e.g. **What order books is Thales using?***"
);
msg.reply(exampleEmbed);
}
function listQuestions() {
let exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Frequently Asked Questions")
.setURL("https://docs.thales.market/getting-started/faqs");
let counter = 0;
let pagenumber = 2;
qaMaps.forEach((value, key) => {
exampleEmbed.addField(key, value.description, false);
counter++;
if (counter == 20) {
msg.reply(exampleEmbed);
exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Frequently Asked Questions page " + pagenumber)
.setURL("https://docs.thales.market/getting-started/faqs");
pagenumber++;
counter = 0;
}
});
msg.reply(exampleEmbed);
}
function listCategories() {
let rawdata = fs.readFileSync("categories/categories.json");
let categories = JSON.parse(rawdata);
const exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Categories");
categories.forEach(function (category) {
exampleEmbed.addField(category.name, category.desc, false);
});
exampleEmbed.addField(
"\u200b",
"Choose the category with **category categoryName**, e.g. **category General*"
);
msg.reply(exampleEmbed);
}
function doSearch(searchWord, args) {
const exampleEmbed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Questions found for ***" + searchWord + "***:");
const Match = class {
constructor(title, value) {
this.title = title;
this.value = value;
}
matchedCount = 0;
title;
value;
};
const fullMatches = [];
const partialMatches = [];
qaMaps.forEach((value, key) => {
let res = value.description;
if (res.includes(searchWord)) {
res = replaceString(res, searchWord, "**" + searchWord + "**");
fullMatches.push(
new Match(file.substring(0, file.lastIndexOf(".")), res)
);
} else {