-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchecker.js
More file actions
78 lines (60 loc) · 2.79 KB
/
checker.js
File metadata and controls
78 lines (60 loc) · 2.79 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
const { ethers } = require("ethers");
const axios = require("axios");
require("dotenv").config();
// Load config from .env
const RPC_URL = process.env.RPC_URL;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
const WALLET_ADDRESS = process.env.WALLET_ADDRESS_TO_CHECK;
// Airdrop criteria constants
const MIN_TX_COUNT = 10;
const MIN_WALLET_AGE_DAYS = 90;
const UNISWAP_V2_ROUTER = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
if (!RPC_URL || !ETHERSCAN_API_KEY || !WALLET_ADDRESS) {
console.error("Error: Missing required environment variables.");
process.exit(1);
}
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
// Helper to call Etherscan API
async function getTxHistory(address) {
const url = `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&sort=asc&apikey=${ETHERSCAN_API_KEY}`;
const response = await axios.get(url);
return response.data.result;
}
// --- CHECK FUNCTIONS ---
async function checkWalletAge(transactions) {
if (transactions.length === 0) return { met: false, age: 0 };
const firstTxTimestamp = parseInt(transactions[0].timeStamp);
const firstTxDate = new Date(firstTxTimestamp * 1000);
const ageInMs = Date.now() - firstTxDate.getTime();
const ageInDays = Math.floor(ageInMs / (1000 * 60 * 60 * 24));
return { met: ageInDays >= MIN_WALLET_AGE_DAYS, age: ageInDays };
}
async function checkTxCount(address) {
const count = await provider.getTransactionCount(address);
return { met: count >= MIN_TX_COUNT, count: count };
}
async function checkDeFiInteraction(transactions) {
const interaction = transactions.some(tx => tx.to.toLowerCase() === UNISWAP_V2_ROUTER.toLowerCase());
return { met: interaction };
}
async function main() {
console.log(`🚀 Checking Airdrop Eligibility for wallet: ${WALLET_ADDRESS}\n`);
try {
const transactions = await getTxHistory(WALLET_ADDRESS);
// Run checks in parallel
const [ageResult, countResult, defiResult] = await Promise.all([
checkWalletAge(transactions),
checkTxCount(WALLET_ADDRESS),
checkDeFiInteraction(transactions)
]);
// Print report
console.log("--- Airdrop Eligibility Report ---");
console.log(`${ageResult.met ? '✅' : '❌'} Wallet Age > ${MIN_WALLET_AGE_DAYS} days (Actual: ${ageResult.age} days)`);
console.log(`${countResult.met ? '✅' : '❌'} Transaction Count > ${MIN_TX_COUNT} (Actual: ${countResult.count} txs)`);
console.log(`${defiResult.met ? '✅' : '❌'} Interacted with Uniswap V2 Router`);
console.log("---------------------------------");
} catch (error) {
console.error("❌ An error occurred:", error.message);
}
}
main();