-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
794 lines (574 loc) · 28.8 KB
/
content.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
var waitTime = 2000;
var tokenData2 = {};
// checkURL(document.URL);
if (document.URL.includes("uniswap")) {
console.log("uni loaded");
// This code will be executed after 2 seconds
var uniSwapBtn = document.getElementById('swap-button');
if (uniSwapBtn != undefined) {
console.log("1");
setTimeout(function() {
uniSwapBtn.addEventListener("click", async () => await updateUniswapQuote());
}, waitTime);
} else {
console.log("2");
// if swap-button is not on page yet we listen to the time when it is added
var targetNode = document.getElementById('swap-page');
var observer = new MutationObserver(function(mutationsList, observer) {
for(var mutation of mutationsList) {
if (mutation.type === 'childList') {
console.log("added child");
for (var i = 0; i < mutation.addedNodes.length; i++) {
var node = mutation.addedNodes[i];
if (node.id === 'swap-button') {
console.log("added btn");
setTimeout(function() {
document.getElementById('swap-button').addEventListener("click", async () => await updateUniswapQuote());
}, waitTime);
// observer.disconnect();
}
}
}
}
});
observer.observe(targetNode, { childList: true, subtree: true });
console.log("uni observer added");
}
} else if (document.URL.includes("1inch")) {
console.log("1 inch page loaded");
var swapButton = document.getElementsByClassName('swap-confirmation-button ng-star-inserted')[0];
if (swapButton != undefined) {
console.log("got btn")
swapButton.addEventListener("click", async () => await update1inchQuote());
};
} else if (document.URL.includes("www.sushi.com/swap")) {
console.log("sushi page loaded");
setTimeout(function() {
var swapButton = document.getElementsByClassName('cursor-pointer whitespace-nowrap inline-flex gap-2 items-center justify-center font-medium transition-colors !ring-0 disabled:opacity-50 disabled:pointer-events-none ring-offset-background bg-blue hover:bg-blue-600 focus:bg-blue-700 active:bg-blue-600 text-white min-h-[52px] h-[52px] px-4 rounded-xl flex-1 w-full')[0];
console.log(swapButton);
if (swapButton != undefined) {
swapButton.addEventListener("click", async () => await updateSushiQuote());
}
}, waitTime);
} else if (document.URL.includes("curve.fi/#")){
console.log("curve loaded");
setTimeout(function() {
var targetNode = document.getElementsByClassName('Stepper__StepsContainer-sc-1uaxpr7-2 cpYDyr')[0];
var observer = new MutationObserver( async function(mutationsList, observer) {
for(var mutation of mutationsList){
console.log(mutation);
if(mutation.removedNodes.length === 1){
console.log("removed");
var button = document.getElementsByClassName('Button__StyledButton-sc-15l7t19-0 bWwxNz StepAction__StyledButton-sc-1uouzsr-2 jLwXhJ custom-font step-box')[0];
button.addEventListener('mouseover', async () => await updateCurveQuote());
}
}
});
observer.observe(targetNode, { attributes: true, attributeFilter: ['class'], childList: true, subtree: true });
}, waitTime);
} else if (document.URL.includes("pancakeswap")){
console.log("pancake loaded");
setTimeout(function() {
var button = document.getElementsByClassName('pancake-button--disabled')[0];
button.addEventListener('click', async () => await updatePancakeQuote());
console.log("added");
}, waitTime);
} else if (document.URL.includes("balancer")) {
console.log("balancer loaded");
setTimeout(function() {
var targetNode = document.getElementsByClassName('content p-4')[1];
var observer = new MutationObserver( async function(mutationsList, observer) {
for(var mutation of mutationsList){
console.log(mutation);
if(mutation.type === "attributes" && mutation.target.innerText == "Preview"){
var button = document.getElementsByClassName('bal-btn px-4 h-12 text-base')[0];
button.addEventListener('click', async () => await updateBalancerQuote());
}
}
});
observer.observe(targetNode, { attributes: true, attributeFilter: ['class'], childList: true, subtree: true });
}, waitTime);
} else if (document.URL.includes("matcha")) {
console.log("matcha loaded");
setTimeout(function() {
document.getElementsByClassName('mxvt6o17 mxvt6o1 _1ye189v2zd _1ye189v3dm _1ye189v3d4 _1rlm7v0y _1rlm7v00 _1d0g9qk4 _1rlm7v0j mxvt6ob _1rlm7v0z _1rlm7v0l _1ye189v6wm _1ye189v76g _1ye189v7b7 _1ye189v6hv')[0]
.addEventListener('click', async () => await updateMatchaQuote());
}, waitTime);
} else if (document.URL.includes("paraswap")) {
console.log("paraswap loaded");
setTimeout(function() {
document.getElementsByClassName('MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12')[0]
.addEventListener('click', async () => await updateParaswapQuote());
}, waitTime);
} else if (document.URL.includes("cow")) {
console.log("cow loaded");
setTimeout(function() {
document.getElementById('swap-button')
.addEventListener('click', async () => await updateCowQuote());
}, waitTime);
} else if (document.URL.includes("jumper")) {
console.log("jumper loaded");
setTimeout(function() {
document.getElementsByClassName('MuiButtonBase-root MuiButton-root MuiLoadingButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-disableElevation MuiButton-fullWidth MuiButton-root MuiLoadingButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-disableElevation MuiButton-fullWidth css-kbmgdj')[0]
.addEventListener('click', async () => await updateJumperQuote());
}, waitTime);
} else if (document.URL.includes("rocketpool")) {
console.log("rocketpool loaded");
setTimeout(function() {
let walletAdd = document.getElementsByClassName('hidden sm:inline-flex items-center px-2.5 py-0.5 rounded-full text-sm font-medium bg-slate-100/30 text-slate-100 mr-3 cursor-pointer')[0];
if (walletAdd == undefined){
var targetNode = document.getElementsByClassName('flex justify-end items-center flex-row')[0];
var observer = new MutationObserver( async function(mutationsList, observer) {
for(var mutation of mutationsList){
console.log(mutation);
if(mutation.type === "childList"){
document.getElementsByClassName('w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-semibold rounded-md text-white action-button md:py-5 md:text-xl md:px-10')[0]
.addEventListener('mousedown', async () => await updateRocketPoolQuote());
}
}
});
observer.observe(targetNode, { attributes: true, attributeFilter: ['class'], childList: true, subtree: true });
} else {
document.getElementsByClassName('w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-semibold rounded-md text-white action-button md:py-5 md:text-xl md:px-10')[0]
.addEventListener('mousedown', async () => await updateRocketPoolQuote());
}
}, waitTime);
} else if (document.URL.includes("lido")) {
console.log("lido loaded");
setTimeout(function() {
let walletBtn = document.getElementsByClassName('sc-bjUoiL fYhPbI')[0];
if (walletBtn != undefined){
var targetNode = document.getElementsByClassName('sc-51fa3f9c-1 gXuGfb')[0];
var observer = new MutationObserver( async function(mutationsList, observer) {
for(var mutation of mutationsList){
console.log(mutation);
if(mutation.type === "childList"){
console.log("loggedin");
document.getElementsByClassName('sc-bjUoiL gLzAs')[0].addEventListener('mousedown', async () => await updateLidoQuote());
}
}
});
observer.observe(targetNode, { attributes: true, attributeFilter: ['class'], childList: true, subtree: true });
} else {
document.getElementsByClassName('sc-bjUoiL gLzAs')[0].addEventListener('mousedown', async () => await updateLidoQuote());
}
}, waitTime);
} else if (document.URL.includes("defillama")) {
console.log("defillama loaded");
setTimeout(function() {
let bestQuote = document.getElementsByClassName('sc-51fa3f9c-1 gXuGfb')[0];
if (bestQuote != undefined){
var targetNode = document.getElementsByClassName('sc-bb167634-2 cObIGF')[0];
var observer = new MutationObserver( async function(mutationsList, observer) {
for(var mutation of mutationsList){
console.log(mutation);
if(mutation.type === "childList"){
console.log("loggedin");
document.getElementsByClassName('sc-d413ea6e-0 kxiweL RouteWrapper is-selected')[0].addEventListener('mousedown', async () => await updateLlamaQuote());
}
}
});
observer.observe(targetNode, { attributes: true, attributeFilter: ['class'], childList: true, subtree: true });
} else {
document.getElementsByClassName('sc-bb167634-2 cObIGF')[0].addEventListener('click', async () => await updateLlamaQuote());
}
}, waitTime);
} else if (document.URL.includes("dodoex")) {
console.log("dodo loaded");
setTimeout(function() {
var targetNode = document.getElementsByClassName('MuiBox-root mui-style-nzjmwu')[0];
var observer = new MutationObserver( async function(mutationsList, observer) {
for(var mutation of mutationsList){
if(mutation.type === "childList"){
document.getElementsByClassName('MuiButtonBase-root contained mui-style-1ayh7r2')[0].addEventListener('click', async () => await updateDodoQuote());
}
}
});
observer.observe(targetNode, { attributes: true, attributeFilter: ['class'], childList: true, subtree: true });
}, waitTime);
} else if (document.URL.includes("mav.xyz")) {
console.log("mav loaded");
setTimeout(function() {
var button = document.getElementsByClassName('MuiButton-root MuiButton-contained MuiButton-containedSecondary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButtonBase-root')[0];
button.addEventListener('click', async () => await updateMavQuote());
}, waitTime);
}
////////////////////////////////////
// quote updating functions ////////
////////////////////////////////////
async function updateUniswapQuote(){
var quote = [
sanitizeNum(document.querySelectorAll("#swap-currency-input .token-amount-input")[0].value), //input amt
document.querySelectorAll("#swap-currency-input .token-symbol-container")[0].innerHTML, //input symbol
sanitizeNum(document.querySelectorAll("#swap-currency-output .token-amount-input")[0].value), //output amt
document.querySelectorAll("#swap-currency-output .token-symbol-container")[0].innerHTML, // output symbol
"uniswap", //protocol
document.querySelector("img[data-testid = 'chain-selector-logo']").alt //chainName
];
console.log(document.querySelectorAll("#swap-currency-output .token-amount-input")[0].value, quote[2]);
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function update1inchQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.querySelectorAll('[data-id = "token-amount"]')[0].innerText), //input amt
document.querySelectorAll('.ng-star-inserted .token-symbol.ng-star-inserted')[0].innerText, //input symbol
sanitizeNum(document.querySelectorAll('[data-id = "token-amount"]')[1].innerText), //output amt
document.querySelectorAll('.ng-star-inserted .token-symbol.ng-star-inserted')[1].innerText, // output symbol
"1inch", //protocol
document.querySelectorAll(".header-button-text.ng-star-inserted")[0].innerText //chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateSushiQuote(){
var quote = [
sanitizeNum(document.getElementById("swap-from-input").value), //input amt
document.getElementById("swap-from-button").innerText, //input symbol
sanitizeNum(document.getElementById("swap-to-input").value), //output amt
document.getElementById("swap-to-button").innerText, // output symbol
"sushiswap", //protocol
document.getElementsByClassName("hidden xl:block")[0].innerText //chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateCurveQuote(){
var quote = [
sanitizeNum(document.getElementById("inpFromAmount").value), //input amt
document.getElementsByClassName("combo-box-tokens__SelectedLabelText-sc-cjs0do-7 guIxtP")[0].innerText, //input symbol
sanitizeNum(document.getElementById("inpTo").value), //output amt
document.getElementsByClassName("combo-box-tokens__SelectedLabelText-sc-cjs0do-7 guIxtP")[1].innerText, // output symbol
"curve", //protocol
document.getElementsByClassName("select-network__Text-sc-1xhmszc-0 bDxSyE network-label")[0].innerText //chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updatePancakeQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.getElementsByClassName("token-amount-input")[0].value), //input amt
document.getElementsByClassName("sc-daa4d312-0 ihXAEA")[1].innerText, //input symbol
sanitizeNum(document.getElementsByClassName("token-amount-input")[1].value), //output amt
document.getElementsByClassName("sc-daa4d312-0 ihXAEA")[2].innerText, // output symbol
"pancake", //protocol
document.getElementsByClassName("sc-3a5c8d1f-1 iGRbQA")[0].innerText //chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateBalancerQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.getElementsByClassName("input h-10")[0].value), //input amt
document.getElementsByClassName("text-base font-medium")[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName("input h-10")[1].value), //output amt
document.getElementsByClassName("text-base font-medium")[1].innerText, // output symbol
"balancer", //protocol
document.URL.slice(26,-5)//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateMatchaQuote(){
console.log("quoting");
var quotePanel = document.getElementsByClassName('_1ye189v6hv _1ye189v2yy _1ye189v2zm _1ye189v3dd _1ye189v4gj')[0];
var quote = [
sanitizeNum(document.getElementsByClassName("_1f2jl0f1 _1ye189v6my _1ye189v59a _1rlm7v0r _1rlm7v00 _1d0g9qk4 _1rlm7v05 _1f2jl0f3 _1ye189v4vg _1ye189v4zs _1ye189v6pd")[0].value), //input amt
quotePanel.getElementsByClassName('_1ye189v5lv')[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName("_1f2jl0f1 _1ye189v6my _1ye189v59a _1rlm7v0r _1rlm7v00 _1d0g9qk4 _1rlm7v05 _1f2jl0f3 _1ye189v4vg _1ye189v4zs _1ye189v6pd")[1].value), //output amt
quotePanel.getElementsByClassName('_1ye189v5lv')[1].innerText, // output symbol
"matcha", //protocol
document.getElementsByClassName('_1ye189v5lv')[0].innerText//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateParaswapQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.getElementsByClassName('MuiInputBase-input')[0].value), //input amt
document.getElementsByClassName('jss99')[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName('MuiInputBase-input')[1].value), //output amt
document.getElementsByClassName('jss99')[1].innerText, // output symbol
"paraswap", //protocol
document.getElementsByClassName('jss16 jss17')[0].getElementsByClassName('jss23')[0].querySelector('img').alt//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateCowQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.getElementsByClassName('sc-1pwzfxs-0 ggsRKG sc-1e1t2tl-3 KRnqG token-amount-input')[0].value), //input amt
document.getElementsByClassName('sc-gd5mbo-2 kbAhOy token-symbol-container')[0].querySelectorAll('span')[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName('sc-1pwzfxs-0 ggsRKG sc-1e1t2tl-3 KRnqG token-amount-input')[1].value), //output amt
document.getElementsByClassName('sc-gd5mbo-2 kbAhOy token-symbol-container')[1].querySelectorAll('span')[0].innerText, // output symbol
"cowswap", //protocol
document.getElementsByClassName('sc-jpbl2b-9 sc-jpbl2b-10 jPZhFf kqMNGQ')[0].innerText//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateJumperQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.getElementsByClassName('MuiInputBase-input MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedStart MuiInputBase-inputAdornedEnd css-1yrz7eg')[0].value), //input amt
document.getElementsByClassName('MuiTypography-root MuiTypography-body2 MuiCardHeader-title css-1787jda')[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName('MuiBox-root css-14oqdsi')[0].querySelectorAll('text')[0].innerHTML), //output amt
document.getElementsByClassName('MuiTypography-root MuiTypography-body2 MuiCardHeader-title css-1787jda')[1].innerText, // output symbol
"jumper", //protocol
document.getElementsByClassName('MuiTypography-root MuiTypography-body2 MuiCardHeader-subheader css-23d9t0')[0].innerText//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateRocketPoolQuote(){
console.log("quoting");
console.log(document.getElementById('ethAmountToStake'));
var quote = [
sanitizeNum(document.getElementById('ethAmountToStake').value), //input amt
document.getElementsByClassName('text-sm pl-3 h-sm:text-xs')[0].innerText.includes('ETH') ? 'ETH' : 'rETH', //input symbol
sanitizeNum(document.getElementsByClassName('calculation')[0].innerText), //output amt
document.getElementsByClassName('text-sm pl-3 h-sm:text-xs')[0].innerText.includes('ETH') ? 'rETH' : 'ETH',// output symbol
"rocketpool", //protocol
'Ethereum'//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateLidoQuote(){
console.log("quoting");
var quote = [
sanitizeNum(document.getElementsByClassName('sc-cOFTSb coqqWo')[0].value), //input amt
'ETH', //input symbol
sanitizeNum(document.getElementsByClassName('sc-cOFTSb coqqWo')[0].value), //output amt
'stETH',// output symbol
"lido", //protocol
'Ethereum'//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
async function updateLlamaQuote() {
console.log("quoting");
setTimeout( async function() {
var quote = [
sanitizeNum(document.getElementsByClassName('chakra-input css-lv0ed5')[0].value), //input amt
document.getElementsByClassName('chakra-text css-sys4p8')[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName('chakra-input css-lv0ed5')[1].value), //output amt
document.getElementsByClassName('chakra-text css-sys4p8')[1].innerText,// output symbol
"defillama", //protocol
document.getElementsByClassName(' css-3elh5k-singleValue')[0].children[0].children[1].innerText//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}, waitTime);
}
async function updateDodoQuote() {
console.log("quoting");
setTimeout( async function() {
var quote = [
sanitizeNum(document.getElementsByClassName('MuiInputBase-input MuiInput-input mui-style-sg2ko9')[0].value), //input amt
document.getElementsByClassName('MuiButtonBase-root MuiBox-root mui-style-1xb7tfc')[0].children[1].children[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName('MuiInputBase-input MuiInput-input Mui-readOnly MuiInputBase-readOnly mui-style-sg2ko9')[0].value), //output amt
document.getElementsByClassName('MuiButtonBase-root MuiBox-root mui-style-1xb7tfc')[1].children[1].children[0].innerText,// output symbol
"dodo", //protocol
document.getElementsByClassName('showName MuiBox-root mui-style-1isemmb')[1].innerText//chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}, waitTime);
}
async function updateMavQuote() {
console.log("quoting mav");
setTimeout( async function() {
var trynode = document.getElementsByClassName('MuiTypography-root MuiTypography-h4 css-1pfa1h9')[0];
if (trynode != undefined){
var quote = [
sanitizeNum(document.getElementsByClassName('MuiTypography-root MuiTypography-h4 css-1pfa1h9')[0].innerText), //input amt
document.getElementsByClassName('MuiTypography-root MuiTypography-h4 css-1p63m5p')[0].innerText, //input symbol
sanitizeNum(document.getElementsByClassName('MuiTypography-root MuiTypography-h4 css-1pfa1h9')[1].innerText),//output amt
document.getElementsByClassName('MuiTypography-root MuiTypography-h4 css-1p63m5p')[1].innerText, // output symbol
"mav", //protocol
document.getElementsByClassName('MuiTypography-root MuiTypography-h6 css-15u73lz')[0].innerText //chainName
];
console.log(quote);
let chainId = JSON.parse(getChainIdFromName(quote[5]));
if (chainId != 1) {
console.log("toomuch - chain not supported");
return;
}
await formatAndCompareQuote(quote);
}
}, waitTime);
}
//// Helpers
function getChainIdFromName(name){
// return 1; //TODO - delete before deploy
name = name.toLowerCase();
name = name.replace(" ", "");
console.log(name);
switch(name){
case "ethereum":
return 1;
case "eth":
return 1;
case "ethereummainnet":
return 1;
case "polygon":
return 137;
case "arbitrum":
return 42161;
case "optimism":
return 10;
case "celo":
return 42220;
case "bnb chain":
return 56;
default:
return 0;
}
}
function sanitizeNum(num){
console.log(num.replace(/[,\s]/g, ""));
return parseFloat(num.replace(/[,\s]/g, ""));
}
// async function getTokenFromSymbol(symbol) {
// if(Object.keys(tokenData2).length === 0) {
// var response;
// chrome.runtime.sendMessage({msg: "getTokensFrom1inch", symbol: symbol}, async function(response) {
// if (response) {
// console.log("got token");
// console.log(response.tokens);
// tokenData2 = response.tokens;
// console.log(tokenData2);
// // let tokenData2Arr = Object.entries(tokenData2);
// // let tokenInfoArry = tokenData2Arr.filter(([key, val]) => { //returns a tokenInfoArry [add, {tokenDetails}]
// // return val.symbol === symbol;
// // });
// let token = tokenData2.find((tk) => tk.symbol == symbol);
// console.log(token);
// if(token != undefined){
// return {
// "address" : token.address,
// "decimal" : token.decimals,
// "symbol" : symbol
// }
// } else {
// console.log("TooMuch - can't get token from symbole via 1inch api");
// return null;
// }
// } else {
// console.error("No response or an error occurred.");
// if (chrome.runtime.lastError) {
// console.error(chrome.runtime.lastError.message);
// };
// return null;
// }
// });
// }
// }
// async function formatAndCompareQuote(quote) {
// console.log("quoting");
// console.log(quote);
// if(quote[0]>0 && quote[2]>0 && quote[1].length>0 && quote[3].length < 7){
// console.log("ready");
// console.log(quote);
// //format quote
// let fromToken = await getTokenFromSymbol(quote[1]);
// let toToken = await getTokenFromSymbol(quote[3]);
// console.log(fromToken);
// console.log(toToken);
// if (fromToken == null || toToken == null) {
// console.log("toomuch - token not supported");
// return;
// }
// let formattedQuote = {
// fromToken: fromToken,
// toToken: toToken,
// fromAmt: quote[0] * 10**fromToken.decimal,
// toAmt: quote[2] * 10**toToken.decimal,
// fromChainName: quote[5],
// toChainName: quote[5],
// protocol: quote[4]
// };
// await chrome.runtime.sendMessage({formattedQuote: formattedQuote, msg: "bgCompareQuote"});
// console.log(formattedQuote);
// }
// }
async function formatAndCompareQuote(quote) {
await chrome.runtime.sendMessage({quote: quote, msg: "formatAndCompareQuote"});
}