forked from 0xmoei/sonic-odyssey-bot
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
132 lines (114 loc) · 3.44 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
const fs = require('fs');
const readlineSync = require('readline-sync');
const colors = require('colors');
const {
sendSol,
generateRandomAddresses,
getKeypairFromSeed,
getKeypairFromPrivateKey,
PublicKey,
connection,
LAMPORTS_PER_SOL,
delay,
} = require('./src/solanaUtils');
const { displayHeader } = require('./src/displayUtils');
(async () => {
displayHeader();
const method = '1';
let seedPhrasesOrKeys;
if (method === '1') {
seedPhrasesOrKeys = JSON.parse(
fs.readFileSync('privateKeys.json', 'utf-8')
);
if (!Array.isArray(seedPhrasesOrKeys) || seedPhrasesOrKeys.length === 0) {
throw new Error(
colors.red('privateKeys.json is not set correctly or is empty')
);
}
}
const defaultAddressCount = 100;
const addressCountInput = 100;
const addressCount = addressCountInput
? parseInt(addressCountInput, 10)
: defaultAddressCount;
if (isNaN(addressCount) || addressCount <= 0) {
throw new Error(colors.red('Invalid number of addresses specified'));
}
const randomAddresses = generateRandomAddresses(addressCount);
let rentExemptionAmount;
try {
rentExemptionAmount =
(await connection.getMinimumBalanceForRentExemption(0)) /
LAMPORTS_PER_SOL;
console.log(
colors.yellow(
`Minimum balance required for rent exemption: ${rentExemptionAmount} SOL`
)
);
} catch (error) {
console.error(
colors.red(
'Failed to fetch minimum balance for rent exemption. Using default value.'
)
);
rentExemptionAmount = 0.001;
}
function amountToSend_rand(){
let amountToSend;
const amountInput = (Math.random() * (0.0030 - 0.00100) + 0.00100).toFixed(4);
console.log(`random amount to send:${amountInput}`);
amountToSend = amountInput ? parseFloat(amountInput) : 0.001;
if (isNaN(amountToSend) || amountToSend < rentExemptionAmount) {
console.log(
colors.red(
`Invalid amount specified. The amount must be at least ${rentExemptionAmount} SOL to avoid rent issues.`
)
);
console.log(
colors.yellow(
`Suggested amount to send: ${Math.max(
0.001,
rentExemptionAmount
)} SOL`
)
);
}
return amountToSend;
}
function delay_rand(){
const defaultDelay = 1000;
const delayInput = Math.floor(Math.random() * (20000 - 1000 + 1) + 1000);
const currentTime = new Date();
console.log(`Date: ${currentTime}`);
console.log(`random delay time in milliseconds: ${delayInput}`);
return delayBetweenTx = delayInput ? parseInt(delayInput, 10) : defaultDelay;
}
for (const [index, seedOrKey] of seedPhrasesOrKeys.entries()) {
let fromKeypair;
if (method === '0') {
fromKeypair = await getKeypairFromSeed(seedOrKey);
} else {
fromKeypair = getKeypairFromPrivateKey(seedOrKey);
}
console.log(
colors.yellow(
`Sending SOL from account ${
index + 1
}: ${fromKeypair.publicKey.toString()}`
)
);
for (const address of randomAddresses) {
const toPublicKey = new PublicKey(address);
const amnt = amountToSend_rand();
try {
await sendSol(fromKeypair, toPublicKey, amnt);
console.log(
colors.green(`Successfully sent ${amnt} SOL to ${address}`)
);
} catch (error) {
console.error(colors.red(`Failed to send SOL to ${address}:`), error);
}
await delay(delay_rand());
}
}
})();