-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathairdrop.js
113 lines (100 loc) · 3.79 KB
/
airdrop.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
const getStakingAccountInfo = require("./helpers/getStakingAccountInfo");
const transferKPL = require("./helpers/transferKPL");
const getFrequentstakingKeys = require("./helpers/getFrequentStake");
const { MongoClient } = require("mongodb");
require("dotenv").config();
const uri = process.env.DB_KEY;
const DB_name = "mainnet_airdrop_middleman";
const collection_name = "kplairdrop";
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
async function hasDateTransferred(address, date) {
await client.connect();
const database = client.db(DB_name);
const transfersCollection = database.collection(collection_name);
try {
// Check if a record with the given address and date exists in the collection
const transfer = await transfersCollection.findOne({
address: address,
date: date,
});
return transfer !== null; // Return true if both address and date exist, otherwise false
} catch (error) {
console.error("Error checking round transfer:", error);
return false; // Return false if an error occurs
} finally {
await client.close(); // Ensure the client connection is closed
}
}
async function recordTransfer(date, kplToken, address) {
await client.connect();
const database = client.db(DB_name);
const transfersCollection = database.collection(collection_name);
try {
// Insert the transfer record
await transfersCollection.insertOne({
date: date,
token: kplToken,
address: address, // An array of objects with { address, amount }
timestamp: new Date(),
});
// console.log(`Recorded transfer for date ${date}`);
} catch (error) {
console.error("Error recording transfer:", error);
}
}
async function main() {
try {
const listOfKPLs = [
"Fe7878UvoGHUM7B8C95rX3MigUqtBZmtcPcX5sz3Qhxd", // BIRD
"AayQB5XgchRR9zTr5bi95aQ1FFtJ6jEVmbrBQRx5m4gw", // BB
"4qayyw53kWz6GzypcejjT1cvwMXS1qYLSMQRE8se3gTv", // FIRE
// "BmdvRw51zhCKfkBmw6jmLawJafimTMtZ2eVwT3fL2WM6", // RATs
"n3Rep7GRh3jgkGXaULNu8WzfuwCC9Rcrv82mxzJMnnH", // SONO
// "NGFruaQX9xHqWv195RNQL2wtq2LJwTmnkE9XjGAZKHx", // SOMA
"9VUq3SfNDh1bgwamF8tr9aGvuXvNi6ktjx1Edc2da7ey", // VIP
// "EErjDSPHmjz9ZipEtVoN54QzCjPvePBADvXcWKT659NW", // SSS
// "HK8STMDTos4QFocyEADxwdXBrN13DCB9AcwLXsmvBthh", // SMART
"CJLjkLohs3PScpBQ3r1WKHjQsWYPq291MgPjpTWTXNc4", // ASTRO
];
let stakingList = await getFrequentstakingKeys();
console.log(`${stakingList.length} address to airdrop`);
const randomKPL = listOfKPLs[Math.floor(Math.random() * listOfKPLs.length)];
// Airdrop amount
const date = new Date().toISOString().split("T")[0];
let kplPerSubmission = 0.2;
console.log("Date already transferred", date);
// Transfer KPL to all addresses
for (let i = 0; i < stakingList.length; i++) {
const address = await getStakingAccountInfo(stakingList[i]);
let checkTransferred = await hasDateTransferred(address, date);
if (!checkTransferred) {
const transferResult = await transferKPL(
randomKPL,
address,
kplPerSubmission
);
if (transferResult) {
console.log(`Transferred ${kplPerSubmission} KPL to ${address}`);
}
// Record the transfer
await recordTransfer(date, randomKPL, address);
} else {
console.log("Already airdrop to this address");
continue;
}
}
// Wait for the next round
console.log("Waiting for the next date...");
// 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();