forked from Soteria-Smart-Contracts/HackBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
970 lines (917 loc) · 19.7 KB
/
script.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
let ABI = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "AllTeams",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "HackBoardAdmin",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "description",
"type": "string"
},
{
"internalType": "string",
"name": "discord",
"type": "string"
},
{
"internalType": "string",
"name": "bountyTargets",
"type": "string"
},
{
"internalType": "bool",
"name": "interestedInPredictionMarket",
"type": "bool"
},
{
"internalType": "bool",
"name": "pledgedToDistributePrize",
"type": "bool"
},
{
"internalType": "bool",
"name": "_willContinue",
"type": "bool"
},
{
"internalType": "string",
"name": "tokenSymbol",
"type": "string"
}
],
"name": "RegisterTeam",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "team",
"type": "address"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "description",
"type": "string"
},
{
"internalType": "string",
"name": "discord",
"type": "string"
},
{
"internalType": "string",
"name": "bountyTargets",
"type": "string"
},
{
"internalType": "bool",
"name": "interestedInPredictionMarket",
"type": "bool"
},
{
"internalType": "bool",
"name": "_willContinue",
"type": "bool"
}
],
"name": "importOldTeam",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_address",
"type": "address"
}
],
"name": "teamCreated",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "teamList",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "teamListLength",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "teams",
"outputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "description",
"type": "string"
},
{
"internalType": "string",
"name": "discord",
"type": "string"
},
{
"internalType": "string",
"name": "bountyTargets",
"type": "string"
},
{
"internalType": "address",
"name": "teamToken",
"type": "address"
},
{
"internalType": "bool",
"name": "interest",
"type": "bool"
},
{
"internalType": "bool",
"name": "pledge",
"type": "bool"
},
{
"internalType": "bool",
"name": "willContinue",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "tokenList",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "_willContinue",
"type": "bool"
}
],
"name": "updateContinue",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_description",
"type": "string"
}
],
"name": "updateDescription",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_discord",
"type": "string"
}
],
"name": "updateDiscord",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "_interest",
"type": "bool"
}
],
"name": "updateInterest",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_description",
"type": "string"
}
],
"name": "updateMainBountyTarget",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
}
],
"name": "updateName",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "_pledge",
"type": "bool"
}
],
"name": "updatePledge",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
let erc20ABI = [
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "string",
"name": "_symbol",
"type": "string"
},
{
"internalType": "address",
"name": "_teamAddress",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "burner",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "buramount",
"type": "uint256"
}
],
"name": "BurnEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "newminter",
"type": "address"
}
],
"name": "ManageMinterEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_BurnAmount",
"type": "uint256"
}
],
"name": "Burn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "delegate",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "Address",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "balances",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "mint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "teamAddress",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_from",
"type": "address"
},
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
const pairAbi = [
{
"constant": true,
"inputs": [],
"name": "getReserves",
"outputs": [
{
"internalType": "uint112",
"name": "_reserve0",
"type": "uint112"
},
{
"internalType": "uint112",
"name": "_reserve1",
"type": "uint112"
},
{
"internalType": "uint32",
"name": "_blockTimestampLast",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
const routerAbi = [
{
"constant": true,
"inputs": [],
"name": "WETH",
"outputs": [{"name": "", "type": "address"}],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
const factoryAbi = [
{
"constant": true,
"inputs": [
{"name": "", "type": "address"},
{"name": "", "type": "address"}
],
"name": "getPair",
"outputs": [{"name": "", "type": "address"}],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
let contractAddress = "0xC1FDf4678C684b2e8344057Eb9b37B7113b5d28b"
let provider;
let signer
let contract
async function Login() {
console.log("button clicked");
if (typeof window.ethereum !== 'undefined') {
console.log("MetaMask is installed");
try {
// Get the network ID
const networkId = await window.ethereum.request({ method: 'net_version' });
if (networkId === '100') {
provider = new ethers.BrowserProvider(window.ethereum);
console.log("Connected to Gnosis Chain");
document.getElementById('metamaskButton').innerText = "Connected";
document.getElementById('metamaskButton').disabled = true;
document.getElementById('temprow').style.display = "none";
signer = await provider.getSigner();
contract = new ethers.Contract(contractAddress, ABI, signer);
await populateTableWithTeamInfo();
} else {
alert("Please switch to Gnosis Chain (Network ID 100) in MetaMask.");
}
} catch (error) {
console.error("User denied account access or an error occurred.");
}
} else {
alert("MetaMask is not installed");
}
}
//Create a function that calls the contract and gets the team info for each team then displays it in the "Table" element as a tbody row
async function GetTeamInfo(teamID) {
let teamAddress = await contract.teamList(teamID)
let teamInfo = await contract.teams(teamAddress);
return JSON.parse(JSON.stringify(teamInfo))
}
async function GetAllTeamInfoToConsole(){
let TeamInfos = [];
let length = await contract.teamListLength()
console.log("start")
for (let i = 0; i < length; i++) {
console.log(i)
TeamInfos.push(await GetTeamInfo(i));
}
console.log(TeamInfos)
return(TeamInfos)
}
async function insertDataIntoTable(data) {
// Add console logs to debug the data
const teamName = data[0];
let tokenAddress = data[4]
let token = new ethers.Contract(tokenAddress, erc20ABI, signer);
console.log(tokenAddress)
let symbol = await token.symbol()
console.log("price")
let pairToken = await getUniswapPairAddress(tokenAddress)
console.log(pairToken)
let price;
let marketcap
let circulatingSupply
circulatingSupply = await token.totalSupply()
console.log(circulatingSupply)
circulatingSupply = ethers.formatUnits(circulatingSupply,18)
console.log(circulatingSupply)
try {
price = await getTokenPrice(pairToken);
marketcap = price*10000000
price = "$" + price
marketcap = "$" + marketcap
}
catch (error) {
price = "no liquidity";
marketcap = "N/A";
}
console.log("price done")
console.log(data)
const description = data[2];
const contactLink = data[3];
const interestInPredictionMarket = data[6] ? "Yes" : "No";
const mainSponsorPrizeTarget = data[4];
console.log(teamName, description, contactLink, interestInPredictionMarket, mainSponsorPrizeTarget);
const tbody = document.getElementById('Registry');
const tr = document.createElement('tbody');
tr.innerHTML = `<tr>
<td></td>
<td>${teamName}</td>
<td>${symbol}</td>
<td>${price}</td>
<td>${marketcap}</td>
<td>${circulatingSupply}</td>
<td><button onclick="mintToken('${tokenAddress}')">Mint</button></td> <!-- Button 1 with onclick event -->
<td><button onclick="addToken('${tokenAddress}')">Add</button></td> <!-- Button 1 with onclick event -->
<td> <button onclick="tradeToken('${tokenAddress}')">Trade</button> <!-- Button 1 with onclick event -->
</tr>
`;
tbody.appendChild(tr);
}
function tradeToken(tokenAddress) {
const baseUrl = "https://honeyswap.1hive.eth.limo//#/swap?inputCurrency=ETH&outputCurrency=";
const finalUrl = baseUrl + tokenAddress;
window.open(finalUrl, '_blank'); // Open URL in a new tab
}0x8b74FFB5bEd9fE8Ea952917F2097EB8Aa7700E36
function addToken(tokenAddress) {
const baseUrl = "https://honeyswap.1hive.eth.limo//#/add/XDAI/";
const finalUrl = baseUrl + tokenAddress;
window.open(finalUrl, '_blank'); // Open URL in a new tab
}
async function mintToken(tokenAddress){
let token = new ethers.Contract(tokenAddress, erc20ABI, signer);
await token.mint()
}
async function addGnosisChainToMetaMask() {
const chainId = 100;
const rpcUrl = 'https://rpc.ankr.com/gnosis';
const currencySymbol = 'XDAI';
const explorerUrl = 'https://gnosisscan.io/';
try {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: `0x${chainId.toString(16)}`,
chainName: 'Gnosis Chain',
nativeCurrency: {
name: currencySymbol,
symbol: currencySymbol,
decimals: 18,
},
rpcUrls: [rpcUrl],
blockExplorerUrls: [explorerUrl],
},
],
});
console.log('Gnosis Chain added to MetaMask!');
} catch (error) {
console.error('Error adding Gnosis Chain to MetaMask:', error);
}
}
async function populateTableWithTeamInfo() {
const teamData = await GetAllTeamInfoToConsole();
console.log(teamData);
for (let i = 0; i < teamData.length; i++){
console.log("populate " + i)
console.log(teamData[i])
await insertDataIntoTable(teamData[i]);
}
}
async function getTokenPrice(pairAddress) {
const pairContract = new ethers.Contract(pairAddress, pairAbi, provider);
console.log(pairContract)
// Fetch reserves
const [reserve0, reserve1] = await pairContract.getReserves();
console.log(reserve0,reserve1)
let x = reserve1*1000000000000000000n
let y = x/reserve0
let xdaiprice = ethers.formatEther(y)
// Calculate the price (assuming token0 is ETH and token1 is the desired token)
// Price = reserve0 (ETH) / reserve1 (TOKEN)
return xdaiprice
}
async function getUniswapPairAddress(tokenAddress) {
const provider = new ethers.JsonRpcProvider('https://rpc.gnosis.gateway.fm'); // Replace with your Infura endpoint or any Ethereum node endpoint
// Addresses for Uniswap V2 on Mainnet
const FACTORY_ADDRESS = '0xA818b4F111Ccac7AA31D0BCc0806d64F2E0737D7';
const ROUTER_ADDRESS = '0x1C232F01118CB8B424793ae03F870aa7D0ac7f77';
const routerContract = new ethers.Contract(ROUTER_ADDRESS, routerAbi, provider);
const factoryContract = new ethers.Contract(FACTORY_ADDRESS, factoryAbi, provider);
const WETH = await routerContract.WETH();
const pairAddress = await factoryContract.getPair(tokenAddress, WETH);
return pairAddress;
}
document.addEventListener("DOMContentLoaded", function() {
// Define the start time and duration (in this case, a 48-hour hackathon)
const startTime = new Date('2023-09-22T21:00:00'); // Adjust the date and time as needed
const durationInMilliseconds = 36 * 60 * 60 * 1000;
const endTime = new Date(startTime.getTime() + durationInMilliseconds);
function updateCountdown() {
const now = new Date();
let timeDifference = endTime - now;
// Calculate hours, minutes, and seconds
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
timeDifference -= hours * (1000 * 60 * 60);
const mins = Math.floor(timeDifference / (1000 * 60));
timeDifference -= mins * (1000 * 60);
const secs = Math.floor(timeDifference / 1000);
// Update the countdown timer display
document.getElementById('timer').textContent = `${hours}:${mins < 10 ? '0' : ''}${mins}:${secs < 10 ? '0' : ''}${secs}`;
}
// Update the countdown every second
setInterval(updateCountdown, 1000);
});