-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbot.ts
73 lines (61 loc) · 1.83 KB
/
bot.ts
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
import { Contract } from 'ethers';
import { bnbAmount, tokenAddress, token } from './config.json';
import {
getFactory,
getRouter,
getTokenConfig,
TokenConfig,
fetchBuy,
} from './util';
const bot = async (
router: Contract,
factory: Contract,
config: TokenConfig
) => {
const wbnbAddressLower = String(config.wbnbAddress).toLocaleLowerCase();
const tokenAddressLower = String(tokenAddress).toLocaleLowerCase();
// This will trigger for ALL pair creation on pancakeswap. We have to filter down for just the pair we want.
// NOTE: This will never fetchBuy if pair is already created!
factory.on('PairCreated', async (token0, token1, pairAddress) => {
let tokenIn, tokenOut;
const token0Lower = String(token0).toLocaleLowerCase();
const token1Lower = String(token1).toLocaleLowerCase();
/* console.log(`
=================
New pair detected
token0: ${token0}
token1: ${token1}
pairAddress: ${pairAddress}
`); */
if (token0Lower === wbnbAddressLower) {
tokenIn = token0Lower;
tokenOut = token1Lower;
}
if (token1Lower === wbnbAddressLower) {
tokenIn = token1Lower;
tokenOut = token0Lower;
}
if (typeof tokenIn === 'undefined' || tokenOut != tokenAddressLower) {
/* console.log(`
This is not the pair you're looking for
=================
`); */
return;
}
console.log(
`EXPECTED PAIR FOUND with address ${pairAddress}. Sniping immediately!`
);
await fetchBuy(router, config, false);
process.exit(0);
});
console.log(
`Sniper loaded with ${bnbAmount} ${token} rounds. Watching for pair creation to fire immediately...`
);
};
const botAsync = async () => {
const config = await getTokenConfig();
const router = getRouter(config);
const factory = getFactory(config);
await bot(router, factory, config);
};
botAsync();