-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.js
More file actions
515 lines (469 loc) · 16.3 KB
/
index.js
File metadata and controls
515 lines (469 loc) · 16.3 KB
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
const { TransactionBlock } = require('@mysten/sui.js/transactions');
const { decodeSuiPrivateKey } = require('@mysten/sui.js/cryptography');
const dotenv = require('dotenv');
const readline = require('readline');
const { HttpsProxyAgent } = require('https-proxy-agent');
const fs = require('fs').promises;
const SocksProxyAgent = require('socks-proxy-agent').SocksProxyAgent;
const colors = {
reset: '\x1b[0m',
cyan: '\x1b[36m',
green: '\x1b[32m',
yellow: '\x1b[33m',
red: '\x1b[31m',
white: '\x1b[37m',
bold: '\x1b[1m',
};
const logger = {
info: (msg) => console.log(`${colors.green}[✓] ${msg}${colors.reset}`),
wallet: (msg) => console.log(`${colors.yellow}[➤] ${msg}${colors.reset}`),
warn: (msg) => console.log(`${colors.yellow}[⚠] ${msg}${colors.reset}`),
error: (msg) => console.log(`${colors.red}[✗] ${msg}${colors.reset}`),
success: (msg) => console.log(`${colors.green}[✅] ${msg}${colors.reset}`),
loading: (msg) => console.log(`\n${colors.cyan}[⏳] ${msg}${colors.reset}`),
step: (msg) => console.log(`${colors.white}[➤] ${msg}${colors.reset}`),
banner: () => {
console.log(`${colors.cyan}${colors.bold}`);
console.log(`--------------------------------------------------`);
console.log(` Merak Testnet Auto Bot - Airdrop Insiders `);
console.log(`--------------------------------------------------${colors.reset}\n`);
},
};
dotenv.config();
const CONFIG = {
WRAP: {
enabled: true,
amount: 100_000_000,
},
SWAP_wSUI_wDUBHE: {
enabled: true,
amount: 100_000,
repeat: 1,
},
SWAP_wDUBHE_wSUI: {
enabled: true,
amount: 100_000,
repeat: 1,
},
SWAP_wSUI_wSTARS: {
enabled: true,
amount: 100_000,
repeat: 1,
},
SWAP_wSTARS_wSUI: {
enabled: true,
amount: 100_000,
repeat: 1,
},
ADD_LIQUIDITY_wSUI_wDUBHE: {
enabled: true,
asset0: 0,
asset1: 1,
amount0: 1_000_000,
amount1: 5765,
min0: 1,
min1: 1,
label: 'Add Liquidity wSUI-wDUBHE',
},
ADD_LIQUIDITY_wSUI_wSTARS: {
enabled: true,
asset0: 0,
asset1: 3,
amount0: 1_000_000,
amount1: 19149,
min0: 1,
min1: 1,
label: 'Add Liquidity wSUI-wSTARS',
},
ADD_LIQUIDITY_wDUBHE_wSTARS: {
enabled: true,
asset0: 1,
asset1: 3,
amount0: 2000,
amount1: 13873,
min0: 1,
min1: 1,
label: 'Add Liquidity wDUBHE-wSTARS',
},
DELAY_BETWEEN_TX_MS: 5000,
};
const CONTRACTS = {
WRAP_TARGET: '0xa6477a6bf50e2389383b34a76d59ccfbec766ff2decefe38e1d8436ef8a9b245::dubhe_wrapper_system::wrap',
DEX_TARGET: '0xa6477a6bf50e2389383b34a76d59ccfbec766ff2decefe38e1d8436ef8a9b245::dubhe_dex_system::swap_exact_tokens_for_tokens',
SHARED_OBJECT: '0x8ece4cb6de126eb5c7a375f90c221bdc16c81ad8f6f894af08e0b6c25fb50a45',
PATHS: {
wSUI_wDUBHE: [BigInt(0), BigInt(1)],
wDUBHE_wSUI: [BigInt(1), BigInt(0)],
wSUI_wSTARS: [BigInt(0), BigInt(3)],
wSTARS_wSUI: [BigInt(3), BigInt(0)],
},
};
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
async function loadProxies() {
try {
const data = await fs.readFile('proxies.txt', 'utf8');
const proxies = data.split('\n').map(line => line.trim()).filter(line => line);
if (proxies.length === 0) {
logger.warn('No proxies found in proxies.txt. Running without proxy.');
return [];
}
logger.info(`Loaded ${proxies.length} proxies from proxies.txt`);
return proxies;
} catch (e) {
logger.error(`Failed to read proxies.txt: ${e.message}`);
return [];
}
}
function parseProxy(proxy) {
let protocol = 'http';
let auth = null;
let host = proxy;
if (proxy.includes('://')) {
const [proto, rest] = proxy.split('://');
protocol = proto.toLowerCase();
host = rest;
}
if (host.includes('@')) {
const [credentials, hostPort] = host.split('@');
auth = credentials;
host = hostPort;
}
const [ip, port] = host.split(':');
if (!ip || !port) {
logger.error(`Invalid proxy format: ${proxy}`);
return null;
}
const proxyUrl = `${protocol}://${auth ? auth + '@' : ''}${ip}:${port}`;
let agent;
if (['socks4', 'socks5'].includes(protocol)) {
agent = new SocksProxyAgent(proxyUrl);
} else if (['http', 'https'].includes(protocol)) {
agent = new HttpsProxyAgent(proxyUrl);
} else {
logger.error(`Unsupported proxy protocol: ${protocol}`);
return null;
}
return { agent, url: proxyUrl, protocol };
}
function getRandomProxy(proxies) {
if (!proxies.length) return null;
const randomIndex = Math.floor(Math.random() * proxies.length);
const proxy = parseProxy(proxies[randomIndex]);
if (!proxy) {
logger.warn(`Skipping invalid proxy: ${proxies[randomIndex]}`);
proxies.splice(randomIndex, 1);
return getRandomProxy(proxies);
}
return proxy;
}
function getTransactionCount() {
return new Promise((resolve) => {
rl.question(`${colors.cyan}Enter the number of transactions per wallet for this cycle (1-100): ${colors.reset}`, (answer) => {
const count = parseInt(answer, 10);
if (isNaN(count) || count < 1 || count > 100) {
logger.error('Invalid input. Please enter a number between 1 and 100.');
resolve(getTransactionCount());
} else {
logger.info(`Set ${count} transactions per wallet for this cycle.`);
resolve(count);
}
});
});
}
function readKeys() {
const keys = [];
const envVars = Object.keys(process.env);
const privateKeys = envVars.filter((key) => key.startsWith('PRIVATE_KEY_'));
for (const key of privateKeys) {
const value = process.env[key]?.trim();
if (value) {
try {
const { secretKey } = decodeSuiPrivateKey(value);
keys.push({ type: 'privateKey', value });
} catch (e) {
logger.error(`Invalid private key for ${key}: ${e.message}`);
}
}
}
const mnemonics = envVars.filter((key) => key.startsWith('MNEMONIC_'));
for (const key of mnemonics) {
const value = process.env[key]?.trim();
if (value) {
try {
const keypair = Ed25519Keypair.deriveKeypair(value);
keys.push({ type: 'mnemonic', value, keypair });
} catch (e) {
logger.error(`Invalid mnemonic for ${key}: ${e.message}`);
}
}
}
if (keys.length === 0) {
logger.error('No valid private keys or mnemonics found in .env');
process.exit(1);
}
return keys;
}
function displayCountdown() {
const nextRun = new Date();
nextRun.setDate(nextRun.getDate() + 1);
nextRun.setHours(0, 0, 0, 0);
const updateCountdown = () => {
const now = new Date();
const timeLeft = nextRun - now;
if (timeLeft <= 0) {
logger.info('Starting daily transactions...');
return true;
}
const hours = Math.floor(timeLeft / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
process.stdout.write(`\r${colors.cyan}Next run in: ${hours}h ${minutes}m ${seconds}s${colors.reset}`);
return false;
};
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCountdown()) {
clearInterval(interval);
resolve();
}
}, 1000);
});
}
async function wrapWsuI(client, keypair) {
logger.loading(`Wrapping wSUI for ${keypair.getPublicKey().toSuiAddress()}`);
const txb = new TransactionBlock();
const [splitCoin] = txb.splitCoins(txb.gas, [CONFIG.WRAP.amount]);
txb.moveCall({
target: CONTRACTS.WRAP_TARGET,
arguments: [
txb.object(CONTRACTS.SHARED_OBJECT),
splitCoin,
txb.pure.address(keypair.getPublicKey().toSuiAddress()),
],
typeArguments: ['0x2::sui::SUI'],
});
try {
const result = await client.signAndExecuteTransactionBlock({
signer: keypair,
transactionBlock: txb,
});
logTx('Wrap wSUI', keypair, result?.digest);
logger.success(`Wrapped wSUI for ${keypair.getPublicKey().toSuiAddress()}`);
} catch (e) {
logError('Wrap', keypair, e);
throw e;
}
}
async function swapTokens(client, keypair, { amount, path, label, repeat }) {
for (let i = 0; i < repeat; i++) {
logger.loading(`${label} (Run ${i + 1}/${repeat}) for ${keypair.getPublicKey().toSuiAddress()}`);
const txb = new TransactionBlock();
txb.moveCall({
target: CONTRACTS.DEX_TARGET,
arguments: [
txb.object(CONTRACTS.SHARED_OBJECT),
txb.pure(BigInt(amount), 'u256'),
txb.pure(BigInt(1), 'u256'),
txb.pure(path, 'vector<u256>'),
txb.pure.address(keypair.getPublicKey().toSuiAddress()),
],
typeArguments: [],
});
try {
const result = await client.signAndExecuteTransactionBlock({
signer: keypair,
transactionBlock: txb,
});
logTx(`${label} (Run ${i + 1})`, keypair, result?.digest);
logger.success(`${label} (Run ${i + 1}) completed for ${keypair.getPublicKey().toSuiAddress()}`);
} catch (e) {
logError(label, keypair, e);
}
if (i < repeat - 1 && CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
}
async function addLiquidity(client, keypair, { sharedObject, asset0, asset1, amount0, amount1, min0, min1, recipient, label }) {
logger.loading(`${label} for ${keypair.getPublicKey().toSuiAddress()}`);
const txb = new TransactionBlock();
txb.moveCall({
target: '0xa6477a6bf50e2389383b34a76d59ccfbec766ff2decefe38e1d8436ef8a9b245::dubhe_dex_system::add_liquidity',
arguments: [
txb.object(sharedObject),
txb.pure(BigInt(asset0), 'u256'),
txb.pure(BigInt(asset1), 'u256'),
txb.pure(BigInt(amount0), 'u256'),
txb.pure(BigInt(amount1), 'u256'),
txb.pure(BigInt(min0), 'u256'),
txb.pure(BigInt(min1), 'u256'),
txb.pure.address(recipient),
],
typeArguments: [],
});
try {
const result = await client.signAndExecuteTransactionBlock({
signer: keypair,
transactionBlock: txb,
});
logTx(label, keypair, result?.digest);
logger.success(`${label} completed for ${keypair.getPublicKey().toSuiAddress()}`);
} catch (e) {
logError(label, keypair, e);
}
}
function logTx(label, keypair, digest) {
const address = keypair.getPublicKey().toSuiAddress();
logger.step(`${label} for ${address}`);
if (digest) {
logger.info(`Transaction: https://testnet.suivision.xyz/txblock/${digest}`);
} else {
logger.error('Failed to retrieve transaction digest!');
}
}
function logError(label, keypair, e) {
logger.error(`${label} failed for ${keypair.getPublicKey().toSuiAddress()}: ${e.message}`);
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function replayWithKey(keyData, proxies) {
let keypair;
if (keyData.type === 'privateKey') {
const { secretKey } = decodeSuiPrivateKey(keyData.value);
keypair = Ed25519Keypair.fromSecretKey(secretKey);
} else {
keypair = keyData.keypair;
}
const address = keypair.getPublicKey().toSuiAddress();
logger.wallet(`Processing wallet: ${address}`);
const proxy = getRandomProxy(proxies);
if (proxy) {
logger.info(`Using proxy: ${proxy.url} (${proxy.protocol}) for ${address}`);
} else {
logger.warn(`No proxy used for ${address}`);
}
const clientOptions = {
url: getFullnodeUrl('testnet'),
transport: proxy ? { httpAgent: proxy.agent, httpsAgent: proxy.agent } : undefined,
};
const client = new SuiClient(clientOptions);
if (CONFIG.WRAP.enabled) {
try {
await wrapWsuI(client, keypair);
} catch {
return;
}
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.SWAP_wSUI_wDUBHE.enabled && CONFIG.SWAP_wSUI_wDUBHE.repeat > 0) {
await swapTokens(client, keypair, {
amount: CONFIG.SWAP_wSUI_wDUBHE.amount,
path: CONTRACTS.PATHS.wSUI_wDUBHE,
label: 'Swap wSUI -> wDUBHE',
repeat: CONFIG.SWAP_wSUI_wDUBHE.repeat,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.SWAP_wDUBHE_wSUI.enabled && CONFIG.SWAP_wDUBHE_wSUI.repeat > 0) {
await swapTokens(client, keypair, {
amount: CONFIG.SWAP_wDUBHE_wSUI.amount,
path: CONTRACTS.PATHS.wDUBHE_wSUI,
label: 'Swap wDUBHE -> wSUI',
repeat: CONFIG.SWAP_wDUBHE_wSUI.repeat,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.SWAP_wSUI_wSTARS.enabled && CONFIG.SWAP_wSUI_wSTARS.repeat > 0) {
await swapTokens(client, keypair, {
amount: CONFIG.SWAP_wSUI_wSTARS.amount,
path: CONTRACTS.PATHS.wSUI_wSTARS,
label: 'Swap wSUI -> wSTARS',
repeat: CONFIG.SWAP_wSUI_wSTARS.repeat,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.SWAP_wSTARS_wSUI.enabled && CONFIG.SWAP_wSTARS_wSUI.repeat > 0) {
await swapTokens(client, keypair, {
amount: CONFIG.SWAP_wSTARS_wSUI.amount,
path: CONTRACTS.PATHS.wSTARS_wSUI,
label: 'Swap wSTARS -> wSUI',
repeat: CONFIG.SWAP_wSTARS_wSUI.repeat,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.enabled) {
await addLiquidity(client, keypair, {
sharedObject: CONTRACTS.SHARED_OBJECT,
asset0: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.asset0,
asset1: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.asset1,
amount0: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.amount0,
amount1: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.amount1,
min0: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.min0,
min1: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.min1,
recipient: address,
label: CONFIG.ADD_LIQUIDITY_wSUI_wSTARS.label,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.enabled) {
await addLiquidity(client, keypair, {
sharedObject: CONTRACTS.SHARED_OBJECT,
asset0: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.asset0,
asset1: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.asset1,
amount0: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.amount0,
amount1: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.amount1,
min0: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.min0,
min1: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.min1,
recipient: address,
label: CONFIG.ADD_LIQUIDITY_wSUI_wDUBHE.label,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
if (CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.enabled) {
await addLiquidity(client, keypair, {
sharedObject: CONTRACTS.SHARED_OBJECT,
asset0: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.asset0,
asset1: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.asset1,
amount0: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.amount0,
amount1: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.amount1,
min0: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.min0,
min1: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.min1,
recipient: address,
label: CONFIG.ADD_LIQUIDITY_wDUBHE_wSTARS.label,
});
if (CONFIG.DELAY_BETWEEN_TX_MS) await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
}
async function main() {
logger.banner();
const keys = readKeys();
logger.info(`Loaded ${keys.length} wallet(s)`);
const proxies = await loadProxies();
while (true) {
const txCount = await getTransactionCount();
for (let i = 0; i < txCount; i++) {
logger.info(`Starting transaction cycle ${i + 1}/${txCount}`);
for (const keyData of keys) {
try {
await replayWithKey(keyData, proxies);
} catch (e) {
logger.error(`Error processing key: ${e.message}`);
}
if (CONFIG.DELAY_BETWEEN_TX_MS) {
await sleep(CONFIG.DELAY_BETWEEN_TX_MS);
}
}
}
logger.success(`All ${txCount} transaction cycles completed`);
await displayCountdown();
}
}
main().catch((e) => {
logger.error(`Fatal error: ${e.message}`);
rl.close();
process.exit(1);
});