-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
161 lines (128 loc) · 4.55 KB
/
app.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
const ethers = require('ethers');
const fs = require('fs');
const Telegraf = require('telegraf').Telegraf;
const mnemonic = 'YOUR MNEMONIC PHRASE GOES HERE';
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
const bot = new Telegraf('YOUR API TOKEN GOES HERE');
/*
====================================================
DEFINING DEXs AND NETWORKs INFO - ADD AN OBJECT HERE
====================================================
*/
const netswap = {
address: '0x70f51d68D16e8f9e418441280342BD43AC9Dff9f',
rpcLink: 'https://andromeda.metis.io/?owner=1088',
dex: 'Netswap'
};
const tethys = {
address: '0x2CdFB20205701FF01689461610C9F321D1d00F80',
rpcLink: 'https://andromeda.metis.io/?owner=1088',
dex: 'Tethys'
};
const trisolaris = {
address: '0xc66F594268041dB60507F00703b152492fb176E7',
rpcLink: 'https://mainnet.aurora.dev/Fon6fPMs5rCdJc4mxX4kiSK1vsKdzc3D8k6UF8aruek',
dex: 'Trisolaris'
};
const fuseswap = {
address: '0x1d1f1A7280D67246665Bb196F38553b469294f3a',
rpcLink: 'https://rpc.fuse.io',
dex: 'Fuseswap'
};
const traderjoe = {
address: '0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10',
rpcLink: 'https://api.avax.network/ext/bc/C/rpc',
dex: 'TraderJoe'
};
/*
==============================================
CONTRACT OBJECTS CREATION - ADD AN OBJECT HERE
==============================================
*/
const netswapFactory = buildContract(netswap.address, netswap.rpcLink);
const tethysFactory = buildContract(tethys.address, tethys.rpcLink);
const trisolarisFactory = buildContract(trisolaris.address, trisolaris.rpcLink);
const fuseswapFactory = buildContract(fuseswap.address, fuseswap.rpcLink);
const traderjoeFactory = buildContract(traderjoe.address, traderjoe.rpcLink);
/*
============
STARTING BOT
============
*/
bot.start((context) => {
/*
============================================================================
LISTENING ON EVERY CONTRACT'S PAIR CREATION EVENT - ADD LISTENING EVENT HERE
============================================================================
*/
console.log('Bot started.')
context.reply('Scanning your favourite dexs...')
netswapFactory.on('PairCreated', async (_token0, _token1, _pairAddress) => {
logPairInfo(_token0, _token1, _pairAddress, netswap.rpcLink, netswap.dex, context);
});
tethysFactory.on('PairCreated', async (_token0, _token1, _pairAddress) => {
logPairInfo(_token0, _token1, _pairAddress, tethys.rpcLink, tethys.dex, context);
});
trisolarisFactory.on('PairCreated', async (_token0, _token1, _pairAddress) => {
logPairInfo(_token0, _token1, _pairAddress, trisolaris.rpcLink, trisolaris.dex, context);
});
fuseswapFactory.on('PairCreated', async (_token0, _token1, _pairAddress) => {
logPairInfo(_token0, _token1, _pairAddress, fuseswap.rpcLink, fuseswap.dex, context);
});
traderjoeFactory.on('PairCreated', async (_token0, _token1, _pairAddress) => {
logPairInfo(_token0, _token1, _pairAddress, traderjoe.rpcLink, traderjoe.dex, context);
});
})
bot.launch()
/*
=========================
=========================
==== AUX FUNCTIONS ====
=========================
=========================
*/
function buildContract(_address, _rpcLink) {
const provider = new ethers.providers.JsonRpcProvider(_rpcLink);
const account = wallet.connect(provider);
const factory = new ethers.Contract(
_address,
['event PairCreated(address indexed token0, address indexed token1, address pair, uint)'],
account
);
return factory;
}
async function getTokenSymbol(_address, _rpcLink) {
const provider = new ethers.providers.JsonRpcProvider(_rpcLink);
const account = wallet.connect(provider);
const token = new ethers.Contract(
_address,
["function symbol() view returns (string)"],
account
);
var symbol = await token.symbol();
return '$' + symbol;
}
async function logPairInfo(_token0, _token1, _pairAddress, rpcLink, dex, context) {
let symbol0 = await getTokenSymbol(_token0, rpcLink);
let symbol1 = await getTokenSymbol(_token1, rpcLink);
var msg = `
=============================
New ` + dex + ` pair detected
` + getDate() + `
` + symbol0 + ` : ${_token0}
` + symbol1 + ` : ${_token1}
pairAddress: ${_pairAddress}
=============================`;
fs.appendFile('./logs/' + dex + '_log.txt', msg, function (err) {
if (err) throw err;
console.log(msg);
});
context.reply(msg);
}
function getDate() {
var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
return dateTime;
}