-
Notifications
You must be signed in to change notification settings - Fork 2
/
KPLminer.js
125 lines (105 loc) · 4.01 KB
/
KPLminer.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
const getTaskData = require("./helpers/getTaskData");
const transferKPL = require("./helpers/transferKPL");
const { MongoClient } = require("mongodb");
require("dotenv").config();
const uri = process.env.DB_KEY;
const DB_name = "tweets_middleman";
const collection_name = "kpltokenminer";
async function hasRoundTransferred(round) {
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
try {
await client.connect();
const database = client.db(DB_name);
const transfersCollection = database.collection(collection_name);
// Check if the round exists in the collection
const transfer = await transfersCollection.findOne({ round: round });
return transfer !== null; // If the round exists, it has been transferred
} catch (error) {
console.error("Error checking round transfer:", error);
return false; // Return false if error occurs
} finally {
await client.close(); // Ensure the connection is closed
}
}
async function recordTransfer(round, kplToken, transfers) {
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
try {
await client.connect();
const database = client.db(DB_name);
const transfersCollection = database.collection(collection_name);
// Insert the transfer record
await transfersCollection.insertOne({
round: round,
token: kplToken,
transfers: transfers, // An array of objects with { address, amount }
timestamp: new Date(),
});
console.log(`Recorded transfer for round ${round}`);
} catch (error) {
console.error("Error recording transfer:", error);
} finally {
await client.close(); // Ensure the connection is closed
}
}
async function main() {
try {
const listOfKPLs = [
"us8mD4jGkFWnUuAHB8V5ZcrAosEqi2h1Zcyca68QA1G", // BIRD
"9UcQaSsBTeXowhMBgSbTEeQubGHxXDNJRjz4s7uxibTP", // BB
"FJG2aEPtertCXoedgteCCMmgngSZo1Zd715oNBzR7xpR", // FIRE
// "BmdvRw51zhCKfkBmw6jmLawJafimTMtZ2eVwT3fL2WM6", // RATs
"n3Rep7GRh3jgkGXaULNu8WzfuwCC9Rcrv82mxzJMnnH", // SONO
// "NGFruaQX9xHqWv195RNQL2wtq2LJwTmnkE9XjGAZKHx", // SOMA
"3kh898gitJDSb6b7MsntLqyUAvy3Y6D4PkMyGfinubht", // VIP
// "EErjDSPHmjz9ZipEtVoN54QzCjPvePBADvXcWKT659NW", // SSS
"HK8STMDTos4QFocyEADxwdXBrN13DCB9AcwLXsmvBthh" // SMART
];
let addresses = {};
const taskData = await getTaskData(
"CPscE41WQxF9j8KuwJD7GGv9yjCNZRyWLsGjS3f9V4Kp",
0
);
const randomKPL = listOfKPLs[Math.floor(Math.random() * listOfKPLs.length)];
// Split 500 KPL among all submission addresses
const totalKPL = 1000;
addresses.push(taskData);
let kplPerSubmission = totalKPL / addresses.length;
kplPerSubmission = parseFloat(kplPerSubmission.toFixed(2));
console.log("Random KPL: ", randomKPL);
console.log("Total KPL: ", totalKPL);
console.log("KPL per submission: ", kplPerSubmission);
console.log("Addresses: ", addresses.length);
let checkTransferred = await hasRoundTransferred(taskData.maxRound);
if (checkTransferred) {
console.log("Round already transferred", taskData.maxRound);
return;
} else {
// Transfer KPL to all addresses
for (let i = 0; i < addresses.length; i++) {
const address = addresses[i];
const transferResult = await transferKPL(randomKPL, address, kplPerSubmission);
if (transferResult) {
console.log(`Transferred ${kplPerSubmission} KPL to ${address}`);
}
}
// Record the transfer after processing all addresses
await recordTransfer(taskData.maxRound, randomKPL, addresses);
}
// Wait for the next round
console.log("Waiting for the next round...");
// await new Promise((resolve) => setTimeout(resolve, taskData.roundTime * 1000));
main();
} catch (error) {
console.error("Error in main function:", error);
console.log("Retrying in 5 seconds");
await new Promise((resolve) => setTimeout(resolve, 5000));
main();
}
}
main();