-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (56 loc) · 2.44 KB
/
index.js
File metadata and controls
83 lines (56 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const cors = require("cors");
const express = require("express");
const bodyParser = require("body-parser");
const helper = require("./helper");
const consts = require("./constants");
const app = express();
const PORT = 3001;
const corsOpts = {
origin: "*",
methods: ["GET", "POST"],
allowedHeaders: ["Content-Type"],
};
app.use(cors(corsOpts));
app.use(bodyParser.json());
app.get("/webhook", async (req, res) => {
let maindata = await bot();
console.log("Received webhook:", maindata);
res.send({ maindata });
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
async function bot() {
var data = [];
var isOppertunity = "false";
let pairUni = await helper.getPair(consts.usdc_usdt, consts.uniswap_factory);
let pairPk = await helper.getPair(consts.usdt_usdc, consts.pancake_factory);
console.log("pairUni: ", pairUni);
console.log("pairPk: ", pairPk);
if (consts.nullAddress == pairUni && consts.nullAddress == pairPk) {
console.log(
`${consts.usdc_usdt.symbol1} - ${consts.usdc_usdt.symbol2} no pair exists at uniswap\n`,
`${consts.usdt_usdc.symbol1} - ${consts.usdt_usdc.symbol2} no pair exists at pancake\n`
);
} else if (consts.nullAddress == pairUni) {
console.log(`${consts.usdc_usdt.symbol1} - ${consts.usdc_usdt.symbol2} no pair exists at uniswap`);
} else if (consts.nullAddress == pairPk) {
console.log(`${consts.usdt_usdc.symbol1} - ${consts.usdt_usdc.symbol2} no pair exists at pancake\n`);
} else {
const priceImpact1 = await helper.getPriceImpact(consts.usdc_usdt, pairUni, "uniswap");
console.log(priceImpact1);
const priceImpact2 = await helper.getPriceImpact(consts.usdt_usdc, pairPk, "pancake");
console.log(priceImpact2);
let prices_usdc_usdt = await helper.getPrice(1, consts.usdc_usdt, consts.RouterABI, consts.uniswap_address, "uniswap");
console.log("prices_usdc_usdt", prices_usdc_usdt)
let prices_usdt_usdc = await helper.getPrice(prices_usdc_usdt, consts.usdt_usdc, consts.RouterABI, consts.pancake_address, "pancake");
console.log("prices_usdt_usdc", prices_usdt_usdc)
let calculate = prices_usdc_usdt - prices_usdt_usdc;
if(calculate > 0) {
console.log(`Oppertunity at pair ${consts.usdc_usdt.symbol1 - consts.usdc_usdt.symbol2} at uniswap and pancakeswap`)
isOppertunity = "true"
}
data.push(pairUni, pairPk, isOppertunity, prices_usdc_usdt, prices_usdt_usdc)
}
return data;
}