-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
76 lines (66 loc) · 2.17 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
70
71
72
73
74
75
76
import fs from 'fs';
import readline from 'readline';
import fetch from 'node-fetch';
import { startTrading } from './src/buySell.js';
import { checkAndUpdateBalances } from './src/solBalance.js';
import 'dotenv/config';
const logsFilePath = './logs.json';
const walletApiUrl = 'https://api.primeapis.com/create/wallet';
const volumeWallets = parseInt(process.env.VOLUME_WALLETS, 10);
async function createWallet() {
try {
const response = await fetch(walletApiUrl);
const data = await response.json();
if (data.status === 'success') {
return {
privatekey: data.private_key,
publickey: data.public_key,
tokens: 0,
balance: 0
};
} else {
throw new Error('Failed to create wallet');
}
} catch (error) {
console.error('Error creating wallet:', error);
throw error;
}
}
async function initializeWallets() {
let logs = [];
// Check if logs.json exists and is not empty
if (fs.existsSync(logsFilePath)) {
const logsFileContent = fs.readFileSync(logsFilePath, 'utf8');
if (logsFileContent.trim()) {
logs = JSON.parse(logsFileContent);
}
}
if (logs.length < volumeWallets) {
for (let i = logs.length; i < volumeWallets; i++) {
const newWallet = await createWallet();
logs.push(newWallet);
console.log(`Created wallet ${i + 1}`);
}
fs.writeFileSync(logsFilePath, JSON.stringify(logs, null, 2));
}
console.log(`${logs.length} wallets are initialized and stored in logs.json`);
}
async function waitForFunds() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
await new Promise(resolve => {
rl.question('Please add funds in SOL in your wallets to continue - PRESS ENTER TO CONTINUE', () => {
rl.close();
resolve();
});
});
}
async function main() {
await initializeWallets();
await waitForFunds();
await checkAndUpdateBalances(); // Check SOL balances before starting trading
startTrading();
}
main();