-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
71 lines (52 loc) · 2.77 KB
/
main.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
const hre = require("hardhat");
let {web3} = require("hardhat");
const BigNumber = require('bignumber.js')
const {KeyEncryption} = require('./keyEncryption');
const env = require('dotenv').config();
const { Strategy } = require('./strategy/strategy');
const { RunningMode, CAKE_WHALE_ACCOUNT, CAKE_ADDRESS} = require('./config');
const yargs = require('yargs/yargs');
const {CAKE_ABI} = require("./abis");
const { hideBin } = require('yargs/helpers');
const argv = yargs(hideBin(process.argv)).argv;
const {Logger} = require('./logger')
const logger = new Logger('main')
async function main() {
const runningMode = (argv.prod==="true"? RunningMode.PRODUCTION: RunningMode.DEV);
let account
const confFileInfo = {
name: "",
encryptionMethod: "",
};
if (runningMode === RunningMode.PRODUCTION) {
const Web3 = require("web3");
web3 = new Web3(process.env.ENDPOINT_HTTPS);
confFileInfo.name = `${__dirname}/${process.env.CONFIG_ID_FILE_NAME}`
confFileInfo.encryptionMethod = process.env.CONFIG_ID_ENCRYPTION_METHOD
account = web3.eth.accounts.privateKeyToAccount(await new KeyEncryption(confFileInfo).loadKey());
} else if (runningMode === RunningMode.DEV) {
confFileInfo.name = `${__dirname}/${process.env.DEV_CONFIG_ID_FILE_NAME}`
confFileInfo.encryptionMethod = process.env.DEV_CONFIG_ID_ENCRYPTION_METHOD
// account = web3.eth.accounts.create();
account = web3.eth.accounts.privateKeyToAccount(await new KeyEncryption(confFileInfo).loadKey());
await hre.network.provider.request({method: "hardhat_impersonateAccount",params: [CAKE_WHALE_ACCOUNT]});
await hre.network.provider.request({method: "hardhat_impersonateAccount",params: [account.address]});
await hre.network.provider.request({method: "hardhat_setBalance", params: [account.address, "0x100000000000000000000"]});
const cakeContract = new web3.eth.Contract(CAKE_ABI, CAKE_ADDRESS);
let amount = new BigNumber(1e18) //await cakeContract.methods.balanceOf(CAKE_WHALE_ACCOUNT).call()
await cakeContract.methods.transfer(account.address, amount.toString()).send({ from: CAKE_WHALE_ACCOUNT});
console.log('Bot cake balance (DEV mode): ', await cakeContract.methods.balanceOf(account.address).call())
}
web3.eth.defaultAccount = account.address;
logger.debug(`[PID pid ${process.pid}] Starting Bot: address=${account.address}, mode=${runningMode}, mute-discord=${process.env.MUTE_DISCORD}`);
const strategy = new Strategy(env, runningMode, account, web3);
await strategy.start();
}
main()
.then(() => {
logger.debug(`Bot initialized and running, mute discord notification = ${process.env.MUTE_DISCORD}`);
})
.catch((error) => {
logger.error(error);
process.exit(1);
});