forked from robotchangzhang/chainrobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
691 lines (580 loc) · 17.5 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
<link href="./styles.css" rel="stylesheet">
<title>链上自动买卖程序</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
}
body {
padding: 10px 15px;
margin: 0;
}
h1 {
margin: 0 0 10px;
}
button {
display: inline-block;
line-height: 1;
white-space: nowrap;
cursor: pointer;
background: #fff;
border: 1px solid #dcdfe6;
color: #606266;
-webkit-appearance: none;
text-align: center;
box-sizing: border-box;
outline: none;
margin: 0;
font-weight: 500;
padding: 8px 12px;
font-size: 14px;
border-radius: 4px;
}
button:hover {
border-color: #409eff;
color: #409eff;
}
.grid {
width: 600px;
padding: 10px;
border-radius: 8px;
box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
margin-bottom: 12px;
}
input {
font-size: 14px;
-webkit-appearance: none;
background-color: #fff;
background-image: none;
border-radius: 4px;
border: 1px solid #dcdfe6;
box-sizing: border-box;
color: #606266;
display: inline-block;
height: 32px;
line-height: 32px;
outline: none;
padding: 0 12px;
}
input:focus {
outline: none;
border-color: #409eff;
}
input[type=radio] {
display: none;
}
input[type=radio]+label {
padding: 8px 12px;
border-radius: 4px;
border: 1px solid #ddd;
cursor: pointer;
font-size: 14px;
margin-right: 6px;
}
input[type=radio]:checked+label {
background-color: #409eff;
border-color: #409eff;
color: #fff;
}
.title {
font-size: 18px;
font-weight: 600;
}
.row {
margin-bottom: 4px;
display: flex;
align-items: center;
}
.row:hover label {
color: #409eff;
}
.row label {
font-size: 14px;
width: 160px;
flex-shrink: 0;
}
.row input {
flex: 0 0 400px;
}
#main {
display: flex;
height: 100%;
}
#left {
flex-shrink: 0;
}
#log {
flex-grow: 1;
margin: 0 13px 0 20px;
padding: 8px 10px;
border-radius: 8px;
box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
height: 100%;
overflow: auto;
box-sizing: border-box;
}
.log-row {
font-size: 13px;
margin-bottom: 2px;
}
#webtype,
#network {
display: flex;
margin-bottom: 6px;
}
.form-box {
width: 80%;
margin: 5px auto
}
.row .inputa {
width: 100%;
flex-grow: 1;
}
.evmnetwork {
width: 100px;
margin-top: 2px
}
.btn-add {
width: auto;
margin-left: 8px;
}
</style>
</head>
<body>
<div id="main">
<div id="left">
<div>
<h1>
链上自动买卖程序
</h1>
<div class="grid">
<from id="network">
</from>
<form id="webtype">
<input type="radio" name="webnetwork" value="rpc" id="rpc" onclick='changewebnetwork(this.value)' />
<label for="rpc">rpc地址</label>
<input type="radio" name="webnetwork" value="ws" id="ws" onclick='changewebnetwork(this.value)' />
<label for="ws">ws地址</label>
</form>
<div class="row">
<input class="inputa" type="text" name="name" id="weburl" placeholder="服务地址" autofocus
value="https://mainnet.infura.io/v3/e1d0b7dea53643a194cadb6ed123f88e" />
<button type="button" onclick="initweb3()" class="btn btn-add">初始化web3</button>
</div>
</div>
</div>
<div class="grid">
<div class="title">授权检查:</div>
<div class="row">
<label>代币合约地址:</label><input id="tokenaddresscheck" value="0xc778417E063141139Fce010982780140Aa0cD5Ab">
</div>
<div class="row">
<label>授权地址:</label><input id="approveaddress" value="0x10ED43C718714eb63d5aA57B78B54704E256024E">
</div>
<div class="row">
<label>gas:</label><input id="approvegas" value="5">
</div>
<div class="row">
<label>gaslimint:</label><input id="approvegaslimit" value="420000">
</div>
<button onclick="oncheckapprove()">批量检查授权pancake可以使用该代币</button>
<button onclick="ceshi()">查询主币</button>
</div>
<div class="grid">
<div class="title">监控价格:</div>
<div class="row">
<label>LP池子地址:</label><input id="lpaddress" value="0x09fe9db65c44b9610ab7dcd6853f887d2ade7e7f">
</div>
<div class="row">
<label>代币地址:</label><input id="lptokenaddress" value="0x4a2c860cEC6471b9F5F5a336eB4F38bb21683c98">
</div>
<div class="row">
<label>交易对地址(U地址):</label><input id="lptoken1address" value="0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d">
</div>
<button onclick="onstartmonitor()">监控价格</button>
<button onclick="onstopmonitor()">停止监控</button>
</div>
<div class="grid">
<div class="row">
<label>设置买入价:</label><input id="buyprice" value="9.8">
</div>
<div class="row">
<label>设置买入数量(代币):</label><input id="buynumber" value="100">
</div>
<div class="row">
<label>设置买入滑点:</label><input id="buylose" value="0.01">
</div>
<div class="row">
<label>设置卖出价:</label><input id="sellprice" value="12">
</div>
<div class="row">
<label>设置卖出数量(代币):</label><input id="sellnumber" value="100">
</div>
<div class="row">
<label>设置卖出滑点:</label><input id="selllose" value="0.01">
</div>
<div class="row">
<label>设置买卖gas:</label><input id="buygas" value="5">
</div>
<div class="row">
<label>设置买卖gas limit:</label><input id="buygaslimit" value="420000">
</div>
<div class="row">
<label>设置wbnb(weth) 地址:</label><input id="buywbnb" value="0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c">
</div>
<button onclick="onstartbuy()">开始自动买入卖出</button>
<button onclick="onstopbuy()">停止自动买入卖出</button>
</div>
</div>
<div id="log">
</div>
</div>
<!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>
</body>
<script>
// You can also require other files to run in this process
require('./renderer.js')
const electron = require('electron');
const { ipcRenderer } = electron;
function init() {
document.querySelector("#rpc").checked = true;
}
init();
var nownetwork = 'eth';
var chainid = 1;
//初始化web3
function initweb3() {
var webtype = "rpc";
const wschecked = document.querySelector('#ws').checked
if (wschecked) {
webtype = "ws";
}
const weburl = document.querySelector('#weburl').value;
var value = { webtype, weburl, chainid, nownetwork };
//console.log(value);
ipcRenderer.send('info:initweb3', value)
}
//查询智能合约功能
function queryContarct() {
const contractaddress = document.querySelector('#Contractaddress').value;
evmnetwork = getNetworkInfo(nownetwork);
if (evmnetwork[0]) {
var apiurl = evmnetwork[1].apiurl;
var value = { contractaddress, apiurl };
ipcRenderer.send('info:queryabi', value)
}
}
//抢购开始函数
function qianggou() {
const nftaddress = document.querySelector('#nftaddress').value;
const inputdata = document.querySelector('#inputdata').value;
const gas = document.querySelector('#qianggougas').value;
const gaslimit = document.querySelector('#qianggougaslimit').value;
const neth = document.querySelector('#neth').value;
value = { nftaddress, inputdata, gas, gaslimit, neth };
console.log("开始抢购,请稍等,或者去区块链网络查看:");
ipcRenderer.send('info:qianggou', value)
}
function ceshi() {
ipcRenderer.send('info:test', {})
}
function init1() {
var network = document.querySelector('#network');
var i = 0;
for (evmnetwork in evmnetworks) {
//console.log(evmnetwork);
var radio = document.createElement("input");
radio.type = "radio";
radio.name = "evmnetwork";
radio.value = evmnetworks[evmnetwork].network;
radio.id = evmnetworks[evmnetwork].network;
if (i == 0) {
radio.checked = true;
nownetwork = evmnetworks[evmnetwork].network;
chainid = evmnetworks[evmnetwork].chainid;
}
i++;
//radio.innerHTML = '"' + evmnetworks[evmnetwork].network + '"';
radio.onclick = function () { changenetwork(this.value) };
network.appendChild(radio);
var label = document.createElement("label");
label.innerHTML = evmnetworks[evmnetwork].network;
label.setAttribute('for', evmnetworks[evmnetwork].network)
network.appendChild(label);
}
}
function changewebnetwork(webtype) {
//alert(webtype);
changenetwork(nownetwork);
}
function changenetwork(network) {
var result = getNetworkInfo(network);
if (result[0]) {
nownetwork = result[1].network;
chainid = result[1].chainid;
var webtype = "rpc";
const wschecked = document.querySelector('#ws').checked
if (wschecked) {
webtype = "ws";
}
if (webtype == "rpc") {
document.querySelector('#weburl').value = result[1].rpc;
}
else {
document.querySelector('#weburl').value = result[1].ws;
}
}
}
function getNetworkInfo(network) {
for (evmnetwork of evmnetworks) {
//console.log(evmnetwork);
if (network == evmnetwork.network) {
return [true, evmnetwork];
}
}
return [false, "false"];
}
init1();
ipcRenderer.on('info:initweb3', (e, value) => {
//console.log(value)
if (value.result) {
console.log("initweb3成功");
}
else {
console.log("initweb3失败");
}
});
var abi = null;
ipcRenderer.on('info:queryabi', (e, value) => {
console.log(value)
if (value.result[0] == true) {
console.log("智能合约查询成功")
abi = value.result;
}
else {
abi = null;
}
});
function cleanchild(selecthtml) {
while (true) {
try {
selecthtml.removeChild(selecthtml.childNodes[0]);
}
catch (e) {
break;
}
}
}
function readfunction(value) {
//debugger;
var selecthtml = document.querySelector('#fangfa');
if (selecthtml != null) {
cleanchild(selecthtml)
}
else {
return;
}
if (abi == null) {
return;
}
var viewmap = null;
var typename = "view"
if (value == "view") {
viewmap = abi[1];
typename = "view";
}
else if (value == "nonpayable") {
viewmap = abi[2];
typename = "nonpayable";
}
else if (value == "payable") {
viewmap = abi[3];
typename = "payable";
}
viewmap.forEach(element => {
var fname = element.name;
var option = document.createElement("option");
option.value = typename;
option.id = fname;
option.innerHTML = fname;
//option.onclick = function () { changefunction(this.value,this.id) };
selecthtml.appendChild(option);
});
}
function changefunction(selecthtml) {
//debugger;
var option = selecthtml.options[selecthtml.selectedIndex];
console.log(option.value)
changefunctionEX(option.value, option.id);
}
function transpara(input) {
type = input.name;
value = input.value;
id = input.id;
if (type == "bool") {
if (value.toLowerCase() == "ture" || value == "1") {
return true;
}
else if (value.toLowerCase() == "false" || value == "0") {
return false;
}
else {
console("错误:" + id + "输入的参数不匹配");
return "error";
}
}
else if (type == "address") {
if (value.indexOf("0x") == -1) {
console("错误:" + id + "输入的参数不匹配");
return "error";
}
else {
return value;
}
}
else {
return value;
}
}
function exce() {
var paralist = document.querySelector('#paralist').getElementsByTagName("input")
var okvalue = [];
var tijiao = true;
for (i = 0; i < paralist.length; i++) {
var result = transpara(paralist[i])
if (result != "error")
okvalue.push(result)
else
tijiao = false;
}
if (tijiao) {
//给后台提交数组
if (useabi != null) {
const nftaddress = document.querySelector('#nftaddress').value;
const gas = document.querySelector('#qianggougas').value;
const gaslimit = document.querySelector('#qianggougaslimit').value;
const neth = document.querySelector('#neth').value;
debugger;
value = { useabi, okvalue, nftaddress, gas, gaslimit, neth };
ipcRenderer.send('info:abishiyong', value)
}
}
}
var useabi = null;
function changefunctionEX(name, value) {
var viewmap = null;
if (name == "view") {
viewmap = abi[1];
}
else if (name == "nonpayable") {
viewmap = abi[2];
}
else if (name == "payable") {
viewmap = abi[3];
}
if (viewmap != null) {
var valueabi = viewmap.get(value);
if (valueabi != null) {
console.log(valueabi);
var inputs = valueabi.inputs;
useabi = valueabi;
var selecthtml = document.querySelector('#paralist');
if (selecthtml != null) {
cleanchild(selecthtml)
}
else {
return;
}
inputs.forEach(element => {
var aname = document.createElement('a');
aname.innerHTML = element.name + "(" + element.type + ")";
selecthtml.appendChild(aname)
var input = document.createElement('input');
input.name = element.type;
input.id = element.name;
selecthtml.appendChild(input);
selecthtml.appendChild(document.createElement('BR'));
});
}
else {
useabi = null;
}
}
}
ipcRenderer.on('info:msg', (e, value) => {
console.log(value)
});
// 检查代币是否授权,没有授权直接授权
function oncheckapprove() {
const tokenaddresscheck = document.querySelector('#tokenaddresscheck').value;
const approveaddress = document.querySelector('#approveaddress').value;
const approvegas = document.querySelector('#approvegas').value;
const approvegaslimit = document.querySelector('#approvegaslimit').value;
value = { tokenaddresscheck, approveaddress, approvegas, approvegaslimit };
ipcRenderer.send('info:checkapprove', value)
}
//监控价格
function onstartmonitor() {
const lpaddress = document.querySelector('#lpaddress').value;
const lptokenaddress = document.querySelector('#lptokenaddress').value;
const lptoken1address = document.querySelector('#lptoken1address').value;
value = { lpaddress, lptokenaddress, lptoken1address };
ipcRenderer.send('info:listenprice', value)
}
function onstopmonitor() {
ipcRenderer.send('info:stoplistenprice', {})
}
//开始自动买入卖出
function onstartbuy() {
var buyprice = document.querySelector('#buyprice').value;
var buynumber = document.querySelector('#buynumber').value;
var buylose = document.querySelector('#buylose').value;
var sellprice = document.querySelector('#sellprice').value;
var sellnumber = document.querySelector('#sellnumber').value;
var selllose = document.querySelector('#selllose').value;
var buygas = document.querySelector('#buygas').value;
var buygaslimit = document.querySelector('#buygaslimit').value;
var pancakeaddress = document.querySelector('#approveaddress').value;
var buywbnb = document.querySelector('#buywbnb').value;
var value = { buyprice, buynumber, buylose, sellprice, sellnumber, selllose, buygas, buygaslimit, pancakeaddress,buywbnb }
ipcRenderer.send('info:startbuy', value)
}
function onstopbuy() {
ipcRenderer.send('info:stopbuy', {})
}
function getnowtime() {
dt = new Date();
var y = dt.getFullYear();
var mt = dt.getMonth() + 1;
var day = dt.getDate();
var h = dt.getHours(); //获取时
var m = dt.getMinutes(); //获取分
var s = dt.getSeconds(); //获取秒
var nowtimet = '当前时间:' + y + '年' + mt + '月' + day + '-' + h + '时' + m + '分' + s + '秒:';
return nowtimet;
}
(function () {
var old = console.log;
var logger = document.getElementById('log');
console.log = function (message) {
var nowtime = (Date.now());
if (typeof message == 'object') {
logger.innerHTML += '<div class="log-row">' + getnowtime() + (JSON && JSON.stringify ? JSON.stringify(message) : message) + '</div>';
} else {
logger.innerHTML += '<div class="log-row">' + getnowtime() + message + '</div>';
}
}
})();
</script>
</html>