-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
326 lines (255 loc) · 12.8 KB
/
index.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
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
require('dotenv').config();
const ethers = require('ethers');
const configs = require('./config/config');
const contractAbi = require('./config/contract-abi');
const chalk = require('chalk');
const moment = require('moment');
const chalkAnimation = require('chalk-animation');
const inquirer = require('inquirer');
const { Wallet } = require('ethers');
const delay = require('delay');
const NodeCache = require("node-cache");
const myCache = new NodeCache();
function splitNumberPer3digits(n) {
const newN = n.toString().match(/([\d.]{3})([\d.]{3})/);
const numberDigit = parseFloat(`${newN[1]}.${newN[2]}`);
return numberDigit
};
const isBull = (onePreviousEpoch, secondPreviousEpoch) => {
const firstNumber = splitNumberPer3digits(onePreviousEpoch)
const secondNumber = splitNumberPer3digits(secondPreviousEpoch)
if (firstNumber > secondNumber) {
return true
} else {
return false
}
};
const betting = async (method, ppv2Contract, epoch, betAmount) => {
if (method.toLowerCase() == 'up') {
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Betting on Bullish Bet.`))
let error = true;
let errorDetail = '';
do {
if (!errorDetail || errorDetail.includes('cannot estimate gas')) {
try {
await delay(1000);
const tx = await ppv2Contract.betBull(epoch, {
value: ethers.utils.parseUnits(betAmount, 'ether')
});
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Try to bet...`))
await tx.wait();
error = false;
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Success betting on Bullish Bet.`))
} catch (e) {
errorDetail = e.toString().split('[')[0];
error = true;
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.red(e.toString().split('[')[0]))
}
} else {
error = false;
}
} while (error);
error = true;
} else {
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Betting on Bear Bet.`))
let error = true;
let errorDetail = '';
do {
if (!errorDetail || errorDetail.includes('cannot estimate gas')) {
try {
await delay(1000);
const tx = await ppv2Contract.betBear(epoch, {
value: ethers.utils.parseUnits(betAmount, 'ether')
});
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Try to bet...`))
await tx.wait();
error = false;
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Success betting on Bear Bet.`))
} catch (e) {
error = true;
errorDetail = e.toString().split('[')[0];
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.red(e.toString().split('[')[0]))
}
} else {
error = false;
}
} while (error);
error = true;
}
}
(async () => {
const provider = new ethers.providers.JsonRpcProvider(configs.rpc);
let wallet = {};
const questions = [
{
type: 'password',
name: 'password',
mask: '*',
message: "Insert your Mnemonic / Private Key here : ",
validate: function (value) {
if (value.includes('0x') || !/\s/g.test(value)) {
try {
wallet = new ethers.Wallet(value, provider);
return true;
} catch (e) {
return 'Please enter a valid Mnemonic / private key';
}
} else {
try {
wallet = Wallet.fromMnemonic(value);
wallet = new ethers.Wallet(wallet.privateKey, provider);
return true;
} catch (e) {
return 'Please enter a valid Mnemonic / private key';
}
}
},
},
{
type: 'input',
name: 'method',
message: "Input your method ex. (UP UP DOWN DOWN) : ",
default() {
return 'UP UP DOWN DOWN';
},
}
];
inquirer.prompt(questions).then(async (answers) => {
console.log('')
chalkAnimation.glitch('Started Pancake Prediction BOT')
const ppv2address = configs.pancakePredictV2Address;
const firstBetAmount = configs.betAmount;
// init contract pancake predict
const ppv2Contract = new ethers.Contract(ppv2address, contractAbi.pancakePredictV2, wallet);
// Compent Multiply : x${chalk.red(configs.compentMultiply)}
console.log(`
############################# CONFIG #############################
Your wallet address : ${chalk.green(wallet.address)}
Bet Amount : ${chalk.green(firstBetAmount)} BNB
Method : ${chalk.yellow(answers['method'])}
##################################################################
`)
const currentEpoch = await ppv2Contract.currentEpoch();
const methodToArray = answers['method'].split(' ');
//first bet
if (methodToArray[0].toLowerCase() == 'up') {
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Start Epoch : ${currentEpoch.toString()}`));
await betting('up', ppv2Contract, currentEpoch, firstBetAmount);
methodToArray.splice(0, 1);
myCache.set('round', {
round: 1,
dataMethod: methodToArray,
epoch: currentEpoch
})
} else {
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Start Epoch : ${currentEpoch.toString()}`));
await betting('down', ppv2Contract, currentEpoch, firstBetAmount);
methodToArray.splice(0, 1);
myCache.set('round', {
round: 1,
dataMethod: methodToArray,
epoch: currentEpoch
})
}
ppv2Contract.on('StartRound', async (epoch) => {
const haveRound = myCache.get('round');
if (epoch.toString() !== haveRound.epoch.toString()) {
const haveCompent = myCache.get('compent');
if (!haveCompent) {
// const haveRound = myCache.get('round');
// if (haveRound) {
// console.log('')
// console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.magenta('Are you winning on previous round ? wait a moment for closing.'));
// const claimableEpochs = await ppv2Contract.claimable(parseInt(haveRound.epoch.toString()), wallet.address);
// console.log(claimableEpochs, haveRound.epoch.toString())
// if (claimableEpochs) {
// console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green('Off Course Yes!!! I will claim for you, wait.'));
// try {
// const tx = await ppv2Contract.claim(haveRound.epoch);
// const receipt = await tx.wait();
// console.log(receipt)
// console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Epoch ${parseInt(haveRound.epoch.toString())} claimed....Yess`));
// } catch (e) {
// console.log(e)
// console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.yellow(`Failed to claim, try manually :'(`));
// }
// } else {
// myCache.set('compent', {
// position: 1,
// amount: firstBetAmount * parseInt(configs.compentMultiply)
// })
// console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.red('Off Course NOT!!! Hahahaaha'));
// }
// }
console.log('')
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Start Epoch : ${epoch.toString()}`));
let checkRound = myCache.get('round');
if (checkRound.dataMethod.length >= 1) {
await betting(checkRound.dataMethod[0], ppv2Contract, epoch, firstBetAmount);
checkRound.dataMethod.splice(0, 1);
myCache.set('round', {
round: checkRound.round + 1,
dataMethod: checkRound.dataMethod,
epoch: parseInt(epoch.toString())
});
} else {
await betting(methodToArray[0], ppv2Contract, epoch, firstBetAmount);
methodToArray.splice(0, 1);
myCache.set('round', {
round: 1,
dataMethod: methodToArray,
epoch: parseInt(epoch.toString())
});
}
} else {
const haveRound = myCache.get('round');
if (haveRound) {
if (parseInt(haveRound.epoch.toString()) == parseInt(epoch.toString()) - 1) {
console.log('')
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.magenta('Are you winning on previous round ? wait a moment for closing.'));
const claimableEpochs = await ppv2Contract.claimable(parseInt(haveRound.epoch.toString()), wallet.address);
if (claimableEpochs) {
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green('Off Course Yes!!! I will claim for you, wait.'));
try {
const tx = await ppv2Contract.claim(haveRound.epoch);
const receipt = await tx.wait();
console.log(receipt)
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Epoch ${haveRound.epoch.toString()} claimed....Yess`));
} catch (e) {
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.yellow(`Failed to claim, try manually :'(`));
}
myCache.del('compent')
} else {
myCache.set('compent', {
position: 1,
amount: haveCompent.amount * parseInt(configs.compentMultiply)
})
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.red('Off Course NOT!!! Hahahaaha'));
}
}
}
console.log('')
console.log(`[ ${moment().format("HH:mm:ss")} ] `, chalk.green(`Start Epoch : ${epoch.toString()}, compensation time!!`));
let checkRound = myCache.get('round');
if (checkRound.dataMethod.length >= 1) {
await betting(checkRound.dataMethod[0], ppv2Contract, epoch, parseFloat(haveCompent.amount).toFixed(4).toString());
checkRound.dataMethod.splice(0, 1);
myCache.set('round', {
round: checkRound + 1,
dataMethod: checkRound.dataMethod,
epoch
});
} else {
await betting(methodToArray[0], ppv2Contract, epoch, parseFloat(haveCompent.amount).toFixed(4).toString());
methodToArray.splice(0, 1);
myCache.set('round', {
round: 1,
dataMethod: methodToArray,
epoch
});
}
}
}
});
});
})();